# 更新 Webhook 端点

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

PATCH `/api/settings/webhooks/{id}`

- **认证** 控制台会话 Cookie。
- **成功状态** `200`

## 请求参数

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

## 请求示例

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

**cURL**

```bash
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**

```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**

```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 · 示例响应**

```json
{
  "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"
  }
}
```

**错误示例**

```json
{
  "error": "请先登录。"
}
```

| 字段 | 类型 | 说明 |
| --- | --- | --- |
| `endpoint.id` | string | 端点 ID。 |
| `endpoint.url` | URI | 端点的接收地址。 |
| `endpoint.events` | string\[\] | 订阅的事件类型。 |
| `endpoint.enabled` | boolean | 是否开启自动事件投递。 |
| `endpoint.createdAt` | ISO 8601 date-time | 端点创建时间。 |
| `endpoint.updatedAt` | ISO 8601 date-time | 端点上次更新时间。 |
| `delivery.id` | string | 投递记录 ID。 |
| `delivery.endpointId` | string | 接收端点 ID。 |
| `delivery.url` | URI | 投递时使用的端点地址。 |
| `delivery.eventId` | string | 事件 ID。同一事件重投时保持一致。 |
| `delivery.type` | string | 事件类型。测试投递使用 webhook.test。 |
| `delivery.status` | delivered \| failed | 本次投递结果。 |
| `delivery.statusCode` | integer \| null | 端点返回的 HTTP 状态。连接失败时为 null。 |
| `delivery.error` | string \| null | 失败信息。投递成功时为 null。 |
| `delivery.createdAt` | ISO 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。

## 同组接口

-   [GET 列出 Webhook 与投递记录](<https://social2api.com/docs/api/webhooks-list/>)
-   [POST 创建 Webhook 端点](<https://social2api.com/docs/api/webhooks-create/>)
-   [DELETE 删除 Webhook 端点](<https://social2api.com/docs/api/webhooks-delete/>)
-   [POST 发送 Webhook 测试事件](<https://social2api.com/docs/api/webhooks-test/>)
-   [POST 轮换 Webhook 签名密钥](<https://social2api.com/docs/api/webhooks-rotate/>)

规范页面：<https://social2api.com/docs/api/webhooks-update/>
