此版本的 GitHub Enterprise Server 已于以下日期停止服务 2024-09-25. 即使针对重大安全问题,也不会发布补丁。 为了获得更好的性能、更高的安全性和新功能,请升级到最新版本的 GitHub Enterprise。 如需升级帮助,请联系 GitHub Enterprise 支持。
适用于全局 Webhook 的 REST API 终结点
使用 REST API 管理企业的全局 Webhook。
关于全局 web 挂钩
这些终结点仅供经过身份验证的站点管理员使用。普通用户将收到 404
响应。 若要了解如何配置全局 Webhook,请参阅关于全局 Webhook。
全局 webhook 会自动安装在企业中。 您可以使用全局 web 挂钩来自动监视、响应或实施针对企业上的用户、组织、团队和仓库的规则。
全局 Webhook 可以订阅组织、用户、存储库、团队、成员、成员身份、分支和 ping 事件类型。
Note
这些终结点仅支持使用 personal access token (classic) 进行身份验证。 有关详细信息,请参阅“管理个人访问令牌”。
List global webhooks
“List global webhooks”的细粒度访问令牌
此终结点不适用于 GitHub 应用程序用户访问令牌、GitHub 应用程序安装访问令牌或细粒度个人访问令牌。
“List global webhooks”的参数
名称, 类型, 说明 |
---|
accept string Setting to |
名称, 类型, 说明 |
---|
per_page integer The number of results per page (max 100). For more information, see "Using pagination in the REST API." 默认: |
page integer The page number of the results to fetch. For more information, see "Using pagination in the REST API." 默认: |
“List global webhooks”的 HTTP 响应状态代码
状态代码 | 说明 |
---|---|
200 | OK |
“List global webhooks”的示例代码
请求示例
curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
-H "X-GitHub-Api-Version: 2022-11-28" \
http(s)://HOSTNAME/api/v3/admin/hooks
Response
Status: 200
[
{
"type": "Global",
"id": 1,
"name": "web",
"active": true,
"events": [
"organization",
"user"
],
"config": {
"url": "https://example.com",
"content_type": "json",
"insecure_ssl": "0",
"secret": "********"
},
"updated_at": "2017-12-07T00:14:59Z",
"created_at": "2017-12-07T00:14:59Z",
"url": "https://HOSTNAME/admin/hooks/1",
"ping_url": "https://HOSTNAME/admin/hooks/1/pings"
}
]
Create a global webhook
“Create a global webhook”的细粒度访问令牌
此终结点不适用于 GitHub 应用程序用户访问令牌、GitHub 应用程序安装访问令牌或细粒度个人访问令牌。
“Create a global webhook”的参数
名称, 类型, 说明 |
---|
accept string Setting to |
名称, 类型, 说明 | |||||
---|---|---|---|---|---|
name string 必须Must be passed as "web". | |||||
config object 必须Key/value pairs to provide settings for this webhook. | |||||
Properties of |
名称, 类型, 说明 |
---|
url string 必须The URL to which the payloads will be delivered. |
content_type string The media type used to serialize the payloads. Supported values include |
secret string If provided, the |
insecure_ssl string Determines whether the SSL certificate of the host for |
events
array of strings The events that trigger this webhook. A global webhook can be triggered by user
and organization
events. Default: user
and organization
.
active
boolean Determines if notifications are sent when the webhook is triggered. Set to true
to send notifications.
默认: true
“Create a global webhook”的 HTTP 响应状态代码
状态代码 | 说明 |
---|---|
201 | Created |
“Create a global webhook”的示例代码
请求示例
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
-H "X-GitHub-Api-Version: 2022-11-28" \
http(s)://HOSTNAME/api/v3/admin/hooks \
-d '{"name":"web","events":["organization","user"],"config":{"url":"https://example.com/webhook","content_type":"json","secret":"secret"}}'
Response
Status: 201
{
"type": "Global",
"id": 1,
"name": "web",
"active": true,
"events": [
"organization",
"user"
],
"config": {
"url": "https://example.com",
"content_type": "json",
"insecure_ssl": "0",
"secret": "********"
},
"updated_at": "2017-12-07T00:14:59Z",
"created_at": "2017-12-07T00:14:59Z",
"url": "https://HOSTNAME/admin/hooks/1",
"ping_url": "https://HOSTNAME/admin/hooks/1/pings"
}
Get a global webhook
“Get a global webhook”的细粒度访问令牌
此终结点不适用于 GitHub 应用程序用户访问令牌、GitHub 应用程序安装访问令牌或细粒度个人访问令牌。
“Get a global webhook”的参数
名称, 类型, 说明 |
---|
accept string Setting to |
名称, 类型, 说明 |
---|
hook_id integer 必须The unique identifier of the hook. You can find this value in the |
“Get a global webhook”的 HTTP 响应状态代码
状态代码 | 说明 |
---|---|
200 | OK |
“Get a global webhook”的示例代码
请求示例
curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
-H "X-GitHub-Api-Version: 2022-11-28" \
http(s)://HOSTNAME/api/v3/admin/hooks/HOOK_ID
Response
Status: 200
{
"type": "Global",
"id": 1,
"name": "web",
"active": true,
"events": [
"organization",
"user"
],
"config": {
"url": "https://example.com",
"content_type": "json",
"insecure_ssl": "0",
"secret": "********"
},
"updated_at": "2017-12-07T00:14:59Z",
"created_at": "2017-12-07T00:14:59Z",
"url": "https://HOSTNAME/admin/hooks/1",
"ping_url": "https://HOSTNAME/admin/hooks/1/pings"
}
Update a global webhook
Parameters that are not provided will be overwritten with the default value or removed if no default exists.
“Update a global webhook”的细粒度访问令牌
此终结点不适用于 GitHub 应用程序用户访问令牌、GitHub 应用程序安装访问令牌或细粒度个人访问令牌。
“Update a global webhook”的参数
名称, 类型, 说明 |
---|
accept string Setting to |
名称, 类型, 说明 |
---|
hook_id integer 必须The unique identifier of the hook. You can find this value in the |
名称, 类型, 说明 | |||||
---|---|---|---|---|---|
config object Key/value pairs to provide settings for this webhook. | |||||
Properties of |
名称, 类型, 说明 |
---|
url string 必须The URL to which the payloads will be delivered. |
content_type string The media type used to serialize the payloads. Supported values include |
secret string If provided, the |
insecure_ssl string Determines whether the SSL certificate of the host for |
events
array of strings The events that trigger this webhook. A global webhook can be triggered by user
and organization
events. Default: user
and organization
.
active
boolean Determines if notifications are sent when the webhook is triggered. Set to true
to send notifications.
默认: true
“Update a global webhook”的 HTTP 响应状态代码
状态代码 | 说明 |
---|---|
200 | OK |
“Update a global webhook”的示例代码
请求示例
curl -L \
-X PATCH \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
-H "X-GitHub-Api-Version: 2022-11-28" \
http(s)://HOSTNAME/api/v3/admin/hooks/HOOK_ID \
-d '{"events":["organization"],"config":{"url":"https://example.com/webhook"}}'
Response
Status: 200
{
"type": "Global",
"id": 1,
"name": "web",
"active": true,
"events": [
"organization"
],
"config": {
"url": "https://example.com",
"content_type": "form",
"insecure_ssl": "0"
},
"updated_at": "2017-12-07T00:14:59Z",
"created_at": "2017-12-07T00:14:59Z",
"url": "https://HOSTNAME/admin/hooks/1",
"ping_url": "https://HOSTNAME/admin/hooks/1/pings"
}
Delete a global webhook
“Delete a global webhook”的细粒度访问令牌
此终结点不适用于 GitHub 应用程序用户访问令牌、GitHub 应用程序安装访问令牌或细粒度个人访问令牌。
“Delete a global webhook”的参数
名称, 类型, 说明 |
---|
accept string Setting to |
名称, 类型, 说明 |
---|
hook_id integer 必须The unique identifier of the hook. You can find this value in the |
“Delete a global webhook”的 HTTP 响应状态代码
状态代码 | 说明 |
---|---|
204 | No Content |
“Delete a global webhook”的示例代码
请求示例
curl -L \
-X DELETE \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
-H "X-GitHub-Api-Version: 2022-11-28" \
http(s)://HOSTNAME/api/v3/admin/hooks/HOOK_ID
Response
Status: 204
Ping a global webhook
This will trigger a ping event to be sent to the webhook.
“Ping a global webhook”的细粒度访问令牌
此终结点不适用于 GitHub 应用程序用户访问令牌、GitHub 应用程序安装访问令牌或细粒度个人访问令牌。
“Ping a global webhook”的参数
名称, 类型, 说明 |
---|
accept string Setting to |
名称, 类型, 说明 |
---|
hook_id integer 必须The unique identifier of the hook. You can find this value in the |
“Ping a global webhook”的 HTTP 响应状态代码
状态代码 | 说明 |
---|---|
204 | No Content |
“Ping a global webhook”的示例代码
请求示例
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
-H "X-GitHub-Api-Version: 2022-11-28" \
http(s)://HOSTNAME/api/v3/admin/hooks/HOOK_ID/pings
Response
Status: 204