# Webhooks

> Get a signed POST on your server when an envelope is sent, viewed, signed, declined, completed or voided, with retries for 3 days.

A webhook tells your server when something happens in your workspace, such as a client signing, so you don't have to poll. AppliFlo sends a `POST` with a small JSON summary to a URL you choose, signs it with a secret only you and AppliFlo know, and tries again for 3 days if your server doesn't answer.

Webhooks follow the [Standard Webhooks](https://www.standardwebhooks.com/) spec, so any Standard Webhooks library can check them.

> **Summaries, never answers**
>
> A webhook says what happened and to which envelope: ids, names, statuses and times. It never carries what anyone typed into a form, signature images, access codes, IP addresses or files. To get the signed PDF, [download it with the API](https://dev.appliflo.com/guides/track-envelopes#download-the-signed-pdf).

## Add an endpoint

### Open Settings

An owner or admin opens [Settings → API & AI apps](https://appliflo.com/settings/api-keys) on appliflo.com and scrolls to **Webhooks**. Webhooks work on every plan, and you don't need an API key to use them. A workspace can have up to 20 endpoints.

### Add the URL and pick events

Click **Add endpoint**. Enter an `https://` URL on the standard port (443), a name so you know what it is, and the events you want, or **Select all**.

### Copy the signing secret

The secret starts with `whsec_`. It is shown once. Copy it into your server's settings, for example as `APPLIFLO_WEBHOOK_SECRET`. AppliFlo keeps it encrypted and can't show it again; if you lose it, [rotate it](#rotate-the-secret).

### Send a test

Open the endpoint's **Delivery log** and click **Send test event**. Your server gets a `webhook.test` event, and the log shows what your server answered.

## Events

| Event | Sent when |
| --- | --- |
| `envelope.sent` | An envelope is sent, or sent again with **Resend**. With signing in order, later people getting their turn is not a separate `envelope.sent`. |
| `envelope.viewed` | A recipient's signing page first shows in their browser. Once per recipient per round, never after the round is over; a link scanner opening the link doesn't count. If the page never reports it (for example a signer working through the API), it comes when they consent. |
| `envelope.signed` | One recipient finished signing. Others may still have to. |
| `envelope.declined` | A recipient declined to sign. |
| `envelope.completed` | Everyone has signed and the signed PDF is sealed and ready to download. |
| `envelope.voided` | The sender voided the envelope. |
| `bulk.row_failed` | One row of a [send to many](https://dev.appliflo.com/guides/send-to-many) batch could not be sent. Rows in a batch you cancelled are not announced. |
| `document.detected` | AppliFlo finished finding the boxes on an uploaded document. |
| `webhook.test` | Someone clicked **Send test event**. Only that endpoint gets it. |

Every body has the same outer shape around the event's `data`:

```json
{
  "id": "evt_k7q2m3x4b5n3p6r2t5v4w2y4",
  "type": "envelope.completed",
  "created_at": "2026-11-26T10:00:00Z",
  "workspace_id": "cmw2k8r1d0000qnzh5t7b3a9c",
  "data": { "...": "..." }
}
```

`id` is the event id. It is the same as the `webhook-id` header, and stays the same on every retry. Only event ids have a prefix (`evt_`); envelope, document, client and batch ids are plain strings such as `cmwxfhd0u000qnzhjrb1yhjvw`. Store all ids as text and don't parse them. Times are UTC to the second, such as `2026-11-26T10:00:00Z`. New fields may be added to `data`, so ignore fields you don't know.

### Envelope events

All six `envelope.*` events share one `data` shape:

| Field | What it is |
| --- | --- |
| `envelope_id`, `document_id`, `document_name` | Which envelope, and the document it carries. |
| `status` | `awaiting`, `completing`, `completed`, `declined`, `expired` or `voided`, as in [Track envelopes](https://dev.appliflo.com/guides/track-envelopes#list-envelopes). |
| `round` | 1 for the first send, then 2, 3 and on after each **Resend**. |
| `sent_at` | When this round was sent. Always there. |
| `completed_at`, `voided_at` | Only once the envelope is completed or voided. |
| `recipient` | On `envelope.viewed`, `envelope.signed` and `envelope.declined` only: the person who acted, in the same shape as a `recipients` entry. |
| `recipients` | Everyone on the envelope. |
| `client_id` | Only when the envelope is linked to a client. |

Each recipient has `name`, `email`, `role`, `kind` and `status`:

- `kind` is `signer`, `filler` or `cc`.
- `role` is the template role label, such as `"Client"`, or `null` when the envelope was not sent from a template.
- `status` is `pending`, `sent`, `completed` (signed) or `declined`. A `cc` stays `pending`.
- `viewed_at`, `signed_at` and `declined_at` are there only once they happened. `viewed_at` is when the signing page first showed; the signing certificate keeps its own record.

**envelope.sent**

```json
{
  "id": "evt_a2b3c4d5e6f7g2h3j4k5m6n7",
  "type": "envelope.sent",
  "created_at": "2026-11-26T09:00:00Z",
  "workspace_id": "cmw2k8r1d0000qnzh5t7b3a9c",
  "data": {
    "envelope_id": "cmwxfhd0u000qnzhjrb1yhjvw",
    "document_id": "cmwxf9a2k0004qnzh8vd1m6pe",
    "document_name": "Tenancy agreement",
    "status": "awaiting",
    "round": 1,
    "sent_at": "2026-11-26T09:00:00Z",
    "recipients": [
      { "name": "Lan Nguyen", "email": "lan@example.com", "role": "Tenant", "kind": "signer", "status": "sent" },
      { "name": "Omar Haddad", "email": "omar@example.com", "role": "Landlord", "kind": "signer", "status": "sent" },
      { "name": "Priya Shah", "email": "priya@example.com", "role": null, "kind": "cc", "status": "pending" }
    ],
    "client_id": "cmwq3n7xb0002ld0k4h9s2e7f"
  }
}
```

**envelope.viewed**

```json
{
  "id": "evt_b3c4d5e6f7g2h3j4k5m6n7p2",
  "type": "envelope.viewed",
  "created_at": "2026-11-26T09:12:04Z",
  "workspace_id": "cmw2k8r1d0000qnzh5t7b3a9c",
  "data": {
    "envelope_id": "cmwxfhd0u000qnzhjrb1yhjvw",
    "document_id": "cmwxf9a2k0004qnzh8vd1m6pe",
    "document_name": "Tenancy agreement",
    "status": "awaiting",
    "round": 1,
    "sent_at": "2026-11-26T09:00:00Z",
    "recipient": { "name": "Lan Nguyen", "email": "lan@example.com", "role": "Tenant", "kind": "signer", "status": "sent", "viewed_at": "2026-11-26T09:12:04Z" },
    "recipients": [
      { "name": "Lan Nguyen", "email": "lan@example.com", "role": "Tenant", "kind": "signer", "status": "sent", "viewed_at": "2026-11-26T09:12:04Z" },
      { "name": "Omar Haddad", "email": "omar@example.com", "role": "Landlord", "kind": "signer", "status": "sent" },
      { "name": "Priya Shah", "email": "priya@example.com", "role": null, "kind": "cc", "status": "pending" }
    ],
    "client_id": "cmwq3n7xb0002ld0k4h9s2e7f"
  }
}
```

**envelope.signed**

```json
{
  "id": "evt_c4d5e6f7g2h3j4k5m6n7p2q3",
  "type": "envelope.signed",
  "created_at": "2026-11-26T09:20:31Z",
  "workspace_id": "cmw2k8r1d0000qnzh5t7b3a9c",
  "data": {
    "envelope_id": "cmwxfhd0u000qnzhjrb1yhjvw",
    "document_id": "cmwxf9a2k0004qnzh8vd1m6pe",
    "document_name": "Tenancy agreement",
    "status": "awaiting",
    "round": 1,
    "sent_at": "2026-11-26T09:00:00Z",
    "recipient": { "name": "Lan Nguyen", "email": "lan@example.com", "role": "Tenant", "kind": "signer", "status": "completed", "viewed_at": "2026-11-26T09:12:04Z", "signed_at": "2026-11-26T09:20:31Z" },
    "recipients": [
      { "name": "Lan Nguyen", "email": "lan@example.com", "role": "Tenant", "kind": "signer", "status": "completed", "viewed_at": "2026-11-26T09:12:04Z", "signed_at": "2026-11-26T09:20:31Z" },
      { "name": "Omar Haddad", "email": "omar@example.com", "role": "Landlord", "kind": "signer", "status": "sent" },
      { "name": "Priya Shah", "email": "priya@example.com", "role": null, "kind": "cc", "status": "pending" }
    ],
    "client_id": "cmwq3n7xb0002ld0k4h9s2e7f"
  }
}
```

**envelope.declined**

```json
{
  "id": "evt_d5e6f7g2h3j4k5m6n7p2q3r4",
  "type": "envelope.declined",
  "created_at": "2026-11-26T09:25:10Z",
  "workspace_id": "cmw2k8r1d0000qnzh5t7b3a9c",
  "data": {
    "envelope_id": "cmwxfhd0u000qnzhjrb1yhjvw",
    "document_id": "cmwxf9a2k0004qnzh8vd1m6pe",
    "document_name": "Tenancy agreement",
    "status": "declined",
    "round": 1,
    "sent_at": "2026-11-26T09:00:00Z",
    "recipient": { "name": "Omar Haddad", "email": "omar@example.com", "role": "Landlord", "kind": "signer", "status": "declined", "viewed_at": "2026-11-26T09:24:02Z", "declined_at": "2026-11-26T09:25:10Z" },
    "recipients": [
      { "name": "Lan Nguyen", "email": "lan@example.com", "role": "Tenant", "kind": "signer", "status": "completed", "viewed_at": "2026-11-26T09:12:04Z", "signed_at": "2026-11-26T09:20:31Z" },
      { "name": "Omar Haddad", "email": "omar@example.com", "role": "Landlord", "kind": "signer", "status": "declined", "viewed_at": "2026-11-26T09:24:02Z", "declined_at": "2026-11-26T09:25:10Z" },
      { "name": "Priya Shah", "email": "priya@example.com", "role": null, "kind": "cc", "status": "pending" }
    ],
    "client_id": "cmwq3n7xb0002ld0k4h9s2e7f"
  }
}
```

**envelope.completed**

```json
{
  "id": "evt_e6f7g2h3j4k5m6n7p2q3r4s5",
  "type": "envelope.completed",
  "created_at": "2026-11-26T10:00:02Z",
  "workspace_id": "cmw2k8r1d0000qnzh5t7b3a9c",
  "data": {
    "envelope_id": "cmwxfhd0u000qnzhjrb1yhjvw",
    "document_id": "cmwxf9a2k0004qnzh8vd1m6pe",
    "document_name": "Tenancy agreement",
    "status": "completed",
    "round": 1,
    "sent_at": "2026-11-26T09:00:00Z",
    "completed_at": "2026-11-26T10:00:02Z",
    "recipients": [
      { "name": "Lan Nguyen", "email": "lan@example.com", "role": "Tenant", "kind": "signer", "status": "completed", "viewed_at": "2026-11-26T09:12:04Z", "signed_at": "2026-11-26T09:20:31Z" },
      { "name": "Omar Haddad", "email": "omar@example.com", "role": "Landlord", "kind": "signer", "status": "completed", "viewed_at": "2026-11-26T09:58:15Z", "signed_at": "2026-11-26T09:59:47Z" },
      { "name": "Priya Shah", "email": "priya@example.com", "role": null, "kind": "cc", "status": "pending" }
    ],
    "client_id": "cmwq3n7xb0002ld0k4h9s2e7f"
  }
}
```

**envelope.voided**

```json
{
  "id": "evt_f7g2h3j4k5m6n7p2q3r4s5t6",
  "type": "envelope.voided",
  "created_at": "2026-11-26T11:00:00Z",
  "workspace_id": "cmw2k8r1d0000qnzh5t7b3a9c",
  "data": {
    "envelope_id": "cmwxfhd0u000qnzhjrb1yhjvw",
    "document_id": "cmwxf9a2k0004qnzh8vd1m6pe",
    "document_name": "Tenancy agreement",
    "status": "voided",
    "round": 1,
    "sent_at": "2026-11-26T09:00:00Z",
    "voided_at": "2026-11-26T11:00:00Z",
    "recipients": [
      { "name": "Lan Nguyen", "email": "lan@example.com", "role": "Tenant", "kind": "signer", "status": "sent", "viewed_at": "2026-11-26T09:12:04Z" },
      { "name": "Omar Haddad", "email": "omar@example.com", "role": "Landlord", "kind": "signer", "status": "sent" },
      { "name": "Priya Shah", "email": "priya@example.com", "role": null, "kind": "cc", "status": "pending" }
    ]
  }
}
```

### Other events

**bulk.row_failed**

`row` is the row's index in the batch you sent. `error` says in words why that row was not sent, such as a bounce. Fix it as in [Send to many](https://dev.appliflo.com/guides/send-to-many).

```json
{
  "id": "evt_g2h3j4k5m6n7p2q3r4s5t6u7",
  "type": "bulk.row_failed",
  "created_at": "2026-11-26T09:03:41Z",
  "workspace_id": "cmw2k8r1d0000qnzh5t7b3a9c",
  "data": {
    "batch_id": "cmwy2c5ph0001qnzhd8k3w4ra",
    "row": 12,
    "error": "Bounced: mailbox full"
  }
}
```

**document.detected**

`field_count` is how many boxes were found. `page_count` can be `null` when the page count isn't known.

```json
{
  "id": "evt_h3j4k5m6n7p2q3r4s5t6u7v2",
  "type": "document.detected",
  "created_at": "2026-11-26T08:58:19Z",
  "workspace_id": "cmw2k8r1d0000qnzh5t7b3a9c",
  "data": {
    "document_id": "cmwxf9a2k0004qnzh8vd1m6pe",
    "document_name": "Form 956 Appointment of a registered migration agent",
    "page_count": 6,
    "field_count": 84
  }
}
```

**webhook.test**

Use it to check your URL and your signature check. Don't act on it.

```json
{
  "id": "evt_j4k5m6n7p2q3r4s5t6u7v2w3",
  "type": "webhook.test",
  "created_at": "2026-11-26T08:00:00Z",
  "workspace_id": "cmw2k8r1d0000qnzh5t7b3a9c",
  "data": {}
}
```

## Headers

| Header | Value |
| --- | --- |
| `webhook-id` | The event id: `evt_` and 24 characters. The same on every retry of that event. |
| `webhook-timestamp` | When this attempt was sent, in Unix seconds. |
| `webhook-signature` | `v1,` and a base64 HMAC-SHA256 signature. During a secret rotation there are two, separated by a space. |
| `content-type` | `application/json` |
| `user-agent` | `AppliFlo-Webhooks/1` |

## Check the signature

Check every request before you trust it. The signature is an HMAC-SHA256 of `webhook-id`, `webhook-timestamp` and the raw body, joined with dots:

```text
{webhook-id}.{webhook-timestamp}.{raw body}
```

The key is the part of your secret after `whsec_`, base64-decoded. Compare signatures in constant time, and refuse a timestamp more than 5 minutes from your clock, so an old request can't be replayed.

Sign the **raw body**, exactly as it arrived. If your framework parses the JSON and you stringify it again, the bytes can change and the check fails.

**Node (standardwebhooks)**

The [`standardwebhooks`](https://www.npmjs.com/package/standardwebhooks) package checks the signature and the timestamp for you.

```bash
npm install standardwebhooks
```

```js
import express from "express";
import { Webhook } from "standardwebhooks";

const wh = new Webhook(process.env.APPLIFLO_WEBHOOK_SECRET); // whsec_...
const app = express();

// express.raw keeps the body as bytes, so the signature can be checked.
app.post("/hooks/appliflo", express.raw({ type: "application/json" }), (req, res) => {
  let event;
  try {
    event = wh.verify(req.body, req.headers);
  } catch {
    return res.status(400).send("Bad signature");
  }
  res.sendStatus(204); // answer first, then do the work
  handle(event);
});
```

**Node (no dependencies)**

Only `node:crypto`. It accepts any of the `v1,` signatures, so it keeps working during a rotation.

```js title="verify-webhook.js"
import { createHmac, timingSafeEqual } from "node:crypto";

const TOLERANCE_SECONDS = 5 * 60;

/**
 * Checks an AppliFlo webhook and returns the parsed event.
 * secret: "whsec_...". headers: lower-case names. body: the raw body as a string.
 */
export function verifyWebhook(secret, headers, body) {
  const id = headers["webhook-id"];
  const timestamp = headers["webhook-timestamp"];
  const signatures = headers["webhook-signature"];
  if (!id || !timestamp || !signatures) throw new Error("Missing webhook headers");

  const sentAt = Number(timestamp);
  const now = Math.floor(Date.now() / 1000);
  if (!Number.isInteger(sentAt) || Math.abs(now - sentAt) > TOLERANCE_SECONDS) {
    throw new Error("Timestamp is too old or too new");
  }

  const key = Buffer.from(secret.replace(/^whsec_/, ""), "base64");
  const expected = createHmac("sha256", key).update(`${id}.${timestamp}.${body}`).digest();

  // "v1,<sig>" or, during a rotation, "v1,<new> v1,<old>".
  for (const part of signatures.split(" ")) {
    const [version, signature] = part.split(",");
    if (version !== "v1" || !signature) continue;
    const given = Buffer.from(signature, "base64");
    if (given.length === expected.length && timingSafeEqual(given, expected)) {
      return JSON.parse(body);
    }
  }
  throw new Error("No matching signature");
}
```

```js
import express from "express";
import { verifyWebhook } from "./verify-webhook.js";

const app = express();

app.post("/hooks/appliflo", express.raw({ type: "application/json" }), (req, res) => {
  let event;
  try {
    event = verifyWebhook(process.env.APPLIFLO_WEBHOOK_SECRET, req.headers, req.body.toString("utf8"));
  } catch {
    return res.status(400).send("Bad signature");
  }
  res.sendStatus(204);
  handle(event);
});
```

**Python**

Only the standard library. The `standardwebhooks` package on PyPI does the same job if you prefer a library.

```python title="verify_webhook.py"
import base64
import hashlib
import hmac
import json
import time

TOLERANCE_SECONDS = 5 * 60

def verify_webhook(secret, headers, body):
    """Checks an AppliFlo webhook and returns the parsed event.

    secret: "whsec_...". headers: a dict with lower-case names. body: the raw body as bytes.
    """
    msg_id = headers.get("webhook-id")
    timestamp = headers.get("webhook-timestamp")
    signatures = headers.get("webhook-signature")
    if not msg_id or not timestamp or not signatures:
        raise ValueError("Missing webhook headers")

    if not timestamp.isdigit() or abs(time.time() - int(timestamp)) > TOLERANCE_SECONDS:
        raise ValueError("Timestamp is too old or too new")

    key = base64.b64decode(secret[len("whsec_"):] if secret.startswith("whsec_") else secret)
    signed = f"{msg_id}.{timestamp}.".encode() + body
    expected = base64.b64encode(hmac.new(key, signed, hashlib.sha256).digest()).decode()

    # "v1,<sig>" or, during a rotation, "v1,<new> v1,<old>".
    for part in signatures.split(" "):
        version, _, signature = part.partition(",")
        if version == "v1" and hmac.compare_digest(signature, expected):
            return json.loads(body)
    raise ValueError("No matching signature")
```

With Flask:

```python
import os
from flask import Flask, request
from verify_webhook import verify_webhook

app = Flask(__name__)

@app.post("/hooks/appliflo")
def appliflo_hook():
    headers = {k.lower(): v for k, v in request.headers.items()}
    try:
        event = verify_webhook(os.environ["APPLIFLO_WEBHOOK_SECRET"], headers, request.get_data())
    except ValueError:
        return "Bad signature", 400
    handle(event)
    return "", 204
```

## Answer quickly

Answer with any `2xx` status within 10 seconds. Anything else counts as a failure: another status, a timeout, or a redirect. AppliFlo doesn't follow redirects, so give the final URL. If the work takes longer, answer first and do it afterwards, for example from a queue.

## Retries

Deliveries go out from a background job that runs about every 15 minutes. The first attempt lands within about 15 minutes of the event, not the instant it happens. A failed delivery is tried again after at least the wait below, counted from the attempt before, on the job's next run after that:

| Attempt | Earliest |
| --- | --- |
| 1 | The next run, within about 15 minutes |
| 2 | 1 minute later (in practice, the next run) |
| 3 | 5 minutes later (in practice, the next run) |
| 4 | 30 minutes later |
| 5 | 2 hours later |
| 6 | 5 hours later |
| 7 | 10 hours later |
| 8 and on | Every 12 hours |

AppliFlo stops 3 days after the first attempt and marks that delivery as given up. A retry is the same event: same `webhook-id`, same body, a new `webhook-timestamp` and signature.

**Retry** in the delivery log and **Send test event** don't wait for the job: they try straight away.

## Duplicates and order

- **Duplicates.** The same event can reach you more than once, for example when your server did the work but answered too late. Keep the `webhook-id` of each event you have handled and skip one you have already seen.
- **Order is not guaranteed.** Events can arrive out of order, especially after a retry. Don't assume `envelope.signed` arrives before `envelope.completed`. Use `created_at` and the `status` in `data`, or [get the envelope](https://dev.appliflo.com/api/envelopes/get-envelope) for its current state before you act.

## When an endpoint keeps failing

If every delivery to an endpoint fails for 3 days, AppliFlo turns the endpoint off and emails the workspace owners once. Settings shows it as disabled, with the reason.

You can also turn an endpoint off yourself. Deliveries already queued for it wait, and go out when you turn it back on; one whose event is more than 3 days old gives up after its next failed attempt. Events that happen while an endpoint is off are not queued for it. When your server is fixed, turn the endpoint back on in Settings, then [list envelopes](https://dev.appliflo.com/guides/track-envelopes#list-envelopes) to catch up on what changed meanwhile.

## Delivery log

Each endpoint's **Delivery log** shows every delivery from the last 30 days: the event, the time, your server's status code, the number of attempts, the request body as sent and the start of your server's reply. Bodies in the log are cut to about 4 KB. Filter by **Failed** to see what needs attention.

## Rotate the secret

In the delivery log, click **Rotate secret**. The new secret is shown once, and starts with `whsec_` like the first. The old one keeps signing alongside the new one for 24 hours: in that time every request carries two signatures, `v1,<new> v1,<old>`, so a server with either secret accepts it. Put the new secret on your server within the 24 hours. The verifiers above accept either signature, so there is nothing else to change.

## Network and security

- Endpoint URLs must use `https://` on port 443. Other ports are refused.
- AppliFlo won't send to private, loopback or link-local addresses, and doesn't follow redirects. It checks the URL when you save it and looks up your host's address again before every attempt, so a name that later points at a private address is refused too.
- Requests don't come from fixed IP addresses, so don't rely on an IP allowlist. Check the signature instead.
- Keep the secret on your server. Anyone with it can sign requests your server will accept. If it leaks, rotate it.

## Test your endpoint

1. Click **Send test event** in the endpoint's delivery log. AppliFlo sends a signed `webhook.test` event straight away.
2. Check the log. A `2xx` means your URL and your signature check both work.
3. For real events, send yourself an envelope and sign it. You get `envelope.sent`, `envelope.viewed`, `envelope.signed` and `envelope.completed`.

To work on your own machine, expose your local server through an HTTPS tunnel and add the tunnel's URL as an endpoint. Remove the endpoint when you are done.
