Send webhooks
Each key in webhooks names one webhook:
webhooks: {
purge: {
url: "https://example.com/api/purge",
collections: ["pages", "posts"],
events: ["update", "delete"],
secret: process.env.WEBHOOK_SECRET,
},
},
Options
http or https. Read it from an environment variable: a missing variable fails at startup.collections and globals, every collection and global sends.collections or globals, only the listed ones send."minimal". See Payload.authorization.The database stores only the name of the webhook and the body. The URL, the secret and the headers stay in your config, so a URL with a token never reaches the database or the admin.
Payload
Every request has the same shape: a list of changes. Without debounce, the list holds one change.
{
"changes": [
{
"event": "update",
"collection": "posts",
"id": "8f2c…",
"locale": "en",
"published": true,
"permalink": "/en/posts/new-slug",
"previousPermalink": "/en/posts/old-slug",
"at": "2026-11-10T12:00:00.000Z"
}
],
"truncated": false
}
- A global has
globalinstead ofcollectionandid. permalinkis the public URL after the change, andpreviousPermalinkthe one before. A slug change moves the URL, so a cache purge needs both. They arenullfor a collection without a permalink. On a delete,permalinkisnull.localeisnullwithout localization.
Full documents
payload: "full" adds doc and previousDoc to each change: the stored documents, with relations as ids.
Your own format
A function gets the batch with the full changes and returns the body. Use it for a service that expects its own JSON:
webhooks: {
slack: {
url: process.env.SLACK_WEBHOOK_URL!,
collections: ["posts"],
events: ["create"],
payload: ({ changes }) => ({
text: changes.map((c) => `New post: ${c.doc?.title} ${c.permalink}`).join("\n"),
}),
},
},
The function runs when the job sends, not during the write. It MAY be async. If it throws, the attempt fails and retries.
Collect changes
An import or a cascade delete can change hundreds of documents at once. A deploy hook should run once, not for each of them. debounce collects the changes into one request:
- The first change opens a window of
debounceseconds. - Every change in the window joins the same request.
- When the window ends, the next clock tick sends it.
- The window does not move. Constant editing never holds a deploy back for more than
debounceplus one tick. - A request holds at most 1000 changes. Past that, the rest are dropped and
truncatedistrue. Treat everything as changed then: rebuild the site, or purge the whole cache. - A change that arrives while the request is sending opens a new window.
Without debounce, every change sends its own request. An import of 500 documents sends 500 requests.
Sign requests
Without a secret, requests are not signed. A deploy hook URL is a secret of its own. When the receiver is your own code, set a secret so it can check that the request comes from Tenon.
- Create a secret of at least 24 bytes:
openssl rand -base64 32 - Set it as
WEBHOOK_SECRETon both sides, and pass it assecretin the webhook. - Check each request in the receiver with
verifyWebhook():server/api/purge.tsimport { verifyWebhook } from "tenoncms"; export async function POST(request: Request) { if (!(await verifyWebhook(request, process.env.WEBHOOK_SECRET!))) { return new Response(null, { status: 401 }); } const { changes, truncated } = await request.json(); // Purge `permalink` and `previousPermalink` of each change, or everything when `truncated`. return new Response(null, { status: 204 }); }
verifyWebhook() reads a copy of the request, so you can still read the body after it. It refuses a request whose time is more than 5 minutes off. { tolerance: 600 } changes that, in seconds.
Verify on another stack
The signature follows Standard Webhooks. A receiver that does not run JavaScript can check it with one of their libraries:
| Header | Value |
|---|---|
webhook-id | The id of the delivery |
webhook-timestamp | When it was sent, in Unix seconds |
webhook-signature | v1, and the base64 HMAC-SHA256 of id.timestamp.body |
A secret is either a plain string or a Standard Webhooks secret that starts with whsec_.
Change the secret
A list signs each request with every secret in it. To change a secret without downtime:
- Set
secret: [next, current]and deploy. - Switch the receiver to the new secret.
- Remove the old secret from the list.
Related resources
- Webhooks: retries and timeouts of a delivery.
- Receive webhooks: the other direction, a service that sends to Tenon.