> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dockiln.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Webhook events

> Receive signed completion and failure notifications and safely acknowledge repeat deliveries.

## Subscribe to terminal events

In **Settings**, save a public HTTPS webhook URL and copy the signing secret when shown. Store it on the receiving server. The 1.1 build also accepts a per-job `webhook` with its own `url` and `secret`. DocKiln rejects redirects during delivery.

| Signed payload type | What the receiver can do |
| - | - |
| `document.completed` | Read `document.id` and fetch the relative `document.download` from your configured DocKiln origin using a workspace credential. |
| `document.failed` | Read `document.error` and record the failure against your job. The download field is null. |

## Verify before parsing

Capture the raw request body as a Buffer before JSON middleware transforms it. This Node.js helper takes the incoming Node HTTP headers and enforces a five-minute clock tolerance. Pass the secret associated with this subscription.

```js theme={null}
import { createHmac, timingSafeEqual } from "node:crypto";

export function verifyEvent(rawBody, headers, secret, now = Date.now()) {
  const ts = headers["x-dockiln-timestamp"];
  const sig = headers["x-dockiln-signature"];
  if (typeof ts !== "string" || !/^\d{1,12}$/.test(ts) ||
      Math.abs(Math.floor(now / 1000) - Number(ts)) > 300) {
    throw new Error("Invalid event timestamp");
  }
  if (typeof sig !== "string" || !/^v1=[a-f0-9]{64}$/.test(sig)) {
    throw new Error("Invalid signature format");
  }
  const expected = createHmac("sha256", secret)
    .update(ts + ".").update(rawBody).digest();
  if (!timingSafeEqual(expected, Buffer.from(sig.slice(3), "hex"))) {
    throw new Error("Signature mismatch");
  }
  const event = JSON.parse(rawBody.toString("utf8"));
  if (event.id !== headers["x-dockiln-event"]) {
    throw new Error("Event ID mismatch");
  }
  return event;
}
```

## Handle retries once

Persist the verified event ID with a unique constraint and enqueue the business action in the same database transaction. Return a 2xx response after that transaction commits, including when the event was already accepted. This lets the sender retry a lost acknowledgement without sending your customer a second email.

The sender signs each attempt. The event ID stays stable. After a failed attempt, retry delays are 5 seconds, 30 seconds, 2 minutes and 10 minutes. After the fifth failure, delivery stops. Check [endpoint and delivery history](https://docs.dockiln.io/api-reference/endpoint-and-delivery-history.md) from a signed-in session.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.