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

# Webhooks

> Receive a notice from QX when the reading of a document ends.

With a webhook, QX notifies your system when the reading of a document ends. Your system does not need to poll the API.

## Register the URL

The owner of the organization registers the URL in **Settings › Webhooks**:

1. Enter an HTTPS URL of your system.
2. Check the event `document.reading.finished`.
3. Copy the secret that the screen shows. The screen shows the secret only once.

The registration needs a paid plan, like the API keys. On the free plan, QX sends no notices.

An organization registers up to 5 URLs. On the same screen, the owner:

* pauses, resumes and removes the URL;
* rotates the secret;
* sees the last 50 deliveries of each URL, with the attempts of each one.

The registration refuses:

* a URL without HTTPS;
* a URL with a user and a password;
* an internal IP address.

A URL with a domain name passes the registration. At each send, QX resolves the name and refuses the delivery when the address is internal.

## The notice

QX sends a `POST` to the URL, with a JSON body:

```json theme={null}
{
  "id": "evt_8812",
  "type": "document.reading.finished",
  "version": 1,
  "occurred_at": "2026-09-25T13:33:20.000Z",
  "data": {
    "document_id": "doc_318",
    "collection_id": "col_40",
    "external_id": "CAMBIO-2026-0042",
    "reading": { "state": "complete", "finished_at": "2026-09-25T13:33:20.000Z" },
    "resource_url": "/api/v1/documents/doc_318"
  }
}
```

* `id` identifies the event. The same notice can arrive more than once with the same `id`.
* `data.reading.state` is `complete`, `failed` or `no_reader`.
* `data.external_id` is the external id of the upload, or `null`.
* The notice carries the ids, the state and the time of the reading, and the path of the document. For the fields, call `GET /documents/{id}` with the API key.
* The event tells that the reading ended. The validations of the collection can run after the notice.
* A document of a type with no automatic reading sends no notice, because its reading does not start.

The `POST` carries these headers:

| Header | Value |
| - | - |
| `Content-Type` | `application/json` |
| `X-QX-Event-Id` | The `id` of the event. |
| `X-QX-Event-Type` | The type of the event. |
| `X-QX-Signature` | `t=<unix>,v1=<hex>`: the time of the send and the signature. |

## Check the signature

The signature is the HMAC-SHA256 of a text, with the secret of the URL. The text is `t`, a dot and the exact body of the `POST`. Check the signature before you read the body:

1. Split `t` and `v1` from the `X-QX-Signature` header.
2. Refuse the notice when `t` is more than 5 minutes away from your clock.
3. Compute the HMAC-SHA256 of `"#{t}.#{body}"` with the secret.
4. Compare the result with `v1` in a constant-time comparison.

```ruby theme={null}
timestamp, signature = header.split(",").to_h { _1.split("=", 2) }.values_at("t", "v1")
expected = OpenSSL::HMAC.hexdigest("SHA256", secret, "#{timestamp}.#{body}")
valid = (Time.now.to_i - timestamp.to_i).abs <= 300 && ActiveSupport::SecurityUtils.secure_compare(expected, signature)
```

Use the body as it arrived, before any parsing. A reformatted JSON changes the signature.

## Answer and handle repeats

* Answer with any `2xx` status to confirm the delivery. QX ignores the body of the answer.
* QX waits 5 seconds to connect and 10 seconds for the answer. Answer at once and process the notice later.
* QX does not follow a redirect.
* The same notice can arrive more than once, and two notices can arrive out of order. Drop a repeated `id` and read the current state through the API.

## Retries

QX tries again when the delivery fails for one of these reasons:

* a network failure, or a name that does not resolve;
* a timeout;
* an answer `408`, `429` or `5xx`.

Each notice has up to 5 attempts:

| Attempt | When |
| - | - |
| 1 | Right after the end of the reading. |
| 2 | 1 minute after the first. |
| 3 | 10 minutes after the second. |
| 4 | 1 hour after the third. |
| 5 | 6 hours after the fourth. |

The other answers outside `2xx` end the delivery with no retry: a `4xx` other than `408` and `429`, and a redirect. The fifth failure also ends the delivery.

QX does not send an ended delivery again. To find an end of a reading that did not arrive, call the API from time to time, for example with `GET /documents?external_id=`.

A paused URL keeps the deliveries in the queue. The resume puts the due deliveries in the send queue. A removed URL cancels the queued deliveries.

## Rotate the secret

The new secret works at once: the next notice goes out with the new secret. During the rotation, follow this order:

1. Pause the URL.
2. Rotate the secret.
3. Update the secret in your system.
4. Resume the URL. QX puts the due deliveries in the send queue, with the new secret.

A delivery that started before the pause can arrive signed with the old secret.


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