Skip to content

Add or update team membership for a user (Legacy)

Deprecated
PUT
/teams/{team_id}/memberships/{username}

[!WARNING] Endpoint closing down notice: This endpoint route is closing down and will be removed from the Teams API. We recommend migrating your existing code to use the new Add or update team membership for a user endpoint.

Team synchronization is available for organizations using GitHub Enterprise Cloud. For more information, see GitHub’s products in the GitHub Help documentation.

If the user is already a member of the team’s organization, this endpoint will add the user to the team. To add a membership between an organization member and a team, the authenticated user must be an organization owner or a team maintainer.

[!NOTE] When you have team synchronization set up for a team with your organization’s identity provider (IdP), you will see an error if you attempt to use the API for making changes to the team’s membership. If you have access to manage group membership in your IdP, you can manage GitHub team membership through your identity provider, which automatically adds and removes team members in an organization. For more information, see “Synchronizing teams between your identity provider and GitHub.”

If the user is unaffiliated with the team’s organization, this endpoint will send an invitation to the user via email. This newly-created membership will be in the “pending” state until the user accepts the invitation, at which point the membership will transition to the “active” state and the user will be added as a member of the team. To add a membership between an unaffiliated user and a team, the authenticated user must be an organization owner.

If the user is already a member of the team, this endpoint will update the role of the team member’s role. To update the membership of a team member, the authenticated user must be an organization owner or a team maintainer.

API method documentation

team_id
required
integer

The unique identifier of the team.

username
required
string

The handle for the GitHub user account.

Media type application/json
object
role

The role that this user should have in the team.

string
default: member
Allowed values: member maintainer
Examples
Example default

Assign the member role for a user in a team

{
"role": "member"
}

Response

Media type application/json
Team Membership

Team Membership

object
url
required
string format: uri
role
required

The role of the user in the team.

string
default: member
Allowed values: member maintainer
state
required

The state of the user’s membership in the team.

string
Allowed values: active pending
Examples
Example response-if-users-membership-with-team-is-now-pending

Response if user's membership with team is now pending

{
"url": "https://api.github.com/teams/1/memberships/octocat",
"role": "member",
"state": "pending"
}

Forbidden if team synchronization is set up

Resource not found

Media type application/json
Basic Error

Basic Error

object
message
string
documentation_url
string
url
string
status
string
Example generated
{
"message": "example",
"documentation_url": "example",
"url": "example",
"status": "example"
}

Unprocessable Entity if you attempt to add an organization to a team