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

Set organization membership for a user

Only authenticated organization owners can add a member to the organization or update the member's role.

  • If the authenticated user is adding a member to the organization, the invited user will receive an email inviting them to the organization. The user's membership status will be pending until they accept the invitation.

  • Authenticated users can update a user's membership by passing the role parameter. If the authenticated user changes a member's role to admin, the affected user will receive an email notifying them that they've been made an organization owner. If the authenticated user changes an owner's role to member, no email will be sent.

Rate limits

To prevent abuse, organization owners are limited to creating 50 organization invitations for an organization within a 24 hour period. If the organization is more than one month old or on a paid plan, the limit is 500 invitations per 24 hour period.

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

2 parameters · 1 body field
orgstringrequired
The organization name. The name is not case sensitive.
usernamestringrequired
The handle for the GitHub user account.
rolestringoptional
The role to give the user in the organization. Can be one of: * `admin` - The user will become an owner of the organization. * `member` - The user will become a non-owner member of the organization.
Allowed:adminmemberDefault:member

3 status codes
200Response
urlstringrequired
statestringrequired
The state of the member in the organization. The `pending` state indicates the user has not yet accepted an invitation.
Allowed:activepending
rolestringrequired
The user's membership type in the organization.
Allowed:adminmemberbilling_manager
direct_membershipbooleanoptional
Whether the user has direct membership in the organization.
enterprise_teams_providing_indirect_membershiparray<string>optional
The slugs of the enterprise teams providing the user with indirect membership in the organization. A limit of 100 enterprise team slugs is returned.
organization_urlstringrequired
organizationobjectrequired
A GitHub organization.
userobjectrequired
A GitHub user.
permissionsobjectoptional
403Forbidden
messagestringoptional
documentation_urlstringoptional
urlstringoptional
statusstringoptional
422Validation failed, or the endpoint has been spammed.
messagestringrequired
documentation_urlstringrequired
errorsarray<object>optional

Error handling

A 403 is returned: Forbidden. A 422 is returned: Validation failed, or the endpoint has been spammed.