我们经常发布文档更新,此页面的翻译可能仍在进行中。有关最新信息,请访问英文文档。如果此页面上的翻译有问题,请告诉我们

此版本的 GitHub Enterprise 将停止服务 此版本的 GitHub Enterprise 已停止服务 2020-08-20. 即使针对重大安全问题,也不会发布补丁。 要获得更好的性能、改进的安全性和新功能,请升级到 GitHub Enterprise 的最新版本。 如需升级方面的帮助,请联系 GitHub Enterprise 支持

文章版本: Enterprise Server 2.18

组织

本文内容

List organizations

Lists all organizations, in the order that they were created on GitHub Enterprise.

Note: Pagination is powered exclusively by the since parameter. Use the Link header to get the URL for the next page of organizations.

get /organizations

参数

Name Type In Description
accept string header

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

since integer query

The integer ID of the last organization that you've seen.

代码示例

Shell
curl \
  -H "Accept: application/vnd.github.v3+json" \
  https://{hostname}/organizations
JavaScript (@octokit/core.js)
await octokit.request('GET /organizations')

Default response

Status: 200 OK
[
  {
    "login": "github",
    "id": 1,
    "node_id": "MDEyOk9yZ2FuaXphdGlvbjE=",
    "url": "https://api.github.com/orgs/github",
    "repos_url": "https://api.github.com/orgs/github/repos",
    "events_url": "https://api.github.com/orgs/github/events",
    "hooks_url": "https://api.github.com/orgs/github/hooks",
    "issues_url": "https://api.github.com/orgs/github/issues",
    "members_url": "https://api.github.com/orgs/github/members{/member}",
    "public_members_url": "https://api.github.com/orgs/github/public_members{/member}",
    "avatar_url": "https://github.com/images/error/octocat_happy.gif",
    "description": "A great organization"
  }
]

Notes


Get an organization

To see many of the organization response values, you need to be an authenticated organization owner with the admin:org scope. When the value of two_factor_requirement_enabled is true, the organization requires all members, billing managers, and outside collaborators to enable two-factor authentication.

get /orgs/{org}

参数

Name Type In Description
accept string header

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

查看预览通知.
org string path

代码示例

Shell
curl \
  -H "Accept: application/vnd.github.v3+json" \
  https://{hostname}/orgs/ORG
JavaScript (@octokit/core.js)
await octokit.request('GET /orgs/{org}', {
  org: 'org'
})

Default response

Status: 200 OK
{
  "login": "github",
  "id": 1,
  "node_id": "MDEyOk9yZ2FuaXphdGlvbjE=",
  "url": "https://api.github.com/orgs/github",
  "repos_url": "https://api.github.com/orgs/github/repos",
  "events_url": "https://api.github.com/orgs/github/events",
  "hooks_url": "https://api.github.com/orgs/github/hooks",
  "issues_url": "https://api.github.com/orgs/github/issues",
  "members_url": "https://api.github.com/orgs/github/members{/member}",
  "public_members_url": "https://api.github.com/orgs/github/public_members{/member}",
  "avatar_url": "https://github.com/images/error/octocat_happy.gif",
  "description": "A great organization",
  "name": "github",
  "company": "GitHub",
  "blog": "https://github.com/blog",
  "location": "San Francisco",
  "email": "octocat@github.com",
  "has_organization_projects": true,
  "has_repository_projects": true,
  "public_repos": 2,
  "public_gists": 1,
  "followers": 20,
  "following": 0,
  "html_url": "https://github.com/octocat",
  "created_at": "2008-01-14T04:33:35Z",
  "type": "Organization",
  "total_private_repos": 100,
  "owned_private_repos": 100,
  "private_gists": 81,
  "disk_usage": 10000,
  "collaborators": 8,
  "billing_email": "support@github.com",
  "plan": {
    "name": "Medium",
    "space": 400,
    "private_repos": 20
  },
  "default_repository_permission": "read",
  "members_can_create_repositories": true,
  "two_factor_requirement_enabled": true,
  "members_allowed_repository_creation_type": "all"
}

Notes

预览通知

New repository creation permissions are available to preview. You can now use members_can_create_public_repositories, members_can_create_private_repositories, and members_can_create_internal_repositories. You can only allow members to create internal repositories if your organization is associated with an enterprise account using GitHub Enterprise Cloud or GitHub Enterprise Server 2.20+. These parameters provide more granular permissions to configure the type of repositories organization members can create.

To access these new parameters during the preview period, you must provide a custom media type in the Accept header:

application/vnd.github.surtur-preview+json

Update an organization

Note: The new members_allowed_repository_creation_type replaces the functionality of members_can_create_repositories.

Setting members_allowed_repository_creation_type will override the value of members_can_create_repositories in the following ways:

  • Setting members_allowed_repository_creation_type to all or private sets members_can_create_repositories to true.
  • Setting members_allowed_repository_creation_type to none sets members_can_create_repositories to false.
  • If you omit members_allowed_repository_creation_type, members_can_create_repositories is not modified.

Enables an authenticated organization owner with the admin:org scope to update the organization's profile and member privileges.

patch /orgs/{org}

参数

Name Type In Description
accept string header

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

查看预览通知.
org string path
billing_email string body

Billing email address. This address is not publicized.

company string body

The company name.

email string body

The publicly visible email address.

location string body

The location.

name string body

The shorthand name of the company.

description string body

The description of the company.

has_organization_projects boolean body

Toggles whether an organization can use organization projects.

has_repository_projects boolean body

Toggles whether repositories that belong to the organization can use repository projects.

default_repository_permission string body

Default permission level members have for organization repositories:
* read - can pull, but not push to or administer this repository.
* write - can pull and push, but not administer this repository.
* admin - can pull, push, and administer this repository.
* none - no permissions granted by default.

Default: read
members_can_create_repositories boolean body

Toggles the ability of non-admin organization members to create repositories. Can be one of:
* true - all organization members can create repositories.
* false - only organization owners can create repositories.
Default: true
Note: A parameter can override this parameter. See members_allowed_repository_creation_type in this table for details. Note: A parameter can override this parameter. See members_allowed_repository_creation_type in this table for details.

Default: true
members_allowed_repository_creation_type string body

Specifies which types of repositories non-admin organization members can create. Can be one of:
* all - all organization members can create public and private repositories.
* private - members can create private repositories. This option is only available to repositories that are part of an organization on GitHub Enterprise Cloud.
* none - only admin members can create repositories.
Note: Using this parameter overrides values set in members_can_create_repositories. See this note for details.

代码示例

Shell
curl \
  -X PATCH \
  -H "Accept: application/vnd.github.v3+json" \
  https://{hostname}/orgs/ORG \
  -d '{"billing_email":"billing_email"}'
JavaScript (@octokit/core.js)
await octokit.request('PATCH /orgs/{org}', {
  org: 'org',
  billing_email: 'billing_email'
})

Default response

Status: 200 OK
{
  "login": "github",
  "id": 1,
  "node_id": "MDEyOk9yZ2FuaXphdGlvbjE=",
  "url": "https://api.github.com/orgs/github",
  "repos_url": "https://api.github.com/orgs/github/repos",
  "events_url": "https://api.github.com/orgs/github/events",
  "hooks_url": "https://api.github.com/orgs/github/hooks",
  "issues_url": "https://api.github.com/orgs/github/issues",
  "members_url": "https://api.github.com/orgs/github/members{/member}",
  "public_members_url": "https://api.github.com/orgs/github/public_members{/member}",
  "avatar_url": "https://github.com/images/error/octocat_happy.gif",
  "description": "A great organization",
  "name": "github",
  "company": "GitHub",
  "blog": "https://github.com/blog",
  "location": "San Francisco",
  "email": "octocat@github.com",
  "has_organization_projects": true,
  "has_repository_projects": true,
  "public_repos": 2,
  "public_gists": 1,
  "followers": 20,
  "following": 0,
  "html_url": "https://github.com/octocat",
  "created_at": "2008-01-14T04:33:35Z",
  "type": "Organization",
  "total_private_repos": 100,
  "owned_private_repos": 100,
  "private_gists": 81,
  "disk_usage": 10000,
  "collaborators": 8,
  "billing_email": "support@github.com",
  "plan": {
    "name": "Medium",
    "space": 400,
    "private_repos": 20
  },
  "default_repository_permission": "read",
  "members_can_create_repositories": true,
  "two_factor_requirement_enabled": true,
  "members_allowed_repository_creation_type": "all"
}

Notes

预览通知

New repository creation permissions are available to preview. You can now use members_can_create_public_repositories, members_can_create_private_repositories, and members_can_create_internal_repositories. You can only allow members to create internal repositories if your organization is associated with an enterprise account using GitHub Enterprise Cloud or GitHub Enterprise Server 2.20+. These parameters provide more granular permissions to configure the type of repositories organization members can create.

To access these new parameters during the preview period, you must provide a custom media type in the Accept header:

application/vnd.github.surtur-preview+json

List organizations for the authenticated user

List organizations for the authenticated user.

OAuth scope requirements

This only lists organizations that your authorization allows you to operate on in some way (e.g., you can list teams with read:org scope, you can publicize your organization membership with user scope, etc.). Therefore, this API requires at least user or read:org scope. OAuth requests with insufficient scope receive a 403 Forbidden response.

get /user/orgs

参数

Name Type In Description
accept string header

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

per_page integer query

Results per page (max 100)

page integer query

Page number of the results to fetch.

代码示例

Shell
curl \
  -H "Accept: application/vnd.github.v3+json" \
  https://{hostname}/user/orgs
JavaScript (@octokit/core.js)
await octokit.request('GET /user/orgs')

Default response

Status: 200 OK
[
  {
    "login": "github",
    "id": 1,
    "node_id": "MDEyOk9yZ2FuaXphdGlvbjE=",
    "url": "https://api.github.com/orgs/github",
    "repos_url": "https://api.github.com/orgs/github/repos",
    "events_url": "https://api.github.com/orgs/github/events",
    "hooks_url": "https://api.github.com/orgs/github/hooks",
    "issues_url": "https://api.github.com/orgs/github/issues",
    "members_url": "https://api.github.com/orgs/github/members{/member}",
    "public_members_url": "https://api.github.com/orgs/github/public_members{/member}",
    "avatar_url": "https://github.com/images/error/octocat_happy.gif",
    "description": "A great organization"
  }
]

List organizations for a user

List public organization memberships for the specified user.

This method only lists public memberships, regardless of authentication. If you need to fetch all of the organization memberships (public and private) for the authenticated user, use the List organizations for the authenticated user API instead.

get /users/{username}/orgs

参数

Name Type In Description
accept string header

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

username string path
per_page integer query

Results per page (max 100)

page integer query

Page number of the results to fetch.

代码示例

Shell
curl \
  -H "Accept: application/vnd.github.v3+json" \
  https://{hostname}/users/USERNAME/orgs
JavaScript (@octokit/core.js)
await octokit.request('GET /users/{username}/orgs', {
  username: 'username'
})

Default response

Status: 200 OK
[
  {
    "login": "github",
    "id": 1,
    "node_id": "MDEyOk9yZ2FuaXphdGlvbjE=",
    "url": "https://api.github.com/orgs/github",
    "repos_url": "https://api.github.com/orgs/github/repos",
    "events_url": "https://api.github.com/orgs/github/events",
    "hooks_url": "https://api.github.com/orgs/github/hooks",
    "issues_url": "https://api.github.com/orgs/github/issues",
    "members_url": "https://api.github.com/orgs/github/members{/member}",
    "public_members_url": "https://api.github.com/orgs/github/public_members{/member}",
    "avatar_url": "https://github.com/images/error/octocat_happy.gif",
    "description": "A great organization"
  }
]

Notes


阻止用户

用于对调用进行身份验证的令牌必须具有 admin:org 作用域才可对组织进行任何阻止调用。 否则,响应将返回 HTTP 404

成员

List organization members

List all users who are members of an organization. If the authenticated user is also a member of this organization then both concealed and public members will be returned.

get /orgs/{org}/members

参数

Name Type In Description
accept string header

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

org string path
filter string query

Filter members returned in the list. Can be one of:
* 2fa_disabled - Members without two-factor authentication enabled. Available for organization owners.
* all - All members the authenticated user can see.

role string query

Filter members returned by their role. Can be one of:
* all - All members of the organization, regardless of role.
* admin - Organization owners.
* member - Non-owner organization members.

per_page integer query

Results per page (max 100)

page integer query

Page number of the results to fetch.

代码示例

Shell
curl \
  -H "Accept: application/vnd.github.v3+json" \
  https://{hostname}/orgs/ORG/members
JavaScript (@octokit/core.js)
await octokit.request('GET /orgs/{org}/members', {
  org: 'org'
})

Default response

Status: 200 OK
[
  {
    "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
  }
]

Response if requester is not an organization member

Status: 302 Found

Notes


Check organization membership for a user

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

get /orgs/{org}/members/{username}

参数

Name Type In Description
accept string header

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

org string path
username string path

代码示例

Shell
curl \
  -H "Accept: application/vnd.github.v3+json" \
  https://{hostname}/orgs/ORG/members/USERNAME
JavaScript (@octokit/core.js)
await octokit.request('GET /orgs/{org}/members/{username}', {
  org: 'org',
  username: 'username'
})

Response if requester is an organization member and user is a member

Status: 204 No Content

Response if requester is not an organization member

Status: 302 Found

Response if requester is an organization member and user is not a member

Status: 404 Not Found

Notes


Remove an organization member

Removing a user from this list will remove them from all teams and they will no longer have any access to the organization's repositories.

delete /orgs/{org}/members/{username}

参数

Name Type In Description
accept string header

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

org string path
username string path

代码示例

Shell
curl \
  -X DELETE \
  -H "Accept: application/vnd.github.v3+json" \
  https://{hostname}/orgs/ORG/members/USERNAME
JavaScript (@octokit/core.js)
await octokit.request('DELETE /orgs/{org}/members/{username}', {
  org: 'org',
  username: 'username'
})

Default Response

Status: 204 No Content

Notes


Get organization membership for a user

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

get /orgs/{org}/memberships/{username}

参数

Name Type In Description
accept string header

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

org string path
username string path

代码示例

Shell
curl \
  -H "Accept: application/vnd.github.v3+json" \
  https://{hostname}/orgs/ORG/memberships/USERNAME
JavaScript (@octokit/core.js)
await octokit.request('GET /orgs/{org}/memberships/{username}', {
  org: 'org',
  username: 'username'
})

Response if user has an active admin membership with organization

Status: 200 OK
{
  "url": "https://api.github.com/orgs/octocat/memberships/defunkt",
  "state": "active",
  "role": "admin",
  "organization_url": "https://api.github.com/orgs/octocat",
  "organization": {
    "login": "github",
    "id": 1,
    "node_id": "MDEyOk9yZ2FuaXphdGlvbjE=",
    "url": "https://api.github.com/orgs/github",
    "repos_url": "https://api.github.com/orgs/github/repos",
    "events_url": "https://api.github.com/orgs/github/events",
    "hooks_url": "https://api.github.com/orgs/github/hooks",
    "issues_url": "https://api.github.com/orgs/github/issues",
    "members_url": "https://api.github.com/orgs/github/members{/member}",
    "public_members_url": "https://api.github.com/orgs/github/public_members{/member}",
    "avatar_url": "https://github.com/images/error/octocat_happy.gif",
    "description": "A great organization"
  },
  "user": {
    "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
  }
}

Response if user has an active membership with organization

Status: 200 OK
{
  "url": "https://api.github.com/orgs/octocat/memberships/defunkt",
  "state": "active",
  "role": "member",
  "organization_url": "https://api.github.com/orgs/octocat",
  "organization": {
    "login": "github",
    "id": 1,
    "node_id": "MDEyOk9yZ2FuaXphdGlvbjE=",
    "url": "https://api.github.com/orgs/github",
    "repos_url": "https://api.github.com/orgs/github/repos",
    "events_url": "https://api.github.com/orgs/github/events",
    "hooks_url": "https://api.github.com/orgs/github/hooks",
    "issues_url": "https://api.github.com/orgs/github/issues",
    "members_url": "https://api.github.com/orgs/github/members{/member}",
    "public_members_url": "https://api.github.com/orgs/github/public_members{/member}",
    "avatar_url": "https://github.com/images/error/octocat_happy.gif",
    "description": "A great organization"
  },
  "user": {
    "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
  }
}

Response if user has a pending membership with organization

Status: 200 OK
{
  "url": "https://api.github.com/orgs/invitocat/memberships/defunkt",
  "state": "pending",
  "role": "member",
  "organization_url": "https://api.github.com/orgs/invitocat",
  "organization": {
    "login": "github",
    "id": 1,
    "node_id": "MDEyOk9yZ2FuaXphdGlvbjE=",
    "url": "https://api.github.com/orgs/github",
    "repos_url": "https://api.github.com/orgs/github/repos",
    "events_url": "https://api.github.com/orgs/github/events",
    "hooks_url": "https://api.github.com/orgs/github/hooks",
    "issues_url": "https://api.github.com/orgs/github/issues",
    "members_url": "https://api.github.com/orgs/github/members{/member}",
    "public_members_url": "https://api.github.com/orgs/github/public_members{/member}",
    "avatar_url": "https://github.com/images/error/octocat_happy.gif",
    "description": "A great organization"
  },
  "user": {
    "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
  }
}

Notes


Set organization membership for a user

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

put /orgs/{org}/memberships/{username}

参数

Name Type In Description
accept string header

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

org string path
username string path
role string body

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.

Default: member

代码示例

Shell
curl \
  -X PUT \
  -H "Accept: application/vnd.github.v3+json" \
  https://{hostname}/orgs/ORG/memberships/USERNAME \
  -d '{"role":"role"}'
JavaScript (@octokit/core.js)
await octokit.request('PUT /orgs/{org}/memberships/{username}', {
  org: 'org',
  username: 'username',
  role: 'role'
})

Default response

Status: 200 OK
{
  "url": "https://api.github.com/orgs/octocat/memberships/defunkt",
  "state": "active",
  "role": "admin",
  "organization_url": "https://api.github.com/orgs/octocat",
  "organization": {
    "login": "github",
    "id": 1,
    "node_id": "MDEyOk9yZ2FuaXphdGlvbjE=",
    "url": "https://api.github.com/orgs/github",
    "repos_url": "https://api.github.com/orgs/github/repos",
    "events_url": "https://api.github.com/orgs/github/events",
    "hooks_url": "https://api.github.com/orgs/github/hooks",
    "issues_url": "https://api.github.com/orgs/github/issues",
    "members_url": "https://api.github.com/orgs/github/members{/member}",
    "public_members_url": "https://api.github.com/orgs/github/public_members{/member}",
    "avatar_url": "https://github.com/images/error/octocat_happy.gif",
    "description": "A great organization"
  },
  "user": {
    "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
  }
}

Notes


Remove organization membership for a user

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.

delete /orgs/{org}/memberships/{username}

参数

Name Type In Description
accept string header

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

org string path
username string path

代码示例

Shell
curl \
  -X DELETE \
  -H "Accept: application/vnd.github.v3+json" \
  https://{hostname}/orgs/ORG/memberships/USERNAME
JavaScript (@octokit/core.js)
await octokit.request('DELETE /orgs/{org}/memberships/{username}', {
  org: 'org',
  username: 'username'
})

Default Response

Status: 204 No Content

Notes


List public organization members

Members of an organization can choose to have their membership publicized or not.

get /orgs/{org}/public_members

参数

Name Type In Description
accept string header

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

org string path
per_page integer query

Results per page (max 100)

page integer query

Page number of the results to fetch.

代码示例

Shell
curl \
  -H "Accept: application/vnd.github.v3+json" \
  https://{hostname}/orgs/ORG/public_members
JavaScript (@octokit/core.js)
await octokit.request('GET /orgs/{org}/public_members', {
  org: 'org'
})

Default response

Status: 200 OK
[
  {
    "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
  }
]

Notes


get /orgs/{org}/public_members/{username}

参数

Name Type In Description
accept string header

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

org string path
username string path

代码示例

Shell
curl \
  -H "Accept: application/vnd.github.v3+json" \
  https://{hostname}/orgs/ORG/public_members/USERNAME
JavaScript (@octokit/core.js)
await octokit.request('GET /orgs/{org}/public_members/{username}', {
  org: 'org',
  username: 'username'
})

Response if user is a public member

Status: 204 No Content

Response if user is not a public member

Status: 404 Not Found

Notes


Set public organization membership for the authenticated user

The user can publicize their own membership. (A user cannot publicize the membership for another user.)

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

put /orgs/{org}/public_members/{username}

参数

Name Type In Description
accept string header

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

org string path
username string path

代码示例

Shell
curl \
  -X PUT \
  -H "Accept: application/vnd.github.v3+json" \
  https://{hostname}/orgs/ORG/public_members/USERNAME
JavaScript (@octokit/core.js)
await octokit.request('PUT /orgs/{org}/public_members/{username}', {
  org: 'org',
  username: 'username'
})

Default Response

Status: 204 No Content

delete /orgs/{org}/public_members/{username}

参数

Name Type In Description
accept string header

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

org string path
username string path

代码示例

Shell
curl \
  -X DELETE \
  -H "Accept: application/vnd.github.v3+json" \
  https://{hostname}/orgs/ORG/public_members/USERNAME
JavaScript (@octokit/core.js)
await octokit.request('DELETE /orgs/{org}/public_members/{username}', {
  org: 'org',
  username: 'username'
})

Default Response

Status: 204 No Content

get /user/memberships/orgs

参数

Name Type In Description
accept string header

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

state string query

Indicates the state of the memberships to return. Can be either active or pending. If not specified, the API returns both active and pending memberships.

per_page integer query

Results per page (max 100)

page integer query

Page number of the results to fetch.

代码示例

Shell
curl \
  -H "Accept: application/vnd.github.v3+json" \
  https://{hostname}/user/memberships/orgs
JavaScript (@octokit/core.js)
await octokit.request('GET /user/memberships/orgs')

Default response

Status: 200 OK
[
  {
    "url": "https://api.github.com/orgs/octocat/memberships/defunkt",
    "state": "active",
    "role": "admin",
    "organization_url": "https://api.github.com/orgs/octocat",
    "organization": {
      "login": "github",
      "id": 1,
      "node_id": "MDEyOk9yZ2FuaXphdGlvbjE=",
      "url": "https://api.github.com/orgs/github",
      "repos_url": "https://api.github.com/orgs/github/repos",
      "events_url": "https://api.github.com/orgs/github/events",
      "hooks_url": "https://api.github.com/orgs/github/hooks",
      "issues_url": "https://api.github.com/orgs/github/issues",
      "members_url": "https://api.github.com/orgs/github/members{/member}",
      "public_members_url": "https://api.github.com/orgs/github/public_members{/member}",
      "avatar_url": "https://github.com/images/error/octocat_happy.gif",
      "description": "A great organization"
    },
    "user": {
      "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
    }
  },
  {
    "url": "https://api.github.com/orgs/invitocat/memberships/defunkt",
    "state": "pending",
    "role": "admin",
    "organization_url": "https://api.github.com/orgs/invitocat",
    "organization": {
      "login": "github",
      "id": 1,
      "node_id": "MDEyOk9yZ2FuaXphdGlvbjE=",
      "url": "https://api.github.com/orgs/github",
      "repos_url": "https://api.github.com/orgs/github/repos",
      "events_url": "https://api.github.com/orgs/github/events",
      "hooks_url": "https://api.github.com/orgs/github/hooks",
      "issues_url": "https://api.github.com/orgs/github/issues",
      "members_url": "https://api.github.com/orgs/github/members{/member}",
      "public_members_url": "https://api.github.com/orgs/github/public_members{/member}",
      "avatar_url": "https://github.com/images/error/octocat_happy.gif",
      "description": "A great organization"
    },
    "user": {
      "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 /user/memberships/orgs/{org}

参数

Name Type In Description
accept string header

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

org string path

代码示例

Shell
curl \
  -H "Accept: application/vnd.github.v3+json" \
  https://{hostname}/user/memberships/orgs/ORG
JavaScript (@octokit/core.js)
await octokit.request('GET /user/memberships/orgs/{org}', {
  org: 'org'
})

Default response

Status: 200 OK
{
  "url": "https://api.github.com/orgs/invitocat/memberships/defunkt",
  "state": "pending",
  "role": "admin",
  "organization_url": "https://api.github.com/orgs/invitocat",
  "organization": {
    "login": "github",
    "id": 1,
    "node_id": "MDEyOk9yZ2FuaXphdGlvbjE=",
    "url": "https://api.github.com/orgs/github",
    "repos_url": "https://api.github.com/orgs/github/repos",
    "events_url": "https://api.github.com/orgs/github/events",
    "hooks_url": "https://api.github.com/orgs/github/hooks",
    "issues_url": "https://api.github.com/orgs/github/issues",
    "members_url": "https://api.github.com/orgs/github/members{/member}",
    "public_members_url": "https://api.github.com/orgs/github/public_members{/member}",
    "avatar_url": "https://github.com/images/error/octocat_happy.gif",
    "description": "A great organization"
  },
  "user": {
    "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
  }
}

patch /user/memberships/orgs/{org}

参数

Name Type In Description
accept string header

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

org string path
state string body

Required. The state that the membership should be in. Only "active" will be accepted.

代码示例

Shell
curl \
  -X PATCH \
  -H "Accept: application/vnd.github.v3+json" \
  https://{hostname}/user/memberships/orgs/ORG \
  -d '{"state":"state"}'
JavaScript (@octokit/core.js)
await octokit.request('PATCH /user/memberships/orgs/{org}', {
  org: 'org',
  state: 'state'
})

Default response

Status: 200 OK
{
  "url": "https://api.github.com/orgs/octocat/memberships/defunkt",
  "state": "active",
  "role": "admin",
  "organization_url": "https://api.github.com/orgs/octocat",
  "organization": {
    "login": "github",
    "id": 1,
    "node_id": "MDEyOk9yZ2FuaXphdGlvbjE=",
    "url": "https://api.github.com/orgs/github",
    "repos_url": "https://api.github.com/orgs/github/repos",
    "events_url": "https://api.github.com/orgs/github/events",
    "hooks_url": "https://api.github.com/orgs/github/hooks",
    "issues_url": "https://api.github.com/orgs/github/issues",
    "members_url": "https://api.github.com/orgs/github/members{/member}",
    "public_members_url": "https://api.github.com/orgs/github/public_members{/member}",
    "avatar_url": "https://github.com/images/error/octocat_happy.gif",
    "description": "A great organization"
  },
  "user": {
    "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
  }
}

外部协作者

Web 挂钩

组织 web 挂钩允许您在组织内发生特定事件时接收 HTTP POST 有效负载。 订阅这些事件可以构建对 GitHub.com 上的操作做出反应的集成。 有关您可以订阅的操作的更多信息,请参阅“GitHub 事件类型”。

范围和限制

对组织 web 挂钩的所有操作都需要经过身份验证的用户是所管理组织的管理员。 此外,OAuth 令牌需要 admin:org_hook 作用域。 更多信息请参阅“OAuth 应用程序的作用域”。

为了保护 web 挂钩配置中可能存在的敏感数据,我们还强制实施以下访问控制规则:

  • OAuth 应用程序无法列出、查看或编辑不是它们创建的 web 挂钩。
  • 用户无法列出、查看或编辑由 OAuth 应用程序创建的 web 挂钩。

接收 web 挂钩

为了让 GitHub Enterprise 发送 web 挂钩有效负载,您的服务器需要能够从 Internet 访问。 我们还强烈建议使用 SSL,以便我们可以通过 HTTPS 发送加密的有效负载。

有关更多最佳实践,请参阅我们的指南

Web 挂钩标头

GitHub Enterprise 发送时将附带几个 HTTP 标头,以区分事件类型和有效负载标识符。 更多信息请参阅 web 挂钩标头

get /orgs/{org}/hooks

参数

Name Type In Description
accept string header

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

org string path
per_page integer query

Results per page (max 100)

page integer query

Page number of the results to fetch.

代码示例

Shell
curl \
  -H "Accept: application/vnd.github.v3+json" \
  https://{hostname}/orgs/ORG/hooks
JavaScript (@octokit/core.js)
await octokit.request('GET /orgs/{org}/hooks', {
  org: 'org'
})

Default response

Status: 200 OK
[
  {
    "id": 1,
    "url": "https://api.github.com/orgs/octocat/hooks/1",
    "ping_url": "https://api.github.com/orgs/octocat/hooks/1/pings",
    "name": "web",
    "events": [
      "push",
      "pull_request"
    ],
    "active": true,
    "config": {
      "url": "http://example.com",
      "content_type": "json"
    },
    "updated_at": "2011-09-06T20:39:23Z",
    "created_at": "2011-09-06T17:26:27Z"
  }
]

Notes


Create an organization webhook

Here's how you can create a hook that posts payloads in JSON format:

post /orgs/{org}/hooks

参数

Name Type In Description
accept string header

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

org string path
name string body

Required. Must be passed as "web".

config object body

Required. Key/value pairs to provide settings for this webhook. These are defined below.

Properties of the config object

url (string)

Required. The URL to which the payloads will be delivered.

content_type (string)

The media type used to serialize the payloads. Supported values include json and form. The default is form.

secret (string)

If provided, the secret will be used as the key to generate the HMAC hex digest value in the X-Hub-Signature header.

insecure_ssl (string)

Determines whether the SSL certificate of the host for url will be verified when delivering payloads. Supported values include 0 (verification is performed) and 1 (verification is not performed). The default is 0. We strongly recommend not setting this to 1 as you are subject to man-in-the-middle and other attacks.

events array of strings body

Determines what events the hook is triggered for.

Default: push
active boolean body

Determines if notifications are sent when the webhook is triggered. Set to true to send notifications.

Default: true

代码示例

Shell
curl \
  -X POST \
  -H "Accept: application/vnd.github.v3+json" \
  https://{hostname}/orgs/ORG/hooks \
  -d '{"name":"name","config":{"url":"url","content_type":"content_type","secret":"secret","insecure_ssl":"insecure_ssl"}}'
JavaScript (@octokit/core.js)
await octokit.request('POST /orgs/{org}/hooks', {
  org: 'org',
  name: 'name',
  config: {
    url: 'url',
    content_type: 'content_type',
    secret: 'secret',
    insecure_ssl: 'insecure_ssl'
  }
})

Default response

Status: 201 Created
{
  "id": 1,
  "url": "https://api.github.com/orgs/octocat/hooks/1",
  "ping_url": "https://api.github.com/orgs/octocat/hooks/1/pings",
  "name": "web",
  "events": [
    "push",
    "pull_request"
  ],
  "active": true,
  "config": {
    "url": "http://example.com",
    "content_type": "json"
  },
  "updated_at": "2011-09-06T20:39:23Z",
  "created_at": "2011-09-06T17:26:27Z"
}

Notes


get /orgs/{org}/hooks/{hook_id}

参数

Name Type In Description
accept string header

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

org string path
hook_id integer path

代码示例

Shell
curl \
  -H "Accept: application/vnd.github.v3+json" \
  https://{hostname}/orgs/ORG/hooks/42
JavaScript (@octokit/core.js)
await octokit.request('GET /orgs/{org}/hooks/{hook_id}', {
  org: 'org',
  hook_id: 42
})

Default response

Status: 200 OK
{
  "id": 1,
  "url": "https://api.github.com/orgs/octocat/hooks/1",
  "ping_url": "https://api.github.com/orgs/octocat/hooks/1/pings",
  "name": "web",
  "events": [
    "push",
    "pull_request"
  ],
  "active": true,
  "config": {
    "url": "http://example.com",
    "content_type": "json"
  },
  "updated_at": "2011-09-06T20:39:23Z",
  "created_at": "2011-09-06T17:26:27Z"
}

Notes


patch /orgs/{org}/hooks/{hook_id}

参数

Name Type In Description
accept string header

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

org string path
hook_id integer path
config object body

Key/value pairs to provide settings for this webhook. These are defined below.

Properties of the config object

url (string)

Required. The URL to which the payloads will be delivered.

content_type (string)

The media type used to serialize the payloads. Supported values include json and form. The default is form.

secret (string)

If provided, the secret will be used as the key to generate the HMAC hex digest value in the X-Hub-Signature header.

insecure_ssl (string)

Determines whether the SSL certificate of the host for url will be verified when delivering payloads. Supported values include 0 (verification is performed) and 1 (verification is not performed). The default is 0. We strongly recommend not setting this to 1 as you are subject to man-in-the-middle and other attacks.

events array of strings body

Determines what events the hook is triggered for.

Default: push
active boolean body

Determines if notifications are sent when the webhook is triggered. Set to true to send notifications.

Default: true

代码示例

Shell
curl \
  -X PATCH \
  -H "Accept: application/vnd.github.v3+json" \
  https://{hostname}/orgs/ORG/hooks/42 \
  -d '{"config":{"url":"url","content_type":"content_type","secret":"secret","insecure_ssl":"insecure_ssl"}}'
JavaScript (@octokit/core.js)
await octokit.request('PATCH /orgs/{org}/hooks/{hook_id}', {
  org: 'org',
  hook_id: 42,
  config: {
    url: 'url',
    content_type: 'content_type',
    secret: 'secret',
    insecure_ssl: 'insecure_ssl'
  }
})

Default response

Status: 200 OK
{
  "id": 1,
  "url": "https://api.github.com/orgs/octocat/hooks/1",
  "ping_url": "https://api.github.com/orgs/octocat/hooks/1/pings",
  "name": "web",
  "events": [
    "pull_request"
  ],
  "active": true,
  "config": {
    "url": "http://example.com",
    "content_type": "json"
  },
  "updated_at": "2011-09-06T20:39:23Z",
  "created_at": "2011-09-06T17:26:27Z"
}

Notes


delete /orgs/{org}/hooks/{hook_id}

参数

Name Type In Description
accept string header

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

org string path
hook_id integer path

代码示例

Shell
curl \
  -X DELETE \
  -H "Accept: application/vnd.github.v3+json" \
  https://{hostname}/orgs/ORG/hooks/42
JavaScript (@octokit/core.js)
await octokit.request('DELETE /orgs/{org}/hooks/{hook_id}', {
  org: 'org',
  hook_id: 42
})

Default Response

Status: 204 No Content

Notes


Ping an organization webhook

This will trigger a ping event to be sent to the hook.

post /orgs/{org}/hooks/{hook_id}/pings

参数

Name Type In Description
accept string header

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

org string path
hook_id integer path

代码示例

Shell
curl \
  -X POST \
  -H "Accept: application/vnd.github.v3+json" \
  https://{hostname}/orgs/ORG/hooks/42/pings
JavaScript (@octokit/core.js)
await octokit.request('POST /orgs/{org}/hooks/{hook_id}/pings', {
  org: 'org',
  hook_id: 42
})

Default Response

Status: 204 No Content

Notes


问问别人

找不到要找的内容?

联系我们