# Webhooks

Events sent to an address of yours as they happen, signed, and retried for 72 hours.

## Add an endpoint

1. **Open Webhooks** In the [developer center](https://www.stackide.com/docs/developers), choose **Webhooks**, then **Add endpoint**. Owners and admins add endpoints.
2. **Give it an address** An `https://` address on the public internet. Add a description if you like.
3. **Choose what it hears** Every site in the workspace, or one site; every event (including ones added later), or only the ones you choose.
4. **Copy the signing secret** Press **Add endpoint**. The **Signing secret** (`slsig_…`) is shown once.

- A workspace can have 10 endpoints.
- Subscribe to an exact type (`site.published`), a prefix (`collection.*`) or everything (`*`).

## Deliveries

Each delivery is a `POST` with a JSON body, sent within about a minute of the event. Answer with any `2xx` within 10 seconds. Redirects are not followed.

| Header | Holds |
| --- | --- |
| `Stacklumen-Signature` | `t=<unix seconds>,v1=<signature>` |
| `Stacklumen-Event` | The event type, such as `site.published` |
| `Stacklumen-Event-Id` | The event’s id (`evt_…`), the same on every retry: de-duplicate on it |
| `Stacklumen-Delivery-Id` | This delivery’s id (`wd_…`) |

```json
{
  "id": "evt_…",
  "type": "site.published",
  "mode": "live",
  "created_at": "2026-12-02T09:30:00.000Z",
  "workspace_id": "…",
  "object": {"type": "site", "id": "…"},
  "data": {…}
}
```

A delivery that does not get a `2xx` is tried again after 1, 5 and 30 minutes, then 2, 6, 12 and 24 hours, and given up 72 hours after the first try. If every delivery to an endpoint fails for three days, it is turned off and the workspace’s owners and admins are told.

## Verify the signature

`Stacklumen-Signature` is an HMAC-SHA256, in lowercase hex, of the timestamp `t`, a full stop and the raw body, keyed with the whole signing secret (`slsig_` included).

1. **Read the body exactly as it arrived** Before any JSON parsing: a body parsed and written out again will not match.
2. **Compute and compare** HMAC-SHA256 of `t` + `.` + the body, as hex, compared with `v1` in constant time.
3. **Check the time, then de-duplicate** Refuse a `t` more than 5 minutes from your clock, then de-duplicate on `Stacklumen-Event-Id`.

```ts
import {createHmac, timingSafeEqual} from 'node:crypto';

const TOLERANCE_SECONDS = 300;

/** True when rawBody, the body exactly as received, was signed with secret. */
export function verify(rawBody: string, header: string | null, secret: string, now = Math.floor(Date.now() / 1000)) {
  if (!header) return false;
  const parts = Object.fromEntries(header.split(',').map((p) => p.split('=') as [string, string]));
  const t = Number(parts.t);
  if (!t || !parts.v1 || Math.abs(now - t) > TOLERANCE_SECONDS) return false;
  const expected = createHmac('sha256', secret).update(`${t}.${rawBody}`).digest('hex');
  const a = Buffer.from(expected);
  const b = Buffer.from(parts.v1);
  return a.length === b.length && timingSafeEqual(a, b);
}
```

> **Warning:** **New signing secret** ends the old one at once. Update your receiver straight away, or its deliveries fail the check.

## Testing and replaying

| Action | What it does |
| --- | --- |
| **Send test event** | Sends a `webhook.test` event to the endpoint now and shows the answer. |
| **Redeliver** | Sends one delivery again, with the same event id. |
| **Send failed events again** | Queues every event of the last 30 days whose deliveries all failed. |
| **Disable** / **Enable** | Stops and starts deliveries. |
