Sample - GitHub REST API
PUT/repos/{owner}/{repo}/collaborators/{username}

Add a repository collaborator

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:

Cannot assign {member} permission of {role name}

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.

  • RetriesRetries up to 2×, 500ms backoff, 30s timeout.

3 parameters · 1 body field
ownerstringrequired
The account owner of the repository. The name is not case sensitive.
repostringrequired
The name of the repository without the `.git` extension. The name is not case sensitive.
usernamestringrequired
The handle for the GitHub user account.
permissionstringoptional
The permission to grant the collaborator. **Only valid on organization-owned repositories.** We accept the following permissions to be set: `pull`, `triage`, `push`, `maintain`, `admin` and you can also specify a custom repository role name, if the owning organization has defined any.
Default:push

4 status codes
201Response when a new invitation is created
idintegerrequired
Unique identifier of the repository invitation.
repositoryobjectrequired
Minimal Repository
inviteeobjectrequired
A GitHub user.
inviterobjectrequired
A GitHub user.
permissionsstringrequired
The permission associated with the invitation.
Allowed:readwriteadmintriagemaintain
created_atstringrequired
expiredbooleanoptional
Whether or not the invitation has expired
urlstringrequired
URL for the repository invitation
html_urlstringrequired
node_idstringrequired
204Response when: - an existing collaborator is added as a collaborator - an organization member is added as an individual collaborator - an existing team member (whose team is also a repository collaborator) is added as an individual collaborator
403Forbidden
messagestringoptional
documentation_urlstringoptional
urlstringoptional
statusstringoptional
422Response when: - validation failed, or the endpoint has been spammed - an Enterprise Managed User (EMU) account was invited to a repository in an enterprise with personal user accounts
messagestringrequired
documentation_urlstringrequired
errorsarray<object>optional

Error handling

A 403 is returned: Forbidden. A 422 is returned: Response when:

  • validation failed, or the endpoint has been spammed
  • an Enterprise Managed User (EMU) account was invited to a repository in an enterprise with personal user accounts.