Sample - GitHub REST API
PUT/orgs/{org}/teams/{team_slug}/memberships/{username}

Add or update team membership for a user

Adds an organization member to a team. An authenticated organization owner or team maintainer can add organization members to a team.

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

[!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."

An organization owner can add someone who is not part of the team's organization to a team. When an organization owner adds someone to a team who is not an organization member, this endpoint will send an invitation to the person via email. This newly-created membership will be in the "pending" state until the person 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.

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.

[!NOTE] You can also specify a team by org_id and team_id using the route PUT /organizations/{org_id}/team/{team_id}/memberships/{username}.

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

3 parameters · 1 body field
orgstringrequired
The organization name. The name is not case sensitive.
team_slugstringrequired
The slug of the team name.
usernamestringrequired
The handle for the GitHub user account.
rolestringoptional
The role that this user should have in the team.
Allowed:membermaintainerDefault:member

3 status codes
200Response
urlstringrequired
rolestringrequired
The role of the user in the team.
Allowed:membermaintainerDefault:member
statestringrequired
The state of the user's membership in the team.
Allowed:activepending
403Forbidden if team synchronization is set up
422Unprocessable Entity if you attempt to add an organization to a team

Error handling

A 403 is returned: Forbidden if team synchronization is set up. A 422 is returned: Unprocessable Entity if you attempt to add an organization to a team.