Skip to main content

memberships

Creates, updates, deletes, gets or lists a memberships resource.

Overview

Namememberships
TypeResource
Idgithub.orgs.memberships

Fields

The following fields are returned by SELECT queries:

Response

NameDatatypeDescription
direct_membershipbooleanWhether the user has direct membership in the organization.
enterprise_teams_providing_indirect_membershiparrayThe slugs of the enterprise teams providing the user with indirect membership in the organization. A limit of 100 enterprise team slugs is returned.
organizationobjectA GitHub organization. (title: Organization Simple)
organization_urlstring (uri) (example: https://api.github.com/orgs/octocat)
permissionsobject
rolestringThe user's membership type in the organization. (admin, member, billing_manager) (example: admin)
statestringThe state of the member in the organization. The pending state indicates the user has not yet accepted an invitation. (active, pending) (example: active)
urlstring (uri) (example: https://api.github.com/orgs/octocat/memberships/defunkt)
userobjectA GitHub user. (title: Simple User)

Methods

The following methods are available for this resource:

NameAccessible byRequired ParamsOptional ParamsDescription
get_membership_for_userselectorg, usernameIn order to get a user's membership with an organization, the authenticated user must be an organization member. The state parameter in the response can be used to identify the user's membership status.
get_membership_for_authenticated_userselectorgIf the authenticated user is an active or pending member of the organization, this endpoint will return the user's membership. If the authenticated user is not affiliated with the organization, a 404 is returned. This endpoint will return a 403 if the request is made by a GitHub App that is blocked by the organization.
list_memberships_for_authenticated_userselectstate, per_page, pageLists all of the authenticated user's organization memberships.
update_membership_for_authenticated_userupdateorg, stateConverts the authenticated user to an active member of the organization, if that user has a pending invitation from the organization.
set_membership_for_userreplaceorg, usernameOnly 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.
remove_membership_for_userdeleteorg, usernameIn order to remove a user's membership with an organization, the authenticated user must be an organization owner.

If the specified user is an active member of the organization, this will remove them from the organization. If the specified user has been invited to the organization, this will cancel their invitation. The specified user will receive an email notification in both cases.

> [!NOTE]
> If a user has both direct membership in the organization as well as indirect membership via an enterprise team, only their direct membership will be removed. Their indirect membership via an enterprise team remains until the user is removed from the enterprise team.
check_membership_for_userexecorg, usernameCheck if a user is, publicly or privately, a member of the organization.

Parameters

Parameters can be passed in the WHERE clause of a query. Check the Methods section to see which parameters are required or optional for each operation.

NameDatatypeDescription
orgstringThe organization name. The name is not case sensitive.
usernamestringThe handle for the GitHub user account.
pageintegerThe page number of the results to fetch. For more information, see "Using pagination in the REST API."
per_pageintegerThe number of results per page (max 100). For more information, see "Using pagination in the REST API."
statestringIndicates the state of the memberships to return. If not specified, the API returns both active and pending memberships.

SELECT examples

In order to get a user's membership with an organization, the authenticated user must be an organization member. The state parameter in the response can be used to identify the user's membership status.

SELECT
direct_membership,
enterprise_teams_providing_indirect_membership,
organization,
organization_url,
permissions,
role,
state,
url,
user
FROM github.orgs.memberships
WHERE org = '{{ org }}' -- required
AND username = '{{ username }}' -- required
;

UPDATE examples

Converts the authenticated user to an active member of the organization, if that user has a pending invitation from the organization.

UPDATE github.orgs.memberships
SET
state = '{{ state }}'
WHERE
org = '{{ org }}' --required
AND state = '{{ state }}' --required
RETURNING
direct_membership,
enterprise_teams_providing_indirect_membership,
organization,
organization_url,
permissions,
role,
state,
url,
user;

REPLACE examples

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.

REPLACE github.orgs.memberships
SET
role = '{{ role }}'
WHERE
org = '{{ org }}' --required
AND username = '{{ username }}' --required
RETURNING
direct_membership,
enterprise_teams_providing_indirect_membership,
organization,
organization_url,
permissions,
role,
state,
url,
user;

DELETE examples

In order to remove a user's membership with an organization, the authenticated user must be an organization owner.

If the specified user is an active member of the organization, this will remove them from the organization. If the specified user has been invited to the organization, this will cancel their invitation. The specified user will receive an email notification in both cases.

> [!NOTE]
> If a user has both direct membership in the organization as well as indirect membership via an enterprise team, only their direct membership will be removed. Their indirect membership via an enterprise team remains until the user is removed from the enterprise team.

DELETE FROM github.orgs.memberships
WHERE org = '{{ org }}' --required
AND username = '{{ username }}' --required
;

Lifecycle Methods

Check if a user is, publicly or privately, a member of the organization.

EXEC github.orgs.memberships.check_membership_for_user 
@org='{{ org }}' --required,
@username='{{ username }}' --required
;