---
title: "Webhooks"
description: "Inbox and account webhooks, typed lifecycle payloads, signature verification in Node, Web Crypto and Python, retries, delivery failures, the delivery log and test deliveries."
url: https://doorman.fyi/docs/webhooks
markdown: https://doorman.fyi/docs/webhooks.md
area: "Guides"
section: "Being told about mail"
---

# Webhooks

Inbox and account webhooks, typed lifecycle payloads, signature verification in Node, Web Crypto and Python, retries, delivery failures, the delivery log and test deliveries.

Source: https://doorman.fyi/docs/webhooks

## Two kinds of target

A webhook is a URL of yours that receives a POST for every event. There are two kinds, and an event goes to every one that matches.

- The inbox webhook: One URL per inbox, set with [`PUT /v1/inboxes/{inboxId}/webhook`](https://doorman.fyi/docs/reference/webhooks.md#inboxes-webhook-set) or when [the inbox is issued](https://doorman.fyi/docs/inboxes.md#one-call). It receives every event for that inbox and has its own signing secret. Setting it again replaces the URL and mints a new secret.
- An account endpoint: A URL that receives the account's events across inboxes, created with [`POST /v1/webhooks`](https://doorman.fyi/docs/reference/webhooks.md#webhooks-create). `eventTypes` and `inboxIds` narrow what it receives (empty means all), `enabled` switches it off without deleting it, and it has its own secret. An account holds at most 20.

Use the inbox webhook when one agent owns one inbox. Use an endpoint when one service watches a fleet of inboxes, or when two systems need the same events. Managing either needs account scope: an inbox-scoped key gets `403 forbidden`. In an [organization](https://doorman.fyi/docs/organizations.md#operations), managing either from the console takes the member's `webhooks:manage`, and pointing one at a URL takes `mail:read` as well, because a webhook receives mail.

Set the inbox webhook:
```sh
curl -s -X PUT "https://api.doorman.fyi/v1/inboxes/inb_01jc4q7w9k2m5n8p3r6t1v4x7z/webhook" \
  -H "authorization: Bearer $DOORMAN_API_KEY" \
  -H "content-type: application/json" \
  -d '{
    "url": "https://agent.example.com/hooks/doorman"
  }'
```

200 OK:
```json
{
  "url": "https://agent.example.com/hooks/doorman",
  "secret": "whsec_dGVzdC13ZWJob29rLXNpZ25pbmctc2VjcmV0LTAxMjM0NTY3ODk="
}
```

> Warning: The secret is shown once. The URL must be https without credentials (http is accepted in local development). Rotating the secret with [`POST /v1/inboxes/{inboxId}/webhook/rotate-secret`](https://doorman.fyi/docs/reference/webhooks.md#inboxes-webhook-rotateSecret) or [`POST /v1/webhooks/{endpointId}/rotate-secret`](https://doorman.fyi/docs/reference/webhooks.md#webhooks-rotateSecret) replaces it at once, so update the receiver first.

## The message.received payload

All [event types](https://doorman.fyi/docs/events.md#types) use the same signature and delivery mechanism. Dispatch on `event`: only the mail events have a `message`, and account-level `delivery.failed` payloads have `inbox_id: null`. The example below is inbound mail; the [SDK verifier](https://doorman.fyi/docs/sdk.md#verify) returns a typed union.

Each inbound message produces one `message.received` event, posted as JSON with snake_case field names: the event's id and when it occurred, the inbox and the thread, and the message with its sender, recipients, subject, plain-text body, attachments with their extracted text, classification and the URL of the original. The shape is the [`MessageReceivedEvent`](https://doorman.fyi/docs/reference/schemas.md#MessageReceivedEvent) schema.

The request body:
```json
{
  "event": "message.received",
  "event_id": "evt_01jc5e5f6g7h8j9k0m1n2p3q4r",
  "occurred_at": "2026-11-05T10:05:00.000Z",
  "inbox_id": "inb_01jc4q7w9k2m5n8p3r6t1v4x7z",
  "thread_id": "thr_01jc5a1b2c3d4e5f6g7h8j9k0m",
  "message": {
    "id": "msg_01jc5a6g7h8j9k0m1n2p3q4r5s",
    "rfc_message_id": "<a1b2c3@example.com>",
    "from": "sam@example.com",
    "to": "concierge@doorman.example",
    "header_to": "concierge@doorman.example",
    "delivery_role": "to",
    "cc": [],
    "address_names": {
      "sam@example.com": "Sam Rivera"
    },
    "subject": "Invoice 2847",
    "body_text": "Hi, invoice 2847 is attached.",
    "attachments": [
      {
        "filename": "invoice.pdf",
        "contentType": "application/pdf",
        "sizeBytes": 45000,
        "url": "https://api.doorman.example/v1/attachments/msg_01jc5a6g7h8j9k0m1n2p3q4r5s/invoice.pdf",
        "parsedText": "Invoice 2847. Line 3: Setup fee, billed twice. Total 1,480.",
        "extractionMethod": "pdf"
      }
    ],
    "raw_url": "https://api.doorman.example/v1/messages/msg_01jc5a6g7h8j9k0m1n2p3q4r5s/raw",
    "received_at": "2026-11-05T10:05:00.000Z",
    "category": "personal",
    "auto_replyable": true,
    "verdict": "clean",
    "spam_score": 0.02,
    "risk": {
      "score": 6,
      "level": "low",
      "labels": [],
      "reasons": [],
      "sender": {
        "standing": "known",
        "authenticated": true
      },
      "action": "delivered",
      "analysis": "full",
      "review": null
    }
  }
}
```

`body_text` is the plain-text body, empty when there was none. `address_names` maps addresses to the display names they carried. `auto_replyable`, `category` and `verdict` are explained in [Receiving mail](https://doorman.fyi/docs/receiving.md#classification). Everything else about the message, the HTML body included, is one API call away through the identifiers in the payload.

## Verifying a delivery

Every delivery carries three headers in the Standard Webhooks form: `webhook-id` (the event id, stable across retries), `webhook-timestamp` (seconds since the epoch when the attempt was signed) and `webhook-signature`, which is `v1,` followed by the base64 HMAC-SHA256 of `<id>.<timestamp>.<body>` computed with the decoded secret (the base64 after `whsec_`). Several space-separated signatures may appear, so accept the request when any of them matches.

Verify before parsing, over the raw request body, and refuse stale timestamps. Any Standard Webhooks library verifies these deliveries; so does a few lines of the standard library:

Node:
```js
import { createHmac, timingSafeEqual } from "node:crypto";

// secret is the whsec_... value shown once; body is the raw request text, not re-serialized JSON.
export function verify(headers, body, secret) {
  const id = headers["webhook-id"];
  const timestamp = headers["webhook-timestamp"];
  const key = Buffer.from(secret.replace(/^whsec_/, ""), "base64");
  const expected = createHmac("sha256", key).update(`${id}.${timestamp}.${body}`).digest("base64");
  const fresh = Math.abs(Date.now() / 1000 - Number(timestamp)) < 300;
  return fresh && headers["webhook-signature"].split(" ").some((part) => {
    const [version, signature] = part.split(",");
    return version === "v1" && signature.length === expected.length
      && timingSafeEqual(Buffer.from(signature), Buffer.from(expected));
  });
}
```

Web Crypto:
```ts
// Workers, Deno, Bun and the browser. body is the raw request text.
export async function verify(headers: Headers, body: string, secret: string): Promise<boolean> {
  const id = headers.get("webhook-id") ?? "";
  const timestamp = headers.get("webhook-timestamp") ?? "";
  const raw = Uint8Array.from(atob(secret.replace(/^whsec_/, "")), (c) => c.charCodeAt(0));
  const key = await crypto.subtle.importKey("raw", raw, { name: "HMAC", hash: "SHA-256" }, false, ["sign"]);
  const mac = await crypto.subtle.sign("HMAC", key, new TextEncoder().encode(`${id}.${timestamp}.${body}`));
  const expected = btoa(String.fromCharCode(...new Uint8Array(mac)));
  const fresh = Math.abs(Date.now() / 1000 - Number(timestamp)) < 300;
  return fresh && (headers.get("webhook-signature") ?? "").split(" ").some((part) => part === `v1,${expected}`);
}
```

Python:
```python
import base64, hmac, hashlib, time

def verify(headers: dict, body: bytes, secret: str) -> bool:
    msg_id = headers["webhook-id"]
    timestamp = headers["webhook-timestamp"]
    key = base64.b64decode(secret.removeprefix("whsec_"))
    expected = base64.b64encode(
        hmac.new(key, f"{msg_id}.{timestamp}.".encode() + body, hashlib.sha256).digest()
    ).decode()
    fresh = abs(time.time() - int(timestamp)) < 300
    signatures = [part.split(",", 1)[1] for part in headers["webhook-signature"].split() if part.startswith("v1,")]
    return fresh and any(hmac.compare_digest(sig, expected) for sig in signatures)
```

> Note: [`POST /v1/webhooks/{endpointId}/test`](https://doorman.fyi/docs/reference/webhooks.md#webhooks-test) posts one signed sample with `"test": true` to an endpoint, enabled or not, so a receiver can be checked before real mail arrives. Nothing is stored. It answers what the URL did: `ok`, `statusCode`, `error` and `durationMs`.

## Timeouts, retries and duplicates

A delivery succeeds on any `2xx` answered within 15 seconds. Redirects count as failures, and so do `3xx`, `4xx`, `5xx`, timeouts and connection errors. A failed attempt is retried after 30, 60, 120 and 240 seconds, 5 attempts in total, and every attempt is recorded.

Delivery is at least once: a slow receiver that answered after the timeout will see the same event again. The event id in `webhook-id` (and `event_id` in the body) is stable across retries, so deduplicate on it. Answer `2xx` as soon as the event is safely queued on your side; do the work afterwards.

The webhook queue does not retry forever and the stream does not retry at all. An agent that must not miss anything keeps the last `seq` it handled and [polls the log](https://doorman.fyi/docs/events.md) after an outage, or reconnects to [the stream](https://doorman.fyi/docs/stream.md) with `last_event_id`.

A terminal failure records `delivery.failed` atomically with the failed delivery. Inbox webhook failures retain inbox scope; account endpoint failures require account scope. A failed delivery of that notification produces no further failure event.

## The delivery log

Every attempt is recorded as a [`Delivery`](https://doorman.fyi/docs/reference/schemas.md#Delivery): the event, the target (`inbox` or `endpoint` and its id), the URL at the time, `status` (`pending`, `delivered` or `failed`), `attempts`, `lastStatusCode` and `lastError` (`HTTP <status>`, `timeout`, `network_error` or `target_unavailable`).

- [`GET /v1/inboxes/{inboxId}/webhook/deliveries`](https://doorman.fyi/docs/reference/webhooks.md#inboxes-webhook-deliveries) is the inbox webhook's log, newest first, deliveries to URLs the inbox no longer points at included.
- [`GET /v1/webhooks/{endpointId}/deliveries`](https://doorman.fyi/docs/reference/webhooks.md#webhooks-deliveries) is an endpoint's log. Both page with `limit` and `cursor`, the delivery id to continue from.
- [`GET /v1/events/{eventId}`](https://doorman.fyi/docs/reference/events.md#events-get) shows one event with the payload exactly as it was signed and every delivery it produced.

A delivery:
```json
{
  "id": "whd_01jc5f1a2b3c4d5e6f7g8h9j0k",
  "eventId": "evt_01jc5e5f6g7h8j9k0m1n2p3q4r",
  "target": {
    "kind": "endpoint",
    "id": "whk_01jc5d1a2b3c4d5e6f7g8h9j0k"
  },
  "url": "https://agent.example.com/hooks/doorman",
  "status": "delivered",
  "attempts": 1,
  "lastStatusCode": 200,
  "lastError": null,
  "createdAt": "2026-11-05T10:05:00.000Z",
  "updatedAt": "2026-11-05T10:05:00.000Z"
}
```

## Retrying a delivery by hand

[`POST /v1/deliveries/{deliveryId}/retry`](https://doorman.fyi/docs/reference/webhooks.md#deliveries-retry) puts a delivered or failed delivery back in the queue and answers `202` with the delivery, now `pending`. The attempt is numbered after the previous ones: a delivery that used its whole budget gets exactly one more attempt, and one that still had attempts left follows the usual schedule from where it was. A delivery already queued answers `409 delivery_pending`.

| Case | What happens |
| --- | --- |
| The target was deleted, its URL changed since, or the endpoint is disabled | The retry fails as `target_unavailable`. Enable or repoint the target first, then retry. |
| The receiver fixed a bug | Retry the failed deliveries from the log, oldest first, so events arrive in order. |
