Webhooks

Send webhooks

Pick where a webhook goes, which changes send it, what its body holds and how it is signed.

Each key in webhooks names one webhook:

tenon.config.ts
webhooks: {
  purge: {
    url: "https://example.com/api/purge",
    collections: ["pages", "posts"],
    events: ["update", "delete"],
    secret: process.env.WEBHOOK_SECRET,
  },
},

Options

Where to send the request. It MUST be http or https. Read it from an environment variable: a missing variable fails at startup.The collections that send. Without collections and globals, every collection and global sends.The globals that send. Once you set collections or globals, only the listed ones send.The changes that send. Default: all three. See Events.What the body holds. Default: "minimal". See Payload.Seconds to collect changes into one request. See Collect changes.Signs each request. See Sign requests.Extra headers, like 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 global instead of collection and id.
  • permalink is the public URL after the change, and previousPermalink the one before. A slug change moves the URL, so a cache purge needs both. They are null for a collection without a permalink. On a delete, permalink is null.
  • locale is null without 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:

tenon.config.ts
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:

  1. The first change opens a window of debounce seconds.
  2. Every change in the window joins the same request.
  3. 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 debounce plus one tick.
  • A request holds at most 1000 changes. Past that, the rest are dropped and truncated is true. 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.

Does the receiver run in the same app as Tenon? Then a hook is simpler than a webhook. See Code instead of a request.
  1. Create a secret of at least 24 bytes:
    openssl rand -base64 32
    
  2. Set it as WEBHOOK_SECRET on both sides, and pass it as secret in the webhook.
  3. Check each request in the receiver with verifyWebhook():
    server/api/purge.ts
    import { 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:

HeaderValue
webhook-idThe id of the delivery
webhook-timestampWhen it was sent, in Unix seconds
webhook-signaturev1, 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:

  1. Set secret: [next, current] and deploy.
  2. Switch the receiver to the new secret.
  3. Remove the old secret from the list.