Search + K

Command Palette

Search for a command to run...

Sign In

Add a repository collaborator

PUT /repos/{owner}/{repo}/collaborators/{username}
Copy endpoint
https://api.github.com

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.

Parameters

path Path Parameters

Name Type
owner required

The account owner of the repository. The name is not case sensitive.

string
repo required

The name of the repository without the .git extension. The name is not case sensitive.

string
username required

The handle for the GitHub user account.

string

Request Body

application/json
{ permission?: string; }

Responses

201 application/json

Response when a new invitation is created

interface RepositoryInvitation {
id: number;
repository: MinimalRepository

Minimal Repository

interface MinimalRepository {
id: number;
node_id: string;
name: string;
full_name: string;
owner: SimpleUser;
private: boolean;
html_url: string;
description: string | null;
fork: boolean;
url: string;
archive_url: string;
assignees_url: string;
blobs_url: string;
branches_url: string;
collaborators_url: string;
comments_url: string;
commits_url: string;
compare_url: string;
contents_url: string;
contributors_url: string;
deployments_url: string;
downloads_url: string;
events_url: string;
forks_url: string;
git_commits_url: string;
git_refs_url: string;
git_tags_url: string;
git_url?: string;
issue_comment_url: string;
issue_events_url: string;
issues_url: string;
keys_url: string;
labels_url: string;
languages_url: string;
merges_url: string;
milestones_url: string;
notifications_url: string;
pulls_url: string;
releases_url: string;
ssh_url?: string;
stargazers_url: string;
statuses_url: string;
subscribers_url: string;
subscription_url: string;
tags_url: string;
teams_url: string;
trees_url: string;
clone_url?: string;
mirror_url?: string | null;
hooks_url: string;
svn_url?: string;
homepage?: string | null;
language?: string | null;
forks_count?: number;
stargazers_count?: number;
watchers_count?: number;
size?: number;
default_branch?: string;
open_issues_count?: number;
is_template?: boolean;
topics?: string[];
has_issues?: boolean;
has_projects?: boolean;
has_wiki?: boolean;
has_pages?: boolean;
has_downloads?: boolean;
has_discussions?: boolean;
archived?: boolean;
disabled?: boolean;
visibility?: string;
pushed_at?: string | null;
created_at?: string | null;
updated_at?: string | null;
permissions?: {
admin?: boolean;
maintain?: boolean;
push?: boolean;
triage?: boolean;
pull?: boolean;
}
;
role_name?: string;
temp_clone_token?: string;
delete_branch_on_merge?: boolean;
subscribers_count?: number;
network_count?: number;
code_of_conduct?: CodeOfConduct;
license?: {
key?: string;
name?: string;
spdx_id?: string;
url?: string;
node_id?: string;
}
| null
;
forks?: number;
open_issues?: number;
watchers?: number;
allow_forking?: boolean;
web_commit_signoff_required?: boolean;
security_and_analysis?: SecurityAndAnalysis;
custom_properties?: { };
}
;
invitee: SimpleUser

A GitHub user.

interface SimpleUser {
name?: string | null;
email?: string | null;
login: string;
id: number;
node_id: string;
avatar_url: string;
gravatar_id: string | null;
url: string;
html_url: string;
followers_url: string;
following_url: string;
gists_url: string;
starred_url: string;
subscriptions_url: string;
organizations_url: string;
repos_url: string;
events_url: string;
received_events_url: string;
type: string;
site_admin: boolean;
starred_at?: string;
user_view_type?: string;
}
| null
;
inviter: SimpleUser

A GitHub user.

interface SimpleUser {
name?: string | null;
email?: string | null;
login: string;
id: number;
node_id: string;
avatar_url: string;
gravatar_id: string | null;
url: string;
html_url: string;
followers_url: string;
following_url: string;
gists_url: string;
starred_url: string;
subscriptions_url: string;
organizations_url: string;
repos_url: string;
events_url: string;
received_events_url: string;
type: string;
site_admin: boolean;
starred_at?: string;
user_view_type?: string;
}
| null
;
permissions: "read" | "write" | "admin" | "triage" | "maintain";
created_at: string;
expired?: boolean;
url: string;
html_url: string;
node_id: string;
}
204

Response 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
unknown

Client Errors

403 application/json

Forbidden

interface BasicError {
message?: string;
documentation_url?: string;
url?: string;
status?: string;
}
422 application/json

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
interface ValidationError {
message: string;
documentation_url: string;
errors?: {
resource?: string;
field?: string;
message?: string;
code: string;
index?: number;
value?: string[] | string | number | null;
}
[]
;
}