Webhook
使用 POST /webhooks 创建(需要 webhooks:manage 范围)。签名用的 secret 只返回一次。
事件:note.created、note.updated、note.deleted、folder.created、folder.updated、folder.deleted。
json
{ "id": "…", "event": "note.updated", "created_at": "2026-12-06T18:00:00.000Z",
"data": { "id": "note-id", "type": "note", "seq": 1234 } }载荷只包含 id。如需内容,请通过 API 获取该笔记。
验证签名
请求头:X-PalmNotes-Signature: t=<unix>,v1=<hex>,其中 v1 = HMAC_SHA256(secret, "<t>.<原始请求体>")。
ts
import { createHmac, timingSafeEqual } from 'node:crypto';
export function verify(secret: string, header: string, rawBody: string, toleranceSec = 300) {
const parts = Object.fromEntries(header.split(',').map((p) => p.split('=')));
if (Math.abs(Date.now() / 1000 - Number(parts.t)) > toleranceSec) return false;
const expected = createHmac('sha256', secret).update(`${parts.t}.${rawBody}`).digest('hex');
return timingSafeEqual(Buffer.from(expected), Buffer.from(parts.v1 ?? ''));
}python
import hmac, hashlib, time
def verify(secret: str, header: str, raw_body: bytes, tolerance_sec: int = 300) -> bool:
parts = dict(p.split("=", 1) for p in header.split(","))
if abs(time.time() - int(parts["t"])) > tolerance_sec:
return False
signed = parts["t"].encode() + b"." + raw_body
expected = hmac.new(secret.encode(), signed, hashlib.sha256).hexdigest()
return hmac.compare_digest(expected, parts.get("v1", ""))投递
- 仅支持 HTTPS;私有和内部地址会被拒绝。
- 请尽快返回任意
2xx。 - 失败会重试 5 次(30 秒、2 分钟、10 分钟、1 小时、6 小时)。连续 10 次投递失败后 Webhook 将被停用;可用
PATCH {"active": true}重新启用。