注册 webhook
为公开 URL 订阅受支持的事件。每个端点都会获得独立的 HMAC-SHA256 密钥,该密钥仅在创建时显示一次。如果丢失,请移除端点后重新添加。
POST
https://notpanel.com/api/v3action=webhook.add需要 API key受速率限制(共享账户 + IP + action)请求体:
application/x-www-form-urlencoded每个 API key 最多 5 个 webhook。 请使用可从公网访问的 HTTPS URL。不安全、私有、回环或其他非公开目标会被拒绝。
参数
| 名称 | 类型 | 描述 |
|---|---|---|
| key必需 | string | 你的 API key。 |
| action必需 | string | 必须是字面字符串 “webhook.add”。 |
| url必需 | string (URL) | 将接收 POST 请求的公开 HTTPS 端点。必须能从公网访问。 |
| events | string (CSV) | 以逗号分隔的下方六个受支持事件的子集。省略时订阅全部六个。 |
请求示例
将 YOUR_API_KEY 替换为在你仪表盘 API 页面下生成的 key。
curl -X POST https://notpanel.com/api/v3 \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "key=YOUR_API_KEY&action=webhook.add&url=https://your-server.example.com/notpanel-webhook&events=order.completed,order.refunded"const res = await fetch("https://notpanel.com/api/v3", {
method: "POST",
headers: { "Content-Type": "application/x-www-form-urlencoded" },
body: new URLSearchParams({
key: "YOUR_API_KEY",
action: "webhook.add",
url: "https://your-server.example.com/notpanel-webhook",
events: "order.completed,order.refunded",
}),
});
const data = await res.json();
console.log(data);import requests
res = requests.post(
"https://notpanel.com/api/v3",
data={
"key": "YOUR_API_KEY",
"action": "webhook.add",
"url": "https://your-server.example.com/notpanel-webhook",
"events": "order.completed,order.refunded",
},
)
print(res.json())<?php
$body = http_build_query([
'key' => 'YOUR_API_KEY',
'action' => 'webhook.add',
'url' => 'https://your-server.example.com/notpanel-webhook',
'events' => 'order.completed,order.refunded',
]);
$response = file_get_contents('https://notpanel.com/api/v3', false, stream_context_create([
'http' => [
'method' => 'POST',
'header' => "Content-Type: application/x-www-form-urlencoded\r\n",
'content' => $body,
'ignore_errors' => true,
],
]));
print_r(json_decode($response, true));
响应示例
{
"webhook_id": "3f2504e0-4f89-41d3-9a0c-0305e82c3301",
"url": "https://your-server.example.com/notpanel-webhook",
"secret": "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
"events": [
"order.completed",
"order.refunded"
]
}常见错误
| 状态 | 响应体 | 原因 |
|---|---|---|
| 400 | {"error":"Maximum 5 webhook endpoints per API key"} | 现有端点已用尽上限。请先使用 action=webhook.remove 删除一个未使用的端点。 |
| 400 | {"error":"Webhook URL must be a publicly reachable HTTPS URL"} | URL 不是有效的 HTTPS 地址、无法解析,或解析到了私有/回环 IP。 |
| 400 | {"error":"Webhook event is invalid","error_code":"INVALID_WEBHOOK_EVENT"} | 事件名称不在允许列表中。请重新检查拼写——名称采用 “order.<status>” 形式。 |