{"meta":{"title":"适用于全球 Webhook 的 REST API 终结点","intro":"使用 REST API 管理企业的全局 Webhook。","product":"REST API","breadcrumbs":[{"href":"/zh/enterprise-server@3.19/rest","title":"REST API"},{"href":"/zh/enterprise-server@3.19/rest/enterprise-admin","title":"企业管理"},{"href":"/zh/enterprise-server@3.19/rest/enterprise-admin/global-webhooks","title":"全局 Webhook"}],"documentType":"article"},"body":"# 适用于全球 Webhook 的 REST API 终结点\n\n使用 REST API 管理企业的全局 Webhook。\n\n## 关于全局 web 挂钩\n\n这些终结点仅供[经过身份验证的](/zh/enterprise-server@3.19/rest/authentication/authenticating-to-the-rest-api)站点管理员使用。普通用户将收到 `404` 响应。 若要了解如何配置全局 Webhook，请参阅[关于全局 Webhook](/zh/enterprise-server@3.19/admin/monitoring-activity-in-your-enterprise/exploring-user-activity-in-your-enterprise/managing-global-webhooks)。\n\n全局 webhook 会自动安装在企业中。 您可以使用全局 web 挂钩来自动监视、响应或实施针对企业上的用户、组织、团队和仓库的规则。\n\n全局 Webhook 可以订阅[组织](/zh/enterprise-server@3.19/webhooks/webhook-events-and-payloads#organization)、[用户](/zh/enterprise-server@3.19/webhooks/webhook-events-and-payloads#user)、[存储库](/zh/enterprise-server@3.19/webhooks/webhook-events-and-payloads#repository)、[团队](/zh/enterprise-server@3.19/webhooks/webhook-events-and-payloads#team)、[成员](/zh/enterprise-server@3.19/webhooks/webhook-events-and-payloads#member)、[成员身份](/zh/enterprise-server@3.19/webhooks/webhook-events-and-payloads#membership)、[分支](/zh/enterprise-server@3.19/webhooks/webhook-events-and-payloads#fork)和 [ping](/zh/enterprise-server@3.19/webhooks/about-webhooks#ping-event) 事件类型。\n\n> \\[!NOTE]\n> 这些终结点仅支持使用 personal access token (classic) 进行身份验证。 有关详细信息，请参阅“[管理个人访问令牌](/zh/enterprise-server@3.19/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#creating-a-personal-access-token-classic)”。\n\n> \\[!NOTE]\n> Most endpoints use `Authorization: Bearer <YOUR-TOKEN>` and `Accept: application/vnd.github+json` headers, plus `X-GitHub-Api-Version: 2022-11-28`. Curl examples below omit these standard headers for brevity.\n\n## List global webhooks\n\n```\nGET /admin/hooks\n```\n\n### Parameters\n\n#### Headers\n\n* **`accept`** (string)\n  Setting to `application/vnd.github+json` is recommended.\n\n#### Path and query parameters\n\n* **`per_page`** (integer)\n  The number of results per page (max 100). For more information, see \"Using pagination in the REST API.\"\n  Default: `30`\n\n* **`page`** (integer)\n  The page number of the results to fetch. For more information, see \"Using pagination in the REST API.\"\n  Default: `1`\n\n### HTTP response status codes\n\n* **200** - OK\n\n### Code examples\n\n#### Example\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X GET \\\n  http(s)://HOSTNAME/api/v3/admin/hooks\n```\n\n**Response schema (Status: 200):**\n\nArray of objects:\n\n* `type`: string\n* `id`: integer\n* `name`: string\n* `active`: boolean\n* `events`: array of string\n* `config`: object:\n  * `url`: string\n  * `content_type`: string\n  * `insecure_ssl`: string\n  * `secret`: string\n* `updated_at`: string\n* `created_at`: string\n* `url`: string\n* `ping_url`: string\n\n## Create a global webhook\n\n```\nPOST /admin/hooks\n```\n\n### Parameters\n\n#### Headers\n\n* **`accept`** (string)\n  Setting to `application/vnd.github+json` is recommended.\n\n#### Body parameters\n\n* **`name`** (string) (required)\n  Must be passed as \"web\".\n\n* **`config`** (object) (required)\n  Key/value pairs to provide settings for this webhook.\n  * **`url`** (string) (required)\n    The URL to which the payloads will be delivered.\n  * **`content_type`** (string)\n    The media type used to serialize the payloads. Supported values include json and form. The default is form.\n  * **`secret`** (string)\n    If provided, the secret will be used as the key to generate the HMAC hex digest value in the X-Hub-Signature header.\n  * **`insecure_ssl`** (string)\n    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.\n\n* **`events`** (array of strings)\n  The events that trigger this webhook. A global webhook can be triggered by user and organization events. Default: user and organization.\n\n* **`active`** (boolean)\n  Determines if notifications are sent when the webhook is triggered. Set to true to send notifications.\n  Default: `true`\n\n### HTTP response status codes\n\n* **201** - Created\n\n### Code examples\n\n#### Example\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X POST \\\n  http(s)://HOSTNAME/api/v3/admin/hooks \\\n  -d '{\n  \"name\": \"web\",\n  \"events\": [\n    \"organization\",\n    \"user\"\n  ],\n  \"config\": {\n    \"url\": \"https://example.com/webhook\",\n    \"content_type\": \"json\",\n    \"secret\": \"secret\"\n  }\n}'\n```\n\n**Response schema (Status: 201):**\n\n* `type`: string\n* `id`: integer\n* `name`: string\n* `active`: boolean\n* `events`: array of string\n* `config`: object:\n  * `url`: string\n  * `content_type`: string\n  * `insecure_ssl`: string\n  * `secret`: string\n* `updated_at`: string\n* `created_at`: string\n* `url`: string\n* `ping_url`: string\n\n## Get a global webhook\n\n```\nGET /admin/hooks/{hook_id}\n```\n\n### Parameters\n\n#### Headers\n\n* **`accept`** (string)\n  Setting to `application/vnd.github+json` is recommended.\n\n#### Path and query parameters\n\n* **`hook_id`** (integer) (required)\n  The unique identifier of the hook. You can find this value in the X-GitHub-Hook-ID header of a webhook delivery.\n\n### HTTP response status codes\n\n* **200** - OK\n\n### Code examples\n\n#### Example\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X GET \\\n  http(s)://HOSTNAME/api/v3/admin/hooks/HOOK_ID\n```\n\n**Response schema (Status: 200):**\n\nSame response schema as [Create a global webhook](#create-a-global-webhook).\n\n## Update a global webhook\n\n```\nPATCH /admin/hooks/{hook_id}\n```\n\nParameters that are not provided will be overwritten with the default value or removed if no default exists.\n\n### Parameters\n\n#### Headers\n\n* **`accept`** (string)\n  Setting to `application/vnd.github+json` is recommended.\n\n#### Path and query parameters\n\n* **`hook_id`** (integer) (required)\n  The unique identifier of the hook. You can find this value in the X-GitHub-Hook-ID header of a webhook delivery.\n\n#### Body parameters\n\n* **`config`** (object)\n  Key/value pairs to provide settings for this webhook.\n  * **`url`** (string) (required)\n    The URL to which the payloads will be delivered.\n  * **`content_type`** (string)\n    The media type used to serialize the payloads. Supported values include json and form. The default is form.\n  * **`secret`** (string)\n    If provided, the secret will be used as the key to generate the HMAC hex digest value in the X-Hub-Signature header.\n  * **`insecure_ssl`** (string)\n    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.\n\n* **`events`** (array of strings)\n  The events that trigger this webhook. A global webhook can be triggered by user and organization events. Default: user and organization.\n\n* **`active`** (boolean)\n  Determines if notifications are sent when the webhook is triggered. Set to true to send notifications.\n  Default: `true`\n\n### HTTP response status codes\n\n* **200** - OK\n\n### Code examples\n\n#### Example\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X PATCH \\\n  http(s)://HOSTNAME/api/v3/admin/hooks/HOOK_ID \\\n  -d '{\n  \"events\": [\n    \"organization\"\n  ],\n  \"config\": {\n    \"url\": \"https://example.com/webhook\"\n  }\n}'\n```\n\n**Response schema (Status: 200):**\n\n* `type`: string\n* `id`: integer\n* `name`: string\n* `active`: boolean\n* `events`: array of string\n* `config`: object:\n  * `url`: string\n  * `content_type`: string\n  * `insecure_ssl`: string\n* `updated_at`: string\n* `created_at`: string\n* `url`: string\n* `ping_url`: string\n\n## Delete a global webhook\n\n```\nDELETE /admin/hooks/{hook_id}\n```\n\n### Parameters\n\n#### Headers\n\n* **`accept`** (string)\n  Setting to `application/vnd.github+json` is recommended.\n\n#### Path and query parameters\n\n* **`hook_id`** (integer) (required)\n  The unique identifier of the hook. You can find this value in the X-GitHub-Hook-ID header of a webhook delivery.\n\n### HTTP response status codes\n\n* **204** - No Content\n\n### Code examples\n\n#### Example\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X DELETE \\\n  http(s)://HOSTNAME/api/v3/admin/hooks/HOOK_ID\n```\n\n**Response schema (Status: 204):**\n\n## Ping a global webhook\n\n```\nPOST /admin/hooks/{hook_id}/pings\n```\n\nThis will trigger a ping event to be sent to the webhook.\n\n### Parameters\n\n#### Headers\n\n* **`accept`** (string)\n  Setting to `application/vnd.github+json` is recommended.\n\n#### Path and query parameters\n\n* **`hook_id`** (integer) (required)\n  The unique identifier of the hook. You can find this value in the X-GitHub-Hook-ID header of a webhook delivery.\n\n### HTTP response status codes\n\n* **204** - No Content\n\n### Code examples\n\n#### Example\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X POST \\\n  http(s)://HOSTNAME/api/v3/admin/hooks/HOOK_ID/pings\n```\n\n**Response schema (Status: 204):**"}