Skip to navigation

Getting Information on Project Collaborators

Work out who can access what by combining the V3 collaboration, group membership, and policy endpoints. Two listing endpoints answer these questions in either direction.

Overview

Access in Benchling is described by two objects: a collaboration grants a policy on a resource to a user, app, team, or organization, and a group membership puts a user in a team or organization. Answering “who can see this project?” means walking from one to the other.

This guide uses the V3 REST API, where both objects are first-class listing endpoints with typed filters, to cover four use cases:

  1. Getting all collaborators on a specific project
  2. Getting information about collaborators on all projects on a tenant
  3. Getting a specific party’s access policy on a specific project
  4. Getting a specific user’s access policy for all projects they can access

Why this recipe uses V3

The V2 equivalents of these endpoints are v2-alpha and v2-beta, and answering these questions there takes a different endpoint for each direction: ?adminOf=, ?memberOf=, ?hasMembers=, ?hasAdmins=. V3 replaces all four with one /group-membership/items endpoint that filters by either side, so the same call shape works whichever way you are walking the graph. Use V3 for this.

The V3 collaboration, project, group membership, team, organization, and policy endpoints are beta. Set early_access="true" on the client, as in the examples below, or send the EARLY-ACCESS: true header on raw HTTP requests. See the V3 Stability Guidelines.

Each use case shows the raw endpoint and response, then the same steps with the V3 Python SDK. The Python examples use this client. Pass your tenant’s root URL; the SDK adds /api/v3 itself, and list calls page through nextToken for you.

from benchling_v3_sdk import Benchling
benchling = Benchling(
base_url="https://yourcompany.benchling.com",
api_key="<your-api-key>",
early_access="true",
)

The three objects involved

ObjectEndpointWhat it tells you
Collaboration/api/v3/collaboration/itemsA policy is granted to a collaborator on a resource
Group membership/api/v3/group-membership/itemsA user is a MEMBER or ADMIN of a team or organization
Policy/api/v3/policy/{policy_id}The permissions a policy actually grants

A collaboration’s accessPolicy is a reference, {"__typename": "Policy", "id": "pol_…"}, not the expanded policy. Fetch the policy separately when you need its statements, and cache it: a tenant has few policies and many collaborations.

1) Getting all collaborators on a specific project

For a project ID such as src_TnTw2xzy, list its collaborations:

GET /api/v3/project/src_TnTw2xzy/collaborations/items

With the SDK, benchling.project.list_collaborations("src_TnTw2xzy") returns the same items.

Read collaboratorInfo.__typename (collaborator_info.typename in the SDK) to tell the two kinds of collaborator apart:

  • PrincipalCollaboratorInfo: an individual user, app, or service principal. collaborator is a reference, {__typename, id}, and its __typename says which of the three you got.
  • GroupCollaboratorInfo: a team or organization, plus a role of MEMBER or ADMIN. The role narrows the grant to a subgroup of that group: ADMIN means the policy applies only to the group’s admins. Here collaborator is the fully hydrated group, not a reference, so you get its name and its memberships URI without a second call.

Two booleans qualify the grant. isAuditor marks a read-only auditor collaboration, and fromOwnership marks one that follows from ownership of the resource rather than from an explicit share, which is why the project owner appears in this list without anyone having added them.

This endpoint returns the same information as the project collaborators page in the UI.

The Benchling project permissions page listing each collaborator alongside its access policy
The project permissions page

Every project object also carries a collaborations field holding the URI of this listing, so if you already have the project you do not need to build the URL.

Expanding a group into individual users

To turn a team or organization collaborator into individual users, list that group’s memberships. Filter by the group:

GET /api/v3/group-membership/items?groupId.eq=team_oSrQDUmh

Match each membership’s role against the collaboration’s role. A collaboration scoped to ADMIN applies only to memberships whose role is ADMIN; one scoped to MEMBER applies to everyone in the group. There is no role filter on the endpoint, so filter in your own code.

GET /api/v3/team/{team_id}/memberships/items and GET /api/v3/organization/{organization_id}/memberships/items return the same memberships as unpaginated nested lists, and each team and organization object carries the URI of its own listing in a memberships field.

Putting it together with the SDK, for every project the caller can see:

results = []
for project in benchling.project.list(page_size=100):
for collaboration in benchling.project.list_collaborations(project.id):
info = collaboration.collaborator_info
policy_id = collaboration.access_policy.id
if info.typename == "PrincipalCollaboratorInfo":
# A user, app, or service principal: record it directly
results.append(
{"project_id": project.id, "principal": info.collaborator, "policy_id": policy_id}
)
continue
# A team or organization: expand it, keeping only the matching role
group_id = info.collaborator.id
for membership in benchling.group_membership.list(group_id_eq=group_id):
if info.role == "ADMIN" and membership.role != "ADMIN":
continue
results.append(
{"project_id": project.id, "principal": membership.member, "policy_id": policy_id}
)

Branch on the typename string rather than the Python class of info.collaborator or membership.group: in SDK 9.0.2 a team can be deserialized into the Organization class, while its typename still reads Team.

Collaborators with multiple access policies

In this and every case below, one user can end up with more than one policy on a project: directly, and again through each group they belong to. See Understanding Combined Access Policies for how to reduce them to an effective permission set.

2) Getting information about collaborators on all projects on a tenant

List every project the caller can see, paging with nextToken until it comes back empty:

GET /api/v3/project/items?pageSize=100

Then apply the logic from use case 1 to each project.

Alternatively, skip the per-project loop and list collaborations tenant-wide from /api/v3/collaboration/items, reading each collaboration’s resource to see which project it belongs to. That is one paginated sweep instead of one request per project, which matters on a tenant with many projects.

3) Getting a specific party’s access policy on a specific project

Filter collaborations by both sides at once. collaboratorId.anyOf takes the party’s ID and resourceId.anyOf takes the project’s:

Endpoint
GET /api/v3/collaboration/items?resourceId.anyOf=src_TnTw2xzy&collaboratorId.anyOf=team_oSrQDUmh

Both filters accept a comma-separated list of up to 100 IDs, so you can ask about several parties or several projects in one request. In the SDK, pass a string or a list:

direct = list(
benchling.collaboration.list(
resource_id_any_of="src_TnTw2xzy",
collaborator_id_any_of=["team_oSrQDUmh"],
)
)
print([collaboration.access_policy.id for collaboration in direct])

That covers a party granted access directly. A user can also reach the project through a group, which the filter above will not show, so also list the user’s groups and re-run the filter with those IDs:

Endpoint
GET /api/v3/group-membership/items?memberId.eq=ent_a8asdp

Collect the group.id values, then query collaboratorId.anyOf=<group_id>,<group_id>,… against the same project, remembering to drop any collaboration whose role is ADMIN where the user’s membership role is only MEMBER.

4) Getting a specific user’s access policy for all projects they can access

This is use case 3 without the project filter, and it shows why one endpoint filtering both directions is easier to work with than four.

Listing endpoint visibility

Listing endpoints return only what the API caller can see. This use case therefore returns projects accessible to both the target user and the caller, not everything the target user can access.

  1. Find the groups the user belongs to, and keep each membership’s role:

    Endpoint
    GET /api/v3/group-membership/items?memberId.eq=ent_a8asdp
  2. List every collaboration granted to the user or to any of those groups, in one request:

    Endpoint
    GET /api/v3/collaboration/items?collaboratorId.anyOf=ent_a8asdp,team_oSrQDUmh,org_2kFpWq

    collaboratorId.anyOf caps at 100 IDs, so a user in more than 99 groups needs the list split across requests, as the code below does.

  3. Discard group collaborations whose role the user does not hold, then group what remains by resource.id:

from collections import defaultdict
memberships = {
m.group.id: m.role
for m in benchling.group_membership.list(member_id_eq="ent_a8asdp")
}
collaborator_ids = ["ent_a8asdp", *memberships]
policies_by_project = defaultdict(set)
# collaboratorId.anyOf accepts at most 100 IDs per request
for start in range(0, len(collaborator_ids), 100):
batch = collaborator_ids[start : start + 100]
for collaboration in benchling.collaboration.list(collaborator_id_any_of=batch):
info = collaboration.collaborator_info
if info.typename == "GroupCollaboratorInfo":
held_role = memberships[info.collaborator.id]
# A grant scoped to a group's admins does not apply to plain members
if info.role == "ADMIN" and held_role != "ADMIN":
continue
policies_by_project[collaboration.resource.id].add(collaboration.access_policy.id)

Each entry in policies_by_project is a project the user can reach, paired with every policy that gets them there. Reduce those to one effective permission set as follows.

Understanding Combined Access Policies

A user with more than one policy on a project holds the union of what those policies grant. Fetch each one to see its statements:

GET /api/v3/policy/pol_12345

A V3 policy statement is a triple:

  • itemType: the kind of object the grant covers, such as FOLDER_OR_PROJECT, NOTEBOOK, or CONTAINER. Folders and projects share one item type.
  • action: the operation, such as READ, WRITE, ADMIN, or CREATE_SUBFOLDER.
  • condition: when the grant applies: ALWAYS, IS_AUTHOR, or IS_ASSIGNEE.

All three enums are long and all three include UNKNOWN, which is what you receive for a value your client’s version of the spec does not know about. Treat UNKNOWN as a value to skip rather than an error, so a new permission type does not break your code.

V3 policies list only what they grant. Where a V2 policy carried a statement per permission with an access of GRANTED, GRANTED_TO_AUTHOR, or NOT_GRANTED, a V3 policy simply omits permissions it does not grant. Absence means not granted.

With the SDK, fetch each distinct policy once with benchling.policy.get, then combine them separately for each project.

To combine policies, key statements by (itemType, action) and keep the least restrictive condition. ALWAYS beats IS_AUTHOR and IS_ASSIGNEE. IS_AUTHOR and IS_ASSIGNEE are different conditions rather than stronger and weaker versions of one, so a user holding both keeps both. A pair absent from every policy is not granted at all.

from collections import defaultdict
# Fetch each policy once, however many projects use it
policy_ids = {pid for pids in policies_by_project.values() for pid in pids}
policies = {policy_id: benchling.policy.get(policy_id) for policy_id in policy_ids}
effective_by_project = {}
for project_id, project_policy_ids in policies_by_project.items():
conditions = defaultdict(set)
for policy_id in project_policy_ids:
for statement in policies[policy_id].policy_statements:
if "UNKNOWN" in (statement.item_type, statement.action, statement.condition):
continue
key = (statement.item_type, statement.action)
conditions[key].add(statement.condition)
effective_by_project[project_id] = [
{
"itemType": item_type,
"action": action,
"conditions": ["ALWAYS"] if "ALWAYS" in found else sorted(found),
}
for (item_type, action), found in conditions.items()
]

This is a per-project calculation: a policy the user holds on one project says nothing about their access to another, so each project’s statements are combined only with that project’s policies.

For example, a user holding both a LIBRARIAN policy that grants FOLDER_OR_PROJECT / CREATE_SUBFOLDER with condition: IS_AUTHOR and a SCIENTIST policy that grants the same pair with condition: ALWAYS can create subfolders anywhere in the project, because ALWAYS supersedes IS_AUTHOR. Any pair neither policy mentions stays ungranted.