Team Members

This API is only available to authenticated members of the team's organization. OAuth access tokens require the read:org scope.

List team members

Note: The Nested Teams API is currently available for developers to preview. See the blog post for full details. To access the API, you must provide a custom media type in the Accept header:

application/vnd.github.hellcat-preview+json

Warning: The API may change without advance notice during the preview period. Preview features are not supported for production use. If you experience any issues, contact GitHub support.

If you pass the hellcat-preview media type, team members will include the members of child teams.

To list members in a team, the team must be visible to the authenticated user.

GET /teams/:team_id/members
Name Type Description
role string Filters members returned by their role in the team. Can be one of:
* member - normal members of the team.
* maintainer - team maintainers.
* all - all members of the team.
Default: all

Response

Status: 200 OK
Link: <https://api.github.com/resource?page=2>; rel="next",
      <https://api.github.com/resource?page=5>; rel="last"
[
  {
    "login": "octocat",
    "id": 1,
    "node_id": "MDQ6VXNlcjE=",
    "avatar_url": "https://github.com/images/error/octocat_happy.gif",
    "gravatar_id": "",
    "url": "https://api.github.com/users/octocat",
    "html_url": "https://github.com/octocat",
    "followers_url": "https://api.github.com/users/octocat/followers",
    "following_url": "https://api.github.com/users/octocat/following{/other_user}",
    "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
    "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
    "subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
    "organizations_url": "https://api.github.com/users/octocat/orgs",
    "repos_url": "https://api.github.com/users/octocat/repos",
    "events_url": "https://api.github.com/users/octocat/events{/privacy}",
    "received_events_url": "https://api.github.com/users/octocat/received_events",
    "type": "User",
    "site_admin": false
  }
]

Get team member

Deprecation notice

The "Get team member" API (described below) is deprecated.

We recommend using the Get team membership API instead. It allows you to get both active and pending memberships.

To list members in a team, the team must be visible to the authenticated user.

GET /teams/:team_id/members/:username

Response if user is a member

Status: 204 No Content

Response if user is not a member

Status: 404 Not Found

Add team member

Deprecation notice

The "Add team member" API (described below) is deprecated.

We recommend using the Add team membership API instead. It allows you to invite new organization members to your teams.

To add a user to a team, the authenticated user must have 'admin' permissions to the team or be an owner of the organization that the team is associated with, and the user being added must already be a member of at least one other team on the same organization.

PUT /teams/:team_id/members/:username

Note that you'll need to set Content-Length to zero when calling out to this endpoint. For more information, see "HTTP verbs."

Response

Status: 204 No Content

If you attempt to add an organization to a team, you will get this:

Status: 422 Unprocessable Entity
{
  "message": "Cannot add an organization as a member.",
  "errors": [
    {
      "code": "org",
      "field": "user",
      "resource": "TeamMember"
    }
  ]
}

If you attempt to add a user to a team and that user is not a member of at least one other team on the same organization, you will get this:

Status: 422 Unprocessable Entity
{
  "message": "User isn't a member of this organization. Please invite them first.",
  "errors": [
    {
      "code": "unaffiliated",
      "field": "user",
      "resource": "TeamMember"
    }
  ]
}

Remove team member

Deprecation notice

The "Remove team member" API (described below) is deprecated.

We recommend using the Remove team membership API instead. It allows you to remove both active and pending memberships.

To remove a user from a team, the authenticated user must have 'admin' permissions to the team or be an owner of the org that the team is associated with. NOTE: This does not delete the user, it just removes them from the team.

DELETE /teams/:team_id/members/:username

Response

Status: 204 No Content

Get team membership

Note: The Nested Teams API is currently available for developers to preview. See the blog post for full details. To access the API, you must provide a custom media type in the Accept header:

application/vnd.github.hellcat-preview+json

Warning: The API may change without advance notice during the preview period. Preview features are not supported for production use. If you experience any issues, contact GitHub support.

If you pass the hellcat-preview media type, team members will include the members of child teams.

To get a user's membership with a team, the team must be visible to the authenticated user.

GET /teams/:team_id/memberships/:username

Note: The role for organization owners returns as maintainer. For more information about maintainer roles, see Create team.

Response if user has an active membership with team

Status: 200 OK
{
  "url": "https://api.github.com/teams/1/memberships/octocat",
  "role": "member",
  "state": "active"
}

Response if user is a team maintainer

Status: 200 OK
{
  "url": "https://api.github.com/teams/1/memberships/octocat",
  "role": "maintainer",
  "state": "active"
}

Response if user has a pending membership with team

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

No membership response

Status: 404 Not Found

Add or update team membership

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 maintainer of the team.

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 maintainer of the team.

PUT /teams/:team_id/memberships/:username

Parameters

Name Type Description
role string The role that this user should have in the team. Can be one of:
* member - a normal member of the team.
* maintainer - a team maintainer. Able to add/remove other team members, promote other team members to team maintainer, and edit the team's name and description.
Default: member

Response if user's membership with team is now active

Status: 200 OK
{
  "url": "https://api.github.com/teams/1/memberships/octocat",
  "role": "member",
  "state": "active"
}

Response if user's membership with team is now pending

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

If you attempt to add an organization to a team, you will get this:

Status: 422 Unprocessable Entity
{
  "message": "Cannot add an organization as a member.",
  "errors": [
    {
      "code": "org",
      "field": "user",
      "resource": "TeamMember"
    }
  ]
}

Remove team membership

To remove a membership between a user and a team, the authenticated user must have 'admin' permissions to the team or be an owner of the organization that the team is associated with. NOTE: This does not delete the user, it just removes their membership from the team.

DELETE /teams/:team_id/memberships/:username

Response

Status: 204 No Content

List pending team invitations

Note: You can now use the API to invite users to a GitHub organization. This feature is currently available for developers to preview. See the blog post for full details. To access this feature, you must provide a custom media type in the Accept header:

application/vnd.github.dazzler-preview+json

Warning: The API may change without advance notice during the preview period. Preview features are not supported for production use. If you experience any issues, contact GitHub support.

The return hash contains a role field which refers to the Organization Invitation role and will be one of the following values: direct_member, admin, billing_manager, hiring_manager, or reinstate. If the invitee is not a GitHub member, the login field in the return hash will be null.

GET /teams/:team_id/invitations

Response

Status: 200 OK
Link: <https://api.github.com/resource?page=2>; rel="next",
      <https://api.github.com/resource?page=5>; rel="last"
[
  {
    "id": 1,
    "login": "monalisa",
    "email": "octocat@github.com",
    "role": "direct_member",
    "created_at": "2016-11-30T06:46:10-08:00",
    "inviter": {
      "login": "other_user",
      "id": 1,
      "node_id": "MDQ6VXNlcjE=",
      "avatar_url": "https://github.com/images/error/other_user_happy.gif",
      "gravatar_id": "",
      "url": "https://api.github.com/users/other_user",
      "html_url": "https://github.com/other_user",
      "followers_url": "https://api.github.com/users/other_user/followers",
      "following_url": "https://api.github.com/users/other_user/following{/other_user}",
      "gists_url": "https://api.github.com/users/other_user/gists{/gist_id}",
      "starred_url": "https://api.github.com/users/other_user/starred{/owner}{/repo}",
      "subscriptions_url": "https://api.github.com/users/other_user/subscriptions",
      "organizations_url": "https://api.github.com/users/other_user/orgs",
      "repos_url": "https://api.github.com/users/other_user/repos",
      "events_url": "https://api.github.com/users/other_user/events{/privacy}",
      "received_events_url": "https://api.github.com/users/other_user/received_events",
      "type": "User",
      "site_admin": false
    },
    "team_count": 2,
    "invitation_team_url": "https://api.github.com/organizations/2/invitations/1/teams"
  }
]