# 发送 Webhook 测试事件

立即投递 webhook.test，并返回单次投递结果。

POST `/api/settings/webhooks/{id}/test`

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

## 请求参数

| 参数 | 类型 | 位置 | 必填 | 说明 |
| --- | --- | --- | --- | --- |
| `id` | string | `path` | 是 | 当前账号拥有的 Webhook 端点 ID。 |
| `Origin` | URI | `header` | 是 | 当前站点的完整来源。 |

## 请求示例

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

**cURL**

```bash
curl -i -X POST 'https://social2api.com/api/settings/webhooks/wh_4a5076aa-f9ab-46e6-b383-7b1374392dc4/test' \
  --cookie ./cookies.txt \
  -H 'Origin: https://social2api.com'
```

**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/test",
    method="POST",
    headers={
        "Origin": "https://social2api.com",
    },
)
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/test", {
  method: "POST",
  credentials: "same-origin",
});
console.log(response.status, await response.text());
```

## 响应

**200 · 示例响应**

```json
{
  "delivery": {
    "id": "whd_8fd20315-91cc-4654-9d70-ae084e1cfa80",
    "endpointId": "wh_4a5076aa-f9ab-46e6-b383-7b1374392dc4",
    "url": "https://example.com/webhook",
    "eventId": "evt_b30f6dbc-79c1-4d78-bad1-05ec854a50b2",
    "type": "webhook.test",
    "status": "delivered",
    "statusCode": 204,
    "error": null,
    "createdAt": "2026-01-15T12:00:00.000Z"
  }
}
```

**错误示例**

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

| 字段 | 类型 | 说明 |
| --- | --- | --- |
| `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` | 此部署未配置该控制台服务。 |
| `404` | 该账号没有这个端点。 |

## 使用细节

-   写请求须包含与站点完全相同的 Origin。
-   测试投递失败仍可能返回 200。检查 delivery.status、delivery.statusCode 和 delivery.error。暂停的端点也可以测试。
-   接收端会收到 JSON 事件和 Shishu-Signature 请求头。签名是 HMAC-SHA256，输入为 Unix 秒级时间戳、点和原始请求体。使用端点密钥校验，事件 ID 可用于去重。

## 同组接口

-   [GET 列出 Webhook 与投递记录](<https://social2api.com/docs/api/webhooks-list/>)
-   [POST 创建 Webhook 端点](<https://social2api.com/docs/api/webhooks-create/>)
-   [PATCH 更新 Webhook 端点](<https://social2api.com/docs/api/webhooks-update/>)
-   [DELETE 删除 Webhook 端点](<https://social2api.com/docs/api/webhooks-delete/>)
-   [POST 轮换 Webhook 签名密钥](<https://social2api.com/docs/api/webhooks-rotate/>)

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