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

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

文章版本: Enterprise Server 2.18

GitHub Enterprise administration

本文内容

In addition to the GitHub.com API, these GitHub Enterprise Server-specific endpoints are available.

端点 URL

REST API 端点(管理控制台 API 端点除外)的前缀为以下 URL:

http(s)://hostname/api/v3/

管理控制台 API 端点是唯一以主机名为前缀的端点:

http(s)://hostname/

身份验证

GitHub Enterprise 安装设施的 API 端点接受与 GitHub.com 相同的身份验证方法。 您可以使用 OAuth 令牌(可使用授权 API 创建)或基本身份验证来验证自己。 OAuth 令牌用于企业特定的端点时必须具有 site_admin OAuth 作用域

企业管理 API 端点只有经过身份验证的 GitHub Enterprise 站点管理员可以访问,但管理控制台 API 例外,它需要管理控制台密码

版本信息

每个 API 的响应标头中都会返回 GitHub Enterprise 实例的当前版本:X-GitHub-Enterprise-Version: 2.18.0 您也可以通过调用元端点来读取当前版本。

管理统计

管理统计 API 提供有关安装设施的各种指标。 它只适用于经过身份验证的站点管理员。普通用户尝试访问它时会收到 404 响应。

全局 web 挂钩

全局 web 挂钩安装在 GitHub Enterprise 实例上。 您可以使用全局 web 挂钩来自动监视、响应或实施针对实例上的用户、组织、团队和仓库的规则。 全局 web 挂钩可以订阅组织用户仓库团队成员成员身份复刻ping 事件类型。

此 API 只适用于经过身份验证的站点管理员。普通用户尝试访问它时会收到 404 响应。 要了解如何配置全局 web 挂钩,请参阅关于全局 web 挂钩

LDAP

您可以使用 LDAP API 来更新 GitHub Enterprise Server 用户或团队与其关联的 LDAP 条目之间的帐户关系,或者排队新同步。

通过 LDAP 映射端点,您可以更新用户或团队所映射的识别名称 (DN) 。 请注意,LDAP 端点通常只在您的 GitHub Enterprise Server 设备启用了 LDAP 同步时才有效。 启用了 LDAP 后,即使禁用 LDAP 同步,也可以使用更新用户的 LDAP 映射端点。

Update LDAP mapping for a team

Updates the distinguished name (DN) of the LDAP entry to map to a team. LDAP synchronization must be enabled to map LDAP entries to a team. Use the Create a team endpoint to create a team with LDAP mapping.

If you pass the hellcat-preview media type, you can also update the LDAP mapping of a child team.

patch /admin/ldap/teams/{team_id}/mapping

参数

Name Type In Description
accept string header

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

查看预览通知.
team_id integer path
ldap_dn string body

The distinguished name (DN) of the LDAP entry to map to a team.

代码示例

Shell
curl \
  -X PATCH \
  -H "Accept: application/vnd.github.v3+json" \
  https://{hostname}/admin/ldap/teams/42/mapping \
  -d '{"ldap_dn":"ldap_dn"}'
JavaScript (@octokit/core.js)
await octokit.request('PATCH /admin/ldap/teams/{team_id}/mapping', {
  team_id: 42,
  ldap_dn: 'ldap_dn'
})

Default response

Status: 200 OK
{
  "ldap_dn": "cn=Enterprise Ops,ou=teams,dc=github,dc=com",
  "id": 1,
  "node_id": "MDQ6VGVhbTE=",
  "url": "https://api.github.com/teams/1",
  "html_url": "https://api.github.com/teams/justice-league",
  "name": "Justice League",
  "slug": "justice-league",
  "description": "A great team.",
  "privacy": "closed",
  "permission": "admin",
  "members_url": "https://api.github.com/teams/1/members{/member}",
  "repositories_url": "https://api.github.com/teams/1/repos",
  "parent": null
}

预览通知

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

Sync LDAP mapping for a team

Note that this API call does not automatically initiate an LDAP sync. Rather, if a 201 is returned, the sync job is queued successfully, and is performed when the instance is ready.

post /admin/ldap/teams/{team_id}/sync

参数

Name Type In Description
accept string header

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

team_id integer path

代码示例

Shell
curl \
  -X POST \
  -H "Accept: application/vnd.github.v3+json" \
  https://{hostname}/admin/ldap/teams/42/sync
JavaScript (@octokit/core.js)
await octokit.request('POST /admin/ldap/teams/{team_id}/sync', {
  team_id: 42
})

Response

Status: 201 Created
{
  "status": "queued"
}

patch /admin/ldap/users/{username}/mapping

参数

Name Type In Description
accept string header

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

username string path
ldap_dn string body

The distinguished name (DN) of the LDAP entry to map to a team.

代码示例

Shell
curl \
  -X PATCH \
  -H "Accept: application/vnd.github.v3+json" \
  https://{hostname}/admin/ldap/users/USERNAME/mapping \
  -d '{"ldap_dn":"ldap_dn"}'
JavaScript (@octokit/core.js)
await octokit.request('PATCH /admin/ldap/users/{username}/mapping', {
  username: 'username',
  ldap_dn: 'ldap_dn'
})

Default response

Status: 200 OK
{
  "ldap_dn": "uid=asdf,ou=users,dc=github,dc=com",
  "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
}

Sync LDAP mapping for a user

Note that this API call does not automatically initiate an LDAP sync. Rather, if a 201 is returned, the sync job is queued successfully, and is performed when the instance is ready.

post /admin/ldap/users/{username}/sync

参数

Name Type In Description
accept string header

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

username string path

代码示例

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

Response

Status: 201 Created
{
  "status": "queued"
}

许可

许可 API 提供有关企业许可的信息。 它只适用于经过身份验证的站点管理员。普通用户尝试访问它时会收到 404 响应。

get /enterprise/settings/license

参数

Name Type In Description
accept string header

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

代码示例

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

Default response

Status: 200 OK
{
  "seats": 1400,
  "seats_used": 1316,
  "seats_available": 84,
  "kind": "standard",
  "days_until_expiration": 365,
  "expire_at": "2016/02/06 12:41:52 -0600"
}

管理控制台

管理控制台 API 可帮助您管理 GitHub Enterprise Server 安装设施。

在对管理控制台进行 API 调用时,必须明确设置端口号。 如果在企业实例上启用了 TLS,则端口号为 8443;否则,端口号为 8080

如果您不想提供端口号,则需要将工具配置为自动遵循重定向。

使用 curl 时,您可能还需要添加 -k 标志,因为 GitHub Enterprise Server 在您添加自己的 TLS 证书之前会使用自签名证书。

身份验证

您需要将管理控制台密码作为身份验证令牌传递给除 /setup/api/start 之外的每个管理控制台 API 端点。

使用 api_key 参数在每个请求中发送此令牌。 例如:

$ curl -L 'https://hostname:admin_port/setup/api?api_key=your-amazing-password'

还可以使用标准 HTTP 身份验证发送此令牌。 例如:

$ curl -L 'https://api_key:your-amazing-password@hostname:admin_port/setup/api'

组织

组织管理 API 允许您在 GitHub Enterprise Server 设备上创建组织。 它只适用于经过身份验证的站点管理员。普通用户尝试访问它时会收到 404 响应。

post /admin/organizations

参数

Name Type In Description
accept string header

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

login string body

Required. The organization's username.

admin string body

Required. The login of the user who will manage this organization.

profile_name string body

The organization's display name.

代码示例

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

Default response

Status: 201 Created
{
  "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"
}

patch /admin/organizations/{org}

参数

Name Type In Description
accept string header

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

org string path
login string body

Required. The organization's new name.

代码示例

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

Response

Status: 202 Accepted
{
  "message": "Job queued to rename organization. It may take a few minutes to complete.",
  "url": "https://<hostname>/api/v3/organizations/1"
}

组织预接收挂钩

组织预接收挂钩 API 允许您查看和修改组织可用的预接收挂钩的实施。

对象属性

名称类型描述
name字符串挂钩的名称。
enforcement字符串此仓库中挂钩的实施状态。
allow_downstream_configurationboolean仓库是否可以覆盖实施。
configuration_url字符串设置实施的端点 URL。

enforcement 的可能值包括 enableddisabledtestingdisabled 表示预接收挂钩不会运行。 enabled 表示它将运行并拒绝会导致非零状态的任何推送。 testing 表示脚本将运行,但不会导致任何推送被拒绝。

configuration_url 可能是此端点或此挂钩的全局配置的链接。 只有站点管理员才能访问全局配置。

预接收环境

预接收环境 API 允许您创建、列出、更新和删除预接收挂钩的环境。 它只适用于经过身份验证的站点管理员。普通用户尝试访问它时会收到 404 响应。

对象属性

预接收环境

名称类型描述
name字符串UI 中显示的环境名称。
image_url字符串将要下载并解压缩的 tarball 的 URL。
default_environmentboolean这是否是 GitHub Enterprise Server 附带的默认环境。
download对象此环境的下载状态。
hooks_count整数使用此环境的预接收挂钩数量。

预接收环境下载

名称类型描述
state字符串最近下载的状态。
downloaded_at字符串最近下载开始的时间。
message字符串在失败时生成任何错误消息。

state 的可能值包括 not_startedin_progresssuccessfailed

预接收挂钩

预接收挂钩 API 允许您创建、列出、更新和删除预接收挂钩。 它只适用于经过身份验证的站点管理员。普通用户尝试访问它时会收到 404 响应。

对象属性

预接收挂钩

名称类型描述
name字符串挂钩的名称。
script字符串挂钩运行的脚本。
script_repository对象保存脚本的 GitHub 仓库。
environment对象执行脚本的预接收环境。
enforcement字符串此挂钩的实施状态。
allow_downstream_configurationboolean是否可以在组织或仓库级别上覆盖实施。

enforcement 的可能值包括 enableddisabledtestingdisabled 表示预接收挂钩不会运行。 enabled 表示它将运行并拒绝会导致非零状态的任何推送。 testing 表示脚本将运行,但不会导致任何推送被拒绝。

仓库预接收挂钩

仓库预接收挂钩 API 允许您查看和修改仓库可用的预接收挂钩的实施。

对象属性

名称类型描述
name字符串挂钩的名称。
enforcement字符串此仓库中挂钩的实施状态。
configuration_url字符串设置实施的端点 URL。

enforcement 的可能值包括 enableddisabledtestingdisabled 表示预接收挂钩不会运行。 enabled 表示它将运行并拒绝会导致非零状态的任何推送。 testing 表示脚本将运行,但不会导致任何推送被拒绝。

configuration_url 可能是此仓库、其组织所有者或全局配置的链接。 configuration_url 端点的访问授权在所有者或站点管理员级别确定。

搜索索引

搜索索引 API 允许您对各种搜索索引任务进行排队。 它只适用于经过身份验证的站点管理员。普通用户尝试访问它时会收到 404 响应。

用户

用户管理 API 允许您在 GitHub Enterprise Server 设备上升级、降级、挂起和取消挂起用户。 它只适用于经过身份验证的站点管理员。普通用户尝试访问它时会收到 403 响应。

get /admin/keys

参数

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}/admin/keys
JavaScript (@octokit/core.js)
await octokit.request('GET /admin/keys')

Default response

Status: 200 OK
[
  {
    "key_id": "012345678912345678",
    "key": "2Sg8iYjAxxmI2LvUXpJjkYrMxURPc8r+dB7TJyvv1234",
    "user_id": 232,
    "repository_id": null
  },
  {
    "key_id": "012345678912345678",
    "key": "2Sg8iYjAxxmI2LvUXpJjkYrMxURPc8r+dB7TJyvv1234",
    "user_id": null,
    "repository_id": 2333,
    "id": "2",
    "url": "https://api.github.com/repos/octocat/Hello-World/keys/2"
  }
]

delete /admin/keys/{key_ids}

参数

Name Type In Description
accept string header

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

key_ids string path

代码示例

Shell
curl \
  -X DELETE \
  -H "Accept: application/vnd.github.v3+json" \
  https://{hostname}/admin/keys/KEY_IDS
JavaScript (@octokit/core.js)
await octokit.request('DELETE /admin/keys/{key_ids}', {
  key_ids: 'key_ids'
})

Default Response

Status: 204 No Content

List personal access tokens

Lists personal access tokens for all users, including admin users.

get /admin/tokens

参数

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}/admin/tokens
JavaScript (@octokit/core.js)
await octokit.request('GET /admin/tokens')

Default response

Status: 200 OK
[
  {
    "id": 2,
    "url": "https://enterprise.octocat.com/api/v3/authorizations/2",
    "app": {
      "name": "My personal access token",
      "url": "https://developer.github.com/enterprise/v3/enterprise-admin/users/#list-personal-access-tokens",
      "client_id": "00000000000000000000"
    },
    "token": "",
    "hashed_token": "23cffb2fab1b0a62747863eba88cb9327e561f2f7a0c8661c0d9b83146cb8d45",
    "token_last_eight": "848f9f8a",
    "note": "My personal access token",
    "note_url": null,
    "created_at": "2019-04-24T21:49:02Z",
    "updated_at": "2019-04-24T21:49:02Z",
    "scopes": [
      "admin:business",
      "admin:gpg_key",
      "admin:org",
      "admin:org_hook",
      "admin:pre_receive_hook",
      "admin:public_key",
      "admin:repo_hook",
      "delete_repo",
      "gist",
      "notifications",
      "repo",
      "user",
      "write:discussion"
    ],
    "fingerprint": null
  }
]

Delete a personal access token

Deletes a personal access token. Returns a 403 - Forbidden status when a personal access token is in use. For example, if you access this endpoint with the same personal access token that you are trying to delete, you will receive this error.

delete /admin/tokens/{token_id}

参数

Name Type In Description
accept string header

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

token_id integer path

代码示例

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

Default Response

Status: 204 No Content

Create a user

If an external authentication mechanism is used, the login name should match the login name in the external system. If you are using LDAP authentication, you should also update the LDAP mapping for the user.

The login name will be normalized to only contain alphanumeric characters or single hyphens. For example, if you send "octo_cat" as the login, a user named "octo-cat" will be created.

If the login name or email address is already associated with an account, the server will return a 422 response.

post /admin/users

参数

Name Type In Description
accept string header

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

login string body

Required. The user's username.

email string body

Required for built-in authentication. The user's email address. This parameter can be omitted when using CAS, LDAP, or SAML. For details on built-in and centrally-managed authentication, see the the GitHub Enterprise Server authentication guide.

代码示例

Shell
curl \
  -X POST \
  -H "Accept: application/vnd.github.v3+json" \
  https://{hostname}/admin/users \
  -d '{"login":"login"}'
JavaScript (@octokit/core.js)
await octokit.request('POST /admin/users', {
  login: 'login'
})

Default response

Status: 201 Created
{
  "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 /admin/users/{username}

参数

Name Type In Description
accept string header

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

username string path
login string body

Required. The user's new username.

代码示例

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

Response

Status: 202 Accepted
{
  "message": "Job queued to rename user. It may take a few minutes to complete.",
  "url": "https://api.github.com/user/1"
}

Delete a user

Deleting a user will delete all their repositories, gists, applications, and personal settings. Suspending a user is often a better option.

You can delete any user account except your own.

delete /admin/users/{username}

参数

Name Type In Description
accept string header

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

username string path

代码示例

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

Default Response

Status: 204 No Content

post /admin/users/{username}/authorizations

参数

Name Type In Description
accept string header

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

username string path
scopes array of strings body

A list of scopes.

代码示例

Shell
curl \
  -X POST \
  -H "Accept: application/vnd.github.v3+json" \
  https://{hostname}/admin/users/USERNAME/authorizations \
  -d '{"scopes":["scopes"]}'
JavaScript (@octokit/core.js)
await octokit.request('POST /admin/users/{username}/authorizations', {
  username: 'username',
  scopes: [
    'scopes'
  ]
})

Default response

Status: 201 Created
{
  "id": 1,
  "url": "https://api.github.com/authorizations/1",
  "scopes": [
    "public_repo"
  ],
  "token": "abcdefgh12345678",
  "token_last_eight": "12345678",
  "hashed_token": "25f94a2a5c7fbaf499c665bc73d67c1c87e496da8985131633ee0a95819db2e8",
  "app": {
    "url": "http://my-github-app.com",
    "name": "my github app",
    "client_id": "abcde12345fghij67890"
  },
  "note": "optional note",
  "note_url": "http://optional/note/url",
  "updated_at": "2011-09-06T20:39:23Z",
  "created_at": "2011-09-06T17:26:27Z",
  "fingerprint": "jklmnop12345678"
}

delete /admin/users/{username}/authorizations

参数

Name Type In Description
accept string header

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

username string path

代码示例

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

Default Response

Status: 204 No Content

Promote a user to be a site administrator

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

put /users/{username}/site_admin

参数

Name Type In Description
accept string header

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

username string path

代码示例

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

Default Response

Status: 204 No Content

Demote a site administrator

You can demote any user account except your own.

delete /users/{username}/site_admin

参数

Name Type In Description
accept string header

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

username string path

代码示例

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

Default Response

Status: 204 No Content

Suspend a user

If your GitHub Enterprise Server instance uses LDAP Sync with Active Directory LDAP servers, Active Directory LDAP-authenticated users cannot be suspended through this API. If you attempt to suspend an Active Directory LDAP-authenticated user through this API, it will return a 403 response.

You can suspend any user account except your own.

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

put /users/{username}/suspended

参数

Name Type In Description
accept string header

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

username string path
reason string body

The reason the user is being suspended. This message will be logged in the audit log. If you don't provide a reason, it will default to "Suspended via API by SITE_ADMINISTRATOR", where SITE_ADMINISTRATOR is the person who performed the action.

代码示例

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

Default Response

Status: 204 No Content

Unsuspend a user

If your GitHub Enterprise Server instance uses LDAP Sync with Active Directory LDAP servers, this API is disabled and will return a 403 response. Active Directory LDAP-authenticated users cannot be unsuspended using the API.

delete /users/{username}/suspended

参数

Name Type In Description
accept string header

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

username string path
reason string body

The reason the user is being unsuspended. This message will be logged in the audit log. If you don't provide a reason, it will default to "Unsuspended via API by SITE_ADMINISTRATOR", where SITE_ADMINISTRATOR is the person who performed the action.

代码示例

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

Default Response

Status: 204 No Content

问问别人

找不到要找的内容?

联系我们