Skip to main content

collaborators

Creates, updates, deletes, gets or lists a collaborators resource.

Overview

Namecollaborators
TypeResource
Idgithub.repos.collaborators

Fields

The following fields are returned by SELECT queries:

Response

NameDatatypeDescription
idinteger (int64)
namestring
gravatar_idstring (example: 41d064eb2195891e12d0413f63227ea7)
node_idstring (example: MDQ6VXNlcjE=)
role_namestring (example: admin)
avatar_urlstring (uri) (example: https://github.com/images/error/octocat_happy.gif)
emailstring
events_urlstring (example: https://api.github.com/users/octocat/events{/privacy})
followers_urlstring (uri) (example: https://api.github.com/users/octocat/followers)
following_urlstring (example: https://api.github.com/users/octocat/following{/other_user})
gists_urlstring (example: https://api.github.com/users/octocat/gists{/gist_id})
html_urlstring (uri) (example: https://github.com/octocat)
loginstring (example: octocat)
organizations_urlstring (uri) (example: https://api.github.com/users/octocat/orgs)
permissionsobject
received_events_urlstring (uri) (example: https://api.github.com/users/octocat/received_events)
repos_urlstring (uri) (example: https://api.github.com/users/octocat/repos)
site_adminboolean
starred_urlstring (example: https://api.github.com/users/octocat/starred{/owner}{/repo})
subscriptions_urlstring (uri) (example: https://api.github.com/users/octocat/subscriptions)
typestring (example: User)
urlstring (uri) (example: https://api.github.com/users/octocat)
user_view_typestring (example: public)

Methods

The following methods are available for this resource:

NameAccessible byRequired ParamsOptional ParamsDescription
list_collaboratorsselectowner, repoaffiliation, permission, per_page, pageFor organization-owned repositories, the list of collaborators includes outside collaborators, organization members that are direct collaborators, organization members with access through team memberships, organization members with access through default organization permissions, and organization owners.
The permissions hash returned in the response contains the base role permissions of the collaborator. The role_name is the highest role assigned to the collaborator after considering all sources of grants, including: repo, teams, organization, and enterprise.
There is presently not a way to differentiate between an organization level grant and a repository level grant from this endpoint response.

Team members will include the members of child teams.

The authenticated user must have write, maintain, or admin privileges on the repository to use this endpoint. For organization-owned repositories, the authenticated user needs to be a member of the organization.
OAuth app tokens and personal access tokens (classic) need the read:org and repo scopes to use this endpoint.
add_collaboratorinsertowner, repo, usernameAdd a user to a repository with a specified level of access. If the repository is owned by an organization, this API does not add the user to the organization - a user that has repository access without being an organization member is called an "outside collaborator" (if they are not an Enterprise Managed User) or a "repository collaborator" if they are an Enterprise Managed User. These users are exempt from some organization policies - see "Adding outside collaborators to repositories" to learn more about these collaborator types.

This endpoint triggers notifications.

Adding an outside collaborator may be restricted by enterprise and organization administrators. For more information, see "Enforcing repository management policies in your enterprise" and "Setting permissions for adding outside collaborators" for organization settings.

For more information on permission levels, see "Repository permission levels for an organization". There are restrictions on which permissions can be granted to organization members when an organization base role is in place. In this case, the role being given must be equal to or higher than the org base permission. Otherwise, the request will fail with:

<br />Cannot assign &#123;member&#125; permission of &#123;role name&#125;<br />

Note that, if you choose not to pass any parameters, you'll need to set Content-Length to zero when calling out to this endpoint. For more information, see "HTTP method."

The invitee will receive a notification that they have been invited to the repository, which they must accept or decline. They may do this via the notifications page, the email they receive, or by using the API.

For Enterprise Managed Users, this endpoint does not send invitations - these users are automatically added to organizations and repositories. Enterprise Managed Users can only be added to organizations and repositories within their enterprise.

Updating an existing collaborator's permission level

The endpoint can also be used to change the permissions of an existing collaborator without first removing and re-adding the collaborator. To change the permissions, use the same endpoint and pass a different permission parameter. The response will be a 204, with no other indication that the permission level changed.

Rate limits

You are limited to sending 50 invitations to a repository per 24 hour period. Note there is no limit if you are inviting organization members to an organization repository.
remove_collaboratordeleteowner, repo, usernameRemoves a collaborator from a repository.

To use this endpoint, the authenticated user must either be an administrator of the repository or target themselves for removal.

This endpoint also:
- Cancels any outstanding invitations sent by the collaborator
- Unassigns the user from any issues
- Removes access to organization projects if the user is not an organization member and is not a collaborator on any other organization repositories.
- Unstars the repository
- Updates access permissions to packages

Removing a user as a collaborator has the following effects on forks:
- If the user had access to a fork through their membership to this repository, the user will also be removed from the fork.
- If the user had their own fork of the repository, the fork will be deleted.
- If the user still has read access to the repository, open pull requests by this user from a fork will be denied.

> [!NOTE]
> A user can still have access to the repository through organization permissions like base repository permissions.

Although the API responds immediately, the additional permission updates might take some extra time to complete in the background.

For more information on fork permissions, see "About permissions and visibility of forks".
check_collaboratorexecowner, repo, usernameFor organization-owned repositories, the list of collaborators includes outside collaborators, organization members that are direct collaborators, organization members with access through team memberships, organization members with access through default organization permissions, and organization owners.

Team members will include the members of child teams.

The authenticated user must have push access to the repository to use this endpoint.

OAuth app tokens and personal access tokens (classic) need the read:org and repo scopes to use this endpoint.

Parameters

Parameters can be passed in the WHERE clause of a query. Check the Methods section to see which parameters are required or optional for each operation.

NameDatatypeDescription
ownerstringThe account owner of the repository. The name is not case sensitive.
repostringThe name of the repository without the .git extension. The name is not case sensitive.
usernamestringThe handle for the GitHub user account.
affiliationstringFilter collaborators returned by their affiliation. outside means all outside collaborators of an organization-owned repository. direct means all collaborators with permissions to an organization-owned repository, regardless of organization membership status. all means all collaborators the authenticated user can see.
pageintegerThe page number of the results to fetch. For more information, see "Using pagination in the REST API."
per_pageintegerThe number of results per page (max 100). For more information, see "Using pagination in the REST API."
permissionstringFilter collaborators by the permissions they have on the repository. If not specified, all collaborators will be returned.

SELECT examples

For organization-owned repositories, the list of collaborators includes outside collaborators, organization members that are direct collaborators, organization members with access through team memberships, organization members with access through default organization permissions, and organization owners.
The permissions hash returned in the response contains the base role permissions of the collaborator. The role_name is the highest role assigned to the collaborator after considering all sources of grants, including: repo, teams, organization, and enterprise.
There is presently not a way to differentiate between an organization level grant and a repository level grant from this endpoint response.

Team members will include the members of child teams.

The authenticated user must have write, maintain, or admin privileges on the repository to use this endpoint. For organization-owned repositories, the authenticated user needs to be a member of the organization.
OAuth app tokens and personal access tokens (classic) need the read:org and repo scopes to use this endpoint.

SELECT
id,
name,
gravatar_id,
node_id,
role_name,
avatar_url,
email,
events_url,
followers_url,
following_url,
gists_url,
html_url,
login,
organizations_url,
permissions,
received_events_url,
repos_url,
site_admin,
starred_url,
subscriptions_url,
type,
url,
user_view_type
FROM github.repos.collaborators
WHERE owner = '{{ owner }}' -- required
AND repo = '{{ repo }}' -- required
AND affiliation = '{{ affiliation }}'
AND permission = '{{ permission }}'
AND per_page = '{{ per_page }}'
AND page = '{{ page }}'
;

INSERT examples

Add a user to a repository with a specified level of access. If the repository is owned by an organization, this API does not add the user to the organization - a user that has repository access without being an organization member is called an "outside collaborator" (if they are not an Enterprise Managed User) or a "repository collaborator" if they are an Enterprise Managed User. These users are exempt from some organization policies - see "Adding outside collaborators to repositories" to learn more about these collaborator types.

This endpoint triggers notifications.

Adding an outside collaborator may be restricted by enterprise and organization administrators. For more information, see "Enforcing repository management policies in your enterprise" and "Setting permissions for adding outside collaborators" for organization settings.

For more information on permission levels, see "Repository permission levels for an organization". There are restrictions on which permissions can be granted to organization members when an organization base role is in place. In this case, the role being given must be equal to or higher than the org base permission. Otherwise, the request will fail with:

<br />Cannot assign &#123;member&#125; permission of &#123;role name&#125;<br />

Note that, if you choose not to pass any parameters, you'll need to set Content-Length to zero when calling out to this endpoint. For more information, see "HTTP method."

The invitee will receive a notification that they have been invited to the repository, which they must accept or decline. They may do this via the notifications page, the email they receive, or by using the API.

For Enterprise Managed Users, this endpoint does not send invitations - these users are automatically added to organizations and repositories. Enterprise Managed Users can only be added to organizations and repositories within their enterprise.

Updating an existing collaborator's permission level

The endpoint can also be used to change the permissions of an existing collaborator without first removing and re-adding the collaborator. To change the permissions, use the same endpoint and pass a different permission parameter. The response will be a 204, with no other indication that the permission level changed.

Rate limits

You are limited to sending 50 invitations to a repository per 24 hour period. Note there is no limit if you are inviting organization members to an organization repository.

INSERT INTO github.repos.collaborators (
permission,
owner,
repo,
username
)
SELECT
'{{ permission }}',
'{{ owner }}',
'{{ repo }}',
'{{ username }}'
RETURNING
id,
node_id,
created_at,
expired,
html_url,
invitee,
inviter,
permissions,
repository,
url
;

DELETE examples

Removes a collaborator from a repository.

To use this endpoint, the authenticated user must either be an administrator of the repository or target themselves for removal.

This endpoint also:
- Cancels any outstanding invitations sent by the collaborator
- Unassigns the user from any issues
- Removes access to organization projects if the user is not an organization member and is not a collaborator on any other organization repositories.
- Unstars the repository
- Updates access permissions to packages

Removing a user as a collaborator has the following effects on forks:
- If the user had access to a fork through their membership to this repository, the user will also be removed from the fork.
- If the user had their own fork of the repository, the fork will be deleted.
- If the user still has read access to the repository, open pull requests by this user from a fork will be denied.

> [!NOTE]
> A user can still have access to the repository through organization permissions like base repository permissions.

Although the API responds immediately, the additional permission updates might take some extra time to complete in the background.

For more information on fork permissions, see "About permissions and visibility of forks".

DELETE FROM github.repos.collaborators
WHERE owner = '{{ owner }}' --required
AND repo = '{{ repo }}' --required
AND username = '{{ username }}' --required
;

Lifecycle Methods

For organization-owned repositories, the list of collaborators includes outside collaborators, organization members that are direct collaborators, organization members with access through team memberships, organization members with access through default organization permissions, and organization owners.

Team members will include the members of child teams.

The authenticated user must have push access to the repository to use this endpoint.

OAuth app tokens and personal access tokens (classic) need the read:org and repo scopes to use this endpoint.

EXEC github.repos.collaborators.check_collaborator 
@owner='{{ owner }}' --required,
@repo='{{ repo }}' --required,
@username='{{ username }}' --required
;