Guides
Webhooks
Uploads and verifications finish in the background. Instead of polling, register an endpoint and ExportFlow will send it a signed request when something happens.
Registering an endpoint#
An endpoint is an https URL on your side, registered against one application, with the list of events it wants. Register it in the console or through the API. An endpoint registered with no event types receives every event.
endpoint = client.webhook_endpoints.create(
"https://erp.example.com/hooks/exportflow",
event_types=["document.processing.completed", "verification.completed"],
)
print(endpoint.signing_secret) # whsec_... store thisRegistering returns the endpoint’s signing secret, which begins whsec_. Store it as you would an API key. An owner can see it again, or replace it, in the console.
The URL must be reachable from the internet. A URL that is not https, that carries a user name or password, or that points at a private or loopback address is refused with invalid_webhook_url, and the address is checked again each time an event is delivered. Redirects are not followed.
Events#
An event about a document or a verification is sent to the endpoints of the application that created the shipment. An account-level event, such as an invoice, is sent to every endpoint of the organisation that subscribes to it.
| Event | When it is sent | What data holds |
|---|---|---|
document.uploaded | A document was accepted, scanned and stored. | document.id, shipment.id, status, document_type |
document.processing.started | Classification began. | document.id, shipment.id, status, document_type |
document.processing.completed | The document was classified and read. Fetch its extraction. | document.id, shipment.id, status, document_type, pages, fields_read |
document.processing.failed | Processing stopped. Fetch the document for the reason. | document.id, shipment.id, status, document_type, stage |
verification.completed | A verification finished. Fetch it for the findings. | verification.id, shipment.id, status, findings (a count for each severity) |
verification.failed | A verification could not run. Fetch it for the reason. | verification.id, shipment.id, status |
usage.threshold.reached | The account reached 80% or 100% of a monthly allowance. Sent once for each threshold in a period. | organisation.id, meter, environment, threshold_percent, used, limit, period, resets_at |
billing.invoice.generated | An invoice was issued to your organisation. | invoice.id, number, period_start, period_end, currency, total_micro |
One more event exists, webhook.test. It is sent only when you press Send test event in the console, and only to that one endpoint. It is signed and delivered exactly as a real event is, so it exercises your verification code. It reaches the endpoint whichever event types the endpoint subscribes to.
An event tells you what happened and to what. It never contains document content or extracted values. Fetch the document, the extraction or the verification with your API key to read it. New fields can be added to data within version 1, so ignore the ones you do not use.
The payload#
Every delivery is a POST with a JSON body in the same envelope. Only type and data differ between events.
{
"id": "<event id>",
"type": "document.processing.completed",
"created_at": "2026-11-11T09:30:00Z",
"api_version": "1.1",
"environment": "sandbox",
"application_id": "<application id>",
"data": {
"document": { "id": "<document id>" },
"shipment": { "id": "<shipment id>" },
"status": "processed",
"document_type": "bill_of_lading"
}
}| Field | Meaning |
|---|---|
id | The event's identifier. The same on every delivery of this event. Use it to discard repeats. |
type | The event type. |
created_at | When the event happened, in UTC. |
api_version | The API version that produced the event. |
environment | sandbox or production. |
application_id | The application the event belongs to. Null for an account-level event. |
data | The subject's identifier under its own name, and the event's details. |
The request also carries three headers:
ExportFlow-Signature: t=<unix seconds>,v1=<hex HMAC-SHA256>
ExportFlow-Event: document.processing.completed
ExportFlow-Event-Id: <event id>Verifying the signature#
Verify every delivery before you trust it. The URL of an endpoint is not a secret, and anybody who learns it can post to it.
The ExportFlow-Signature header is t=<timestamp>,v1=<signature>. The signature is the HMAC-SHA256, in hexadecimal, of the timestamp, a full stop and the raw request body, keyed with the endpoint’s signing secret:
- Split the header on commas and read
tand everyv1. There can be more than onev1, for example while a secret is being rotated: the delivery is genuine if any one of them matches. The SDKs (1.1 and later) do this. - Refuse the delivery if
tis more than 5 minutes from your own clock. This stops a captured delivery being replayed later. - Compute HMAC-SHA256 over
"<t>.<raw body>"with the signing secret as the key. - Compare the result with
v1using a constant-time comparison.
Both SDKs do this in one call. The last two tabs show it with nothing but a standard library.
from exportflow import webhooks, SignatureVerificationError
def handle(request):
try:
event = webhooks.construct_event(
payload=request.body, # raw bytes
signature=request.headers["ExportFlow-Signature"],
secret=WEBHOOK_SECRET,
)
except SignatureVerificationError:
return 400
if already_handled(event.id): # deliveries are at-least-once
return 200
if event.type == "document.processing.completed":
document_id = event.data["document"]["id"]
...
return 200The signature is over the exact bytes ExportFlow sent. If your framework parses the JSON and you serialise it again, the bytes will differ and the signature will not verify. Read the raw body first, verify it, then parse it.
Delivery, retries and duplicates#
Answer with any 2xx status within 10 seconds. Do the real work after you have answered: put the event on a queue of your own and return.
Anything else (another status, a timeout, a connection failure) is retried with increasing delays, starting at a few seconds and doubling up to an hour, for about two and a half hours in total. After that the delivery is marked failed. The event itself is kept, and every attempt is shown in the console.
Delivery is at least once. If your endpoint did the work but answered too slowly, the same event arrives again with the same id. Record the ids you have handled and answer 2xx to a repeat without doing the work twice. Events can also arrive out of order; use the resource’s own status as the truth, not the order of arrival.
An endpoint that fails 20 deliveries in a row is disabled automatically, and the console says why. Fix the endpoint and enable it again in the console; one successful delivery resets the count.
Testing an endpoint#
In the console, open Webhooks, choose an endpoint and press Send test event. A signed webhook.test event is queued for that endpoint, and its outcome appears in the endpoint’s deliveries with the status your server answered, the number of attempts and any error.
Rotating the signing secret takes effect at once, with no overlap. Give your receiver the new secret straight away. A delivery it refuses in between is retried, and each attempt is signed afresh with the current secret and the current time.