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

# Webhooks

> Register an endpoint, the event catalog, signatures, retries and ordering.

Webhooks tell you when the DIAN answered, so you do not have to poll. Register an endpoint
with `POST /v1/tenant/webhooks` or on the console's **Webhooks** page, which also lists the
latest deliveries. The [quickstart](https://docs.cufea.com/en/quickstart.md#2-register-a-webhook-endpoint) walks
through it.

* The endpoint must be an `https` URL on a public host name: `localhost` and private addresses
  are refused.
* An empty `event_types` subscribes to every type.
* The endpoint's signing `secret` is shown **once**, in the create answer.

## Deliveries

Each delivery is a JSON `POST` of `{"id", "type", "created_at", "data"}`, with
`X-Cufea-Signature`, `X-Cufea-Delivery` and `X-Cufea-Event` headers.

* **Signature.** `X-Cufea-Signature: t=<unix seconds>,v1=<hex>`. `v1` is the hex HMAC-SHA256
  of `t`, a `.` and the **raw request body** (`"<t>.<raw body>"`), keyed with the endpoint's
  secret. Reject a `t` more than **300 seconds** away from your clock, either way. Accept the
  request when any `v1` matches. The [quickstart](https://docs.cufea.com/en/quickstart.md#5-verify-the-webhook-signature)
  has complete Python and Node.js verifiers.
* **Answer fast.** Answer any `2xx` within **10 seconds**; do the work after answering.
* **Retries.** No answer, `408`, `429` or `5xx` is retried after **1 min, 5 min, 30 min, 2 h
  and 6 h** (six attempts in all); any other status fails the delivery at once. Each retry is
  signed again with a fresh `t`.
* **Deduplicate by event `id`.** The body's `id` identifies the event, the same on every
  retry; `X-Cufea-Delivery` identifies the delivery. A delivery can arrive more than once.
* **No ordering guarantee.** A retried delivery can arrive after a later event, and deliveries
  are sent in parallel. Do not infer the order of events from their arrival: read the
  document (`GET /v1/invoices/{document_id}`) for its current state.

The payload carries ids and DIAN codes only (and your `reference`), never customer data.
Besides the DIAN outcomes (`invoice.accepted`, `invoice.rejected`, `note.accepted`,
`note.rejected`, `event.registered`), the buyer email emits `invoice.delivered`,
`invoice.delivery_failed`, `note.delivered` and `note.delivery_failed` (`state` `sent` or
`failed`, and a `reason` when it failed). An endpoint registered with no `event_types`
receives every type, these included.


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