Guides

Webhooks

Subscribe a URL to document events and DocuFlow POSTs a signed JSON envelope to it as each one happens, instead of you polling for them.

Subscribing

Create a webhook with the events it wants, or ["*"] for all of them, and optionally a queueId to hear about one queue only. The URL must be https. The response carries the signing secret once; store it, and rotate it with POST /api/v2/webhooks/{id}/rotate-secret.

curl -X POST "https://docuflow.pendral.io/api/v2/webhooks" \
-H "Authorization: Bearer $DOCUFLOW_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "Accounts payable",
"url": "https://hooks.example.com/docuflow",
"events": ["document.needs_review", "document.approved"]
}'

POST /api/v2/webhooks/{id}/test sends a sample delivery so you can build the handler before real documents arrive. The full set of webhook endpoints is in the reference.

Events

10 events
document.received
A document was uploaded or pulled from a source.
document.processing
Processing started.
document.extracted
Extraction finished (data available, may still need review).Carries the extracted fields.
document.needs_review
The document is waiting for a reviewer.Carries the extracted fields.
document.approved
A reviewer or automation approved the data.Carries the extracted fields.
document.rejected
A reviewer rejected the document.
document.exported
Approved data was delivered to a destination.Carries the extracted fields.
document.failed
Processing failed.
document.updated
An automation changed the document (moved it, retagged it, reassigned it).
document.deleted
The document was deleted.

GET /api/v2/events/types returns the same catalog, so an integration can render it instead of hard-coding a list.

What arrives

One POST per event, with Content-Type: application/json. data.fields is the extracted data as a plain nested object, present on the events marked above.

POST https://hooks.example.com/docuflow
{
"id": "evt_5f0c2a9b7d1e4c3a8b6f2d10",
"type": "document.approved",
"createdAt": "2026-10-01T12:00:00.000Z",
"workspaceId": "clx9k2m4p0000qh8z0a1b2c3d",
"data": {
"document": {
"id": "clx9k2m4p0001qh8z3v7d5f2a",
"name": "invoice-1042.pdf",
"queueId": "clx9k2m4p0003qh8zq7n2v4kx",
"queue": {
"id": "clx9k2m4p0003qh8zq7n2v4kx",
"name": "Invoices",
"slug": "invoices"
},
"status": "approved",
"documentType": "invoice",
"confidence": 0.96,
"pageCount": 2,
"source": "upload",
"createdAt": "2026-10-01T11:58:12.000Z",
"reviewedAt": "2026-10-01T12:00:00.000Z",
"exportedAt": null,
"tags": [
"urgent"
]
},
"fields": {
"invoiceNumber": "INV-1042",
"invoiceDate": "2026-09-28",
"total": 1240
},
"links": {
"app": "https://docuflow.pendral.io/documents/clx9k2m4p0001qh8z3v7d5f2a",
"api": "https://docuflow.pendral.io/api/v2/documents/clx9k2m4p0001qh8z3v7d5f2a"
}
}
}
X-DocuFlow-Event
The event type, e.g. document.approved.
X-DocuFlow-Delivery
The delivery id. A redelivery is a new delivery with a new id.
X-DocuFlow-Timestamp
Unix seconds when this attempt was signed.
X-DocuFlow-Signature
sha256= followed by the hex HMAC-SHA256 of <timestamp>.<raw body>, keyed with the webhook's secret.

Verifying the signature

  1. Read the raw body

    Sign the bytes you received, not JSON you parsed and re-serialized: re-serializing changes the bytes and breaks the signature.

  2. Recompute and compare

    HMAC-SHA256 over `${timestamp}.${rawBody}` with your secret, prefixed sha256=, compared in constant time.

  3. Reject stale deliveries

    Refuse a timestamp more than five minutes from your clock, so a captured delivery cannot be replayed later.

verify.ts
import { createHmac, timingSafeEqual } from "node:crypto";
export function verifyDocuFlow(rawBody: string, headers: Headers, secret: string): boolean {
const timestamp = headers.get("x-docuflow-timestamp") ?? "";
const signature = headers.get("x-docuflow-signature") ?? "";
const expected = "sha256=" + createHmac("sha256", secret).update(`${timestamp}.${rawBody}`).digest("hex");
const fresh = Math.abs(Date.now() / 1000 - Number(timestamp)) < 300;
return (
fresh &&
signature.length === expected.length &&
timingSafeEqual(Buffer.from(signature), Buffer.from(expected))
);
}

The TypeScript SDK does this for you in @pendral/docuflow/webhooks.

Delivery and retries

2xx within 15 s
Any 2xx acknowledges the delivery. Anything else, or no answer in 15 seconds, is a failure.
3 attempts
A failed delivery is retried, then marked failed. Every attempt is recorded under GET /api/v2/webhooks/{id}/deliveries with the status and the start of the body your endpoint returned.Exponential backoff, starting at 3 seconds.
Redeliver
POST …/deliveries/{deliveryId}/redeliver sends a delivery again. For anything older, replay the event from the event log, which keeps every event for 30 days whether or not a webhook was listening.
At least once
The same event can arrive more than once. Deduplicate on the envelope's id (evt_…), which stays the same across retries, redeliveries and replays.

Destinations are separate

A webhook destination posts the approved data when a document is exported. It is configured on a queue rather than subscribed to events, sends X-DocuFlow-Event: document.exported, and when it has a secret signs exactly the same way.