更新 Webhook 端点

修改现有端点的接收地址、事件订阅或启用状态。

PATCH/api/settings/webhooks/{id}
认证
控制台会话 Cookie。
成功状态
200

请求参数

参数类型位置必填说明
idstringpath是当前账号拥有的 Webhook 端点 ID。
OriginURIheader是当前站点的完整来源。
urlURIbody否公开 HTTPS 地址,最多 2,048 字符,须使用默认端口且不含凭据或片段。
eventsstring[]body否从列表接口返回的 eventTypes 中选择至少一项。重复项会自动合并。
enabledbooleanbody否是否发送订阅的真实事件。

请求示例

JavaScript 示例可在本站已登录的浏览器中运行。cURL 和 Python 示例读取你本机的 cookies.txt Cookie 文件。请将会话 Cookie 视为私密凭据。

cURL
curl -i -X PATCH 'https://social2api.com/api/settings/webhooks/wh_4a5076aa-f9ab-46e6-b383-7b1374392dc4' \
  --cookie ./cookies.txt \
  -H 'Content-Type: application/json' \
  -H 'Origin: https://social2api.com' \
  --data-binary '{
  "enabled": false
}'
Python
from urllib.error import HTTPError
from urllib.request import Request, HTTPCookieProcessor, build_opener
from http.cookiejar import MozillaCookieJar

request = Request(
    "https://social2api.com/api/settings/webhooks/wh_4a5076aa-f9ab-46e6-b383-7b1374392dc4",
    method="PATCH",
    headers={
        "Content-Type": "application/json",
        "Origin": "https://social2api.com",
    },
    data="{\"enabled\":false}".encode("utf-8"),
)
cookies = MozillaCookieJar("./cookies.txt")
cookies.load(ignore_discard=True)
send = build_opener(HTTPCookieProcessor(cookies)).open
try:
    with send(request) as response:
        print(response.status, response.read().decode("utf-8"))
except HTTPError as error:
    print(error.code, error.read().decode("utf-8"))
JavaScript
const response = await fetch("/api/settings/webhooks/wh_4a5076aa-f9ab-46e6-b383-7b1374392dc4", {
  method: "PATCH",
  credentials: "same-origin",
  headers: {
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "enabled": false
  }),
});
console.log(response.status, await response.text());

响应

200 · 示例响应
{
  "endpoint": {
    "id": "wh_4a5076aa-f9ab-46e6-b383-7b1374392dc4",
    "url": "https://example.com/webhook",
    "events": [
      "tool_run.finished"
    ],
    "enabled": false,
    "createdAt": "2026-01-15T12:00:00.000Z",
    "updatedAt": "2026-01-15T12:00:00.000Z"
  }
}
错误示例
{
  "error": "请先登录。"
}
字段类型说明
endpoint.idstring端点 ID。
endpoint.urlURI端点的接收地址。
endpoint.eventsstring[]订阅的事件类型。
endpoint.enabledboolean是否开启自动事件投递。
endpoint.createdAtISO 8601 date-time端点创建时间。
endpoint.updatedAtISO 8601 date-time端点上次更新时间。
delivery.idstring投递记录 ID。
delivery.endpointIdstring接收端点 ID。
delivery.urlURI投递时使用的端点地址。
delivery.eventIdstring事件 ID。同一事件重投时保持一致。
delivery.typestring事件类型。测试投递使用 webhook.test。
delivery.statusdelivered | failed本次投递结果。
delivery.statusCodeinteger | null端点返回的 HTTP 状态。连接失败时为 null。
delivery.errorstring | null失败信息。投递成功时为 null。
delivery.createdAtISO 8601 date-time投递时间。

错误状态

HTTP原因与处理
403浏览器来源校验未通过。
401控制台会话缺失、过期或无效。
405请求方法不受支持。
503此部署未配置该控制台服务。
400请求格式或字段无效。
413请求体超出 8,192 字节。
415需要 application/json 请求体。
404该账号没有这个端点。
409达到 10 个端点上限、端点 URL 已存在,或该端点同时被修改。
422验证投递失败。确认公开 HTTPS 接收端及时返回 2xx。

使用细节

  • 写请求须包含与站点完全相同的 Origin。
  • JSON 请求体最多 8,192 字节。
  • 至少发送一个属性。只有地址发生变更时,会先向新地址发送验证事件,成功响应同时返回 delivery。