Skip to main content

GitHub AE 目前处于受限版。

我们最近移动了一些 REST API 文档。 如果找不到要查找的内容,可以尝试 操作 REST API 页面。

用户

使用 REST API 暂停以及取消暂停企业上的用户。

关于用户管理

这些终结点仅适用于经过身份验证的网站管理员。 普通用户将收到 403 响应。

List public keys

“List public keys”的参数

标头
名称, 类型, 说明
accept string

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

查询参数
名称, 类型, 说明
per_page integer

The number of results per page (max 100).

默认: 30

page integer

Page number of the results to fetch.

默认: 1

direction string

The direction to sort the results by.

默认: desc

可以是以下选项之一: asc, desc

sort string

默认: created

可以是以下选项之一: created, updated, accessed

since string

Only show public keys accessed after the given time.

“List public keys”的 HTTP 响应状态代码

状态代码说明
200

OK

“List public keys”的示例代码

get/admin/keys
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ https://HOSTNAME/api/v3/admin/keys

Response

Status: 200
[ { "key": "2Sg8iYjAxxmI2LvUXpJjkYrMxURPc8r+dB7TJyvv1234", "id": 2, "url": "https://api.github.com/user/keys/2", "title": "ssh-rsa AAAAB3NzaC1yc2EAAA", "created_at": "2020-06-11T21:31:57Z", "verified": false, "read_only": false, "last_used": "2020-06-11T22:31:57Z", "user_id": 1, "repository_id": 2 }, { "key": "9Og8iYjAyymI9LvABpJerYrMxURPc8r+dB7TJyvv1234", "id": 3, "url": "https://api.github.com/user/keys/2", "title": "ssh-rsa AAAAB3NzaC1yc2EAAA", "created_at": "2020-06-11T21:31:57Z", "verified": false, "read_only": false, "last_used": "2020-06-11T22:31:57Z", "user_id": 1, "repository_id": 2 } ]

Delete a public key

“Delete a public key”的参数

标头
名称, 类型, 说明
accept string

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

路径参数
名称, 类型, 说明
key_ids string 必须

The unique identifier of the key.

“Delete a public key”的 HTTP 响应状态代码

状态代码说明
204

No Content

“Delete a public key”的示例代码

delete/admin/keys/{key_ids}
curl -L \ -X DELETE \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ https://HOSTNAME/api/v3/admin/keys/KEY_IDS

Response

Status: 204

List personal access tokens

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

“List personal access tokens”的参数

标头
名称, 类型, 说明
accept string

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

查询参数
名称, 类型, 说明
per_page integer

The number of results per page (max 100).

默认: 30

page integer

Page number of the results to fetch.

默认: 1

“List personal access tokens”的 HTTP 响应状态代码

状态代码说明
200

OK

“List personal access tokens”的示例代码

get/admin/tokens
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ https://HOSTNAME/api/v3/admin/tokens

Response

Status: 200
[ { "id": 1, "url": "https://api.github.com/authorizations/1", "scopes": [ "public_repo" ], "token": "ghu_16C7e42F292c6912E7710c838347Ae178B4a", "token_last_eight": "Ae178B4a", "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", "expires_at": "2011-09-08T17:26:27Z", "fingerprint": "jklmnop12345678" } ]

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 a personal access token”的参数

标头
名称, 类型, 说明
accept string

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

路径参数
名称, 类型, 说明
token_id integer 必须

The unique identifier of the token.

“Delete a personal access token”的 HTTP 响应状态代码

状态代码说明
204

No Content

“Delete a personal access token”的示例代码

delete/admin/tokens/{token_id}
curl -L \ -X DELETE \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ https://HOSTNAME/api/v3/admin/tokens/TOKEN_ID

Response

Status: 204

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 a user”的参数

标头
名称, 类型, 说明
accept string

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

路径参数
名称, 类型, 说明
username string 必须

The handle for the GitHub user account.

“Delete a user”的 HTTP 响应状态代码

状态代码说明
204

No Content

“Delete a user”的示例代码

delete/admin/users/{username}
curl -L \ -X DELETE \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ https://HOSTNAME/api/v3/admin/users/USERNAME

Response

Status: 204

Create an impersonation OAuth token

“Create an impersonation OAuth token”的参数

标头
名称, 类型, 说明
accept string

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

路径参数
名称, 类型, 说明
username string 必须

The handle for the GitHub user account.

正文参数
名称, 类型, 说明
scopes array of strings 必须

A list of scopes.

“Create an impersonation OAuth token”的 HTTP 响应状态代码

状态代码说明
200

Response when getting an existing impersonation OAuth token

201

Response when creating a new impersonation OAuth token

“Create an impersonation OAuth token”的示例代码

post/admin/users/{username}/authorizations
curl -L \ -X POST \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ https://HOSTNAME/api/v3/admin/users/USERNAME/authorizations \ -d '{"scopes":["public_repo"]}'

Response when getting an existing impersonation OAuth token

Status: 200
{ "id": 1, "url": "https://api.github.com/authorizations/1", "scopes": [ "public_repo" ], "token": "ghu_16C7e42F292c6912E7710c838347Ae178B4a", "token_last_eight": "Ae178B4a", "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", "expires_at": "2011-10-06T17:26:27Z", "fingerprint": "" }

Delete an impersonation OAuth token

“Delete an impersonation OAuth token”的参数

标头
名称, 类型, 说明
accept string

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

路径参数
名称, 类型, 说明
username string 必须

The handle for the GitHub user account.

“Delete an impersonation OAuth token”的 HTTP 响应状态代码

状态代码说明
204

No Content

“Delete an impersonation OAuth token”的示例代码

delete/admin/users/{username}/authorizations
curl -L \ -X DELETE \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ https://HOSTNAME/api/v3/admin/users/USERNAME/authorizations

Response

Status: 204

Suspend a user

If your GitHub 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."

“Suspend a user”的参数

标头
名称, 类型, 说明
accept string

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

路径参数
名称, 类型, 说明
username string 必须

The handle for the GitHub user account.

正文参数
名称, 类型, 说明
reason string

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.

“Suspend a user”的 HTTP 响应状态代码

状态代码说明
204

No Content

“Suspend a user”的示例代码

put/users/{username}/suspended
curl -L \ -X PUT \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ https://HOSTNAME/api/v3/users/USERNAME/suspended \ -d '{"reason":"Suspended during leave of absence."}'

Response

Status: 204

Unsuspend a user

If your GitHub 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.

“Unsuspend a user”的参数

标头
名称, 类型, 说明
accept string

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

路径参数
名称, 类型, 说明
username string 必须

The handle for the GitHub user account.

正文参数
名称, 类型, 说明
reason string

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.

“Unsuspend a user”的 HTTP 响应状态代码

状态代码说明
204

No Content

“Unsuspend a user”的示例代码

delete/users/{username}/suspended
curl -L \ -X DELETE \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ https://HOSTNAME/api/v3/users/USERNAME/suspended \ -d '{"reason":"Unsuspended after leave of absence."}'

Response

Status: 204