Skip to main content

此版本的 GitHub Enterprise 已停止服务 2022-10-12. 即使针对重大安全问题,也不会发布补丁。 为了获得更好的性能、更高的安全性和新功能,请升级到最新版本的 GitHub Enterprise。 如需升级帮助,请联系 GitHub Enterprise 支持

团队成员

关于团队成员 API

此 API 仅供团队组织中经过身份验证的成员使用。 OAuth 访问令牌需要 read:org 作用域。 GitHub 从团队 name 生成团队的 slug

注意:如果为具有组织身份提供程序 (IdP) 的团队设置了团队同步,当尝试使用 API 更改团队的成员身份时,则会看到错误。 如果您有权访问 IdP 中的组成员身份,可以通过身份提供程序管理 GitHub 团队成员身份,该提供程序会自动添� 和� 除组织的成员。 有关详细信息,请参阅“在� �识提供者与 GitHub 之间同步团队”。

List team members

Team members will include the members of child teams.

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

参数

Headers
Name, Type, Description
acceptstring

Setting to application/vnd.github+json is recommended.

Path parameters
Name, Type, Description
orgstringRequired

The organization name. The name is not case sensitive.

team_slugstringRequired

The slug of the team name.

Query parameters
Name, Type, Description
rolestring

Filters members returned by their role in the team.

Default: all

Can be one of: member, maintainer, all

per_pageinteger

The number of results per page (max 100).

Default: 30

pageinteger

Page number of the results to fetch.

Default: 1

HTTP 响应状态代� �

状态代� �说明
200

OK

代� �示例

get/orgs/{org}/teams/{team_slug}/members
curl \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ http(s)://HOSTNAME/api/v3/orgs/ORG/teams/TEAM_SLUG/members

Response

Status: 200
[ { "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 membership for a user

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.

Note: You can also specify a team by org_id and team_id using the route GET /organizations/{org_id}/team/{team_id}/memberships/{username}.

Note: The response contains the state of the membership and the member's role.

The role for organization owners is set to maintainer. For more information about maintainer roles, see see Create a team.

参数

Headers
Name, Type, Description
acceptstring

Setting to application/vnd.github+json is recommended.

Path parameters
Name, Type, Description
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.

HTTP 响应状态代� �

状态代� �说明
200

OK

404

if user has no team membership

代� �示例

get/orgs/{org}/teams/{team_slug}/memberships/{username}
curl \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ http(s)://HOSTNAME/api/v3/orgs/ORG/teams/TEAM_SLUG/memberships/USERNAME

Response if user is a team maintainer

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

Add or update team membership for a user

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

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

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 Enterprise Server 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 Enterprise Server."

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}.

参数

Headers
Name, Type, Description
acceptstring

Setting to application/vnd.github+json is recommended.

Path parameters
Name, Type, Description
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.

Body parameters
Name, Type, Description
rolestring

The role that this user should have in the team.

Default: member

Can be one of: member, maintainer

HTTP 响应状态代� �

状态代� �说明
200

OK

403

Forbidden if team synchronization is set up

422

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

代� �示例

put/orgs/{org}/teams/{team_slug}/memberships/{username}
curl \ -X PUT \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ http(s)://HOSTNAME/api/v3/orgs/ORG/teams/TEAM_SLUG/memberships/USERNAME \ -d '{"role":"maintainer"}'

Response if user's membership with team is now pending

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

Remove team membership for a user

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

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. Removing team membership does not delete the user, it just removes their membership from the team.

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 Enterprise Server 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 Enterprise Server."

Note: You can also specify a team by org_id and team_id using the route DELETE /organizations/{org_id}/team/{team_id}/memberships/{username}.

参数

Headers
Name, Type, Description
acceptstring

Setting to application/vnd.github+json is recommended.

Path parameters
Name, Type, Description
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.

HTTP 响应状态代� �

状态代� �说明
204

No Content

403

Forbidden if team synchronization is set up

代� �示例

delete/orgs/{org}/teams/{team_slug}/memberships/{username}
curl \ -X DELETE \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ http(s)://HOSTNAME/api/v3/orgs/ORG/teams/TEAM_SLUG/memberships/USERNAME

Response

Status: 204

List team members (Legacy)

Deprecation Notice: This endpoint route is deprecated and will be removed from the Teams API. We recommend migrating your existing code to use the new List team members endpoint.

Team members will include the members of child teams.

参数

Headers
Name, Type, Description
acceptstring

Setting to application/vnd.github+json is recommended.

Path parameters
Name, Type, Description
team_idintegerRequired

The unique identifier of the team.

Query parameters
Name, Type, Description
rolestring

Filters members returned by their role in the team.

Default: all

Can be one of: member, maintainer, all

per_pageinteger

The number of results per page (max 100).

Default: 30

pageinteger

Page number of the results to fetch.

Default: 1

HTTP 响应状态代� �

状态代� �说明
200

OK

404

Resource not found

代� �示例

get/teams/{team_id}/members
curl \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ http(s)://HOSTNAME/api/v3/teams/TEAM_ID/members

Response

Status: 200
[ { "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 (Legacy)

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

We recommend using the Get team membership for a user endpoint 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.

参数

Headers
Name, Type, Description
acceptstring

Setting to application/vnd.github+json is recommended.

Path parameters
Name, Type, Description
team_idintegerRequired

The unique identifier of the team.

usernamestringRequired

The handle for the GitHub user account.

HTTP 响应状态代� �

状态代� �说明
204

if user is a member

404

if user is not a member

代� �示例

get/teams/{team_id}/members/{username}
curl \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ http(s)://HOSTNAME/api/v3/teams/TEAM_ID/members/USERNAME

if user is a member

Status: 204

Add team member (Legacy)

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

We recommend using the Add or update team membership for a user endpoint instead. It allows you to invite new organization members to your teams.

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

To add someone to a team, the authenticated user must be an organization owner or a team maintainer in the team they're changing. The person being added to the team must be a member of the team's organization.

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 Enterprise Server 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 Enterprise Server."

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

参数

Headers
Name, Type, Description
acceptstring

Setting to application/vnd.github+json is recommended.

Path parameters
Name, Type, Description
team_idintegerRequired

The unique identifier of the team.

usernamestringRequired

The handle for the GitHub user account.

HTTP 响应状态代� �

状态代� �说明
204

No Content

403

Forbidden

404

Not Found if team synchronization is set up

422

Unprocessable Entity if you attempt to add an organization to a team or you attempt to add a user to a team when they are not a member of at least one other team in the same organization

代� �示例

put/teams/{team_id}/members/{username}
curl \ -X PUT \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ http(s)://HOSTNAME/api/v3/teams/TEAM_ID/members/USERNAME

Response

Status: 204

Remove team member (Legacy)

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

We recommend using the Remove team membership for a user endpoint instead. It allows you to remove both active and pending memberships.

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

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

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 Enterprise Server 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 Enterprise Server."

参数

Headers
Name, Type, Description
acceptstring

Setting to application/vnd.github+json is recommended.

Path parameters
Name, Type, Description
team_idintegerRequired

The unique identifier of the team.

usernamestringRequired

The handle for the GitHub user account.

HTTP 响应状态代� �

状态代� �说明
204

No Content

404

Not Found if team synchronization is setup

代� �示例

delete/teams/{team_id}/members/{username}
curl \ -X DELETE \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ http(s)://HOSTNAME/api/v3/teams/TEAM_ID/members/USERNAME

Response

Status: 204

Get team membership for a user (Legacy)

Deprecation Notice: This endpoint route is deprecated and will be removed from the Teams API. We recommend migrating your existing code to use the new Get team membership for a user endpoint.

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.

Note: The response contains the state of the membership and the member's role.

The role for organization owners is set to maintainer. For more information about maintainer roles, see Create a team.

参数

Headers
Name, Type, Description
acceptstring

Setting to application/vnd.github+json is recommended.

Path parameters
Name, Type, Description
team_idintegerRequired

The unique identifier of the team.

usernamestringRequired

The handle for the GitHub user account.

HTTP 响应状态代� �

状态代� �说明
200

OK

404

Resource not found

代� �示例

get/teams/{team_id}/memberships/{username}
curl \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ http(s)://HOSTNAME/api/v3/teams/TEAM_ID/memberships/USERNAME

Response if user is a team maintainer

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

Add or update team membership for a user (Legacy)

Deprecation Notice: This endpoint route is deprecated 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 Enterprise Server 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 Enterprise Server."

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.

参数

Headers
Name, Type, Description
acceptstring

Setting to application/vnd.github+json is recommended.

Path parameters
Name, Type, Description
team_idintegerRequired

The unique identifier of the team.

usernamestringRequired

The handle for the GitHub user account.

Body parameters
Name, Type, Description
rolestring

The role that this user should have in the team.

Default: member

Can be one of: member, maintainer

HTTP 响应状态代� �

状态代� �说明
200

OK

403

Forbidden if team synchronization is set up

404

Resource not found

422

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

代� �示例

put/teams/{team_id}/memberships/{username}
curl \ -X PUT \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ http(s)://HOSTNAME/api/v3/teams/TEAM_ID/memberships/USERNAME \ -d '{"role":"member"}'

Response if user's membership with team is now pending

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

Remove team membership for a user (Legacy)

Deprecation Notice: This endpoint route is deprecated and will be removed from the Teams API. We recommend migrating your existing code to use the new Remove 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.

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. Removing team membership does not delete the user, it just removes their membership from the team.

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 Enterprise Server 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 Enterprise Server."

参数

Headers
Name, Type, Description
acceptstring

Setting to application/vnd.github+json is recommended.

Path parameters
Name, Type, Description
team_idintegerRequired

The unique identifier of the team.

usernamestringRequired

The handle for the GitHub user account.

HTTP 响应状态代� �

状态代� �说明
204

No Content

403

if team synchronization is set up

代� �示例

delete/teams/{team_id}/memberships/{username}
curl \ -X DELETE \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ http(s)://HOSTNAME/api/v3/teams/TEAM_ID/memberships/USERNAME

Response

Status: 204