# Asynchronous rendering

> Request a PDF without waiting for the answer, then fetch it when it is ready, by webhook or by polling the API.

`POST /v1/render` returns the PDF in the same answer. It is the simplest way. Some tools cannot wait: a no-code tool, a job queue, a nightly batch. For them, `POST /v1/renders` answers at once and makes the PDF in the following seconds.

## Request the PDF

The body is the one of `POST /v1/render`, always as a PDF. Two optional fields are added:

- `reference`: your name for this document (order number, row of a sheet). It comes back with the result and names the file;
- `callback_url`: a public https address told when the PDF is ready.

```bash
curl -X POST https://api.mizanpage.com/v1/renders \
  -H "Authorization: Bearer mzp_…" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: order-C-2041" \
  -d '{"template": "invoice", "reference": "C-2041", "data": {"values": {"client.name": "Brasserie Orlanne SRL", "invoice.total": "€7,788.00"}}}'
```

The answer comes with status `202` and the render `queued`. Everything `POST /v1/render` refuses is refused here, at once: template not published, required field empty with `strict`, plan limit.

## Know when it is ready

Three ways, from the best to the simplest:

1. **A webhook** subscribed to `render.completed` and `render.failed`. See [Receiving webhooks](https://mizanpage.com/en/docs/webhooks/recevoir.md).
2. **`callback_url`**: the same message, sent to the call's address.
3. **Polling** `GET /v1/renders/{id}`, every 2 seconds at most.

| Status | Meaning |
| --- | --- |
| `queued` | Waiting |
| `processing` | Being rendered |
| `succeeded` | Ready: `download_url`, `expires_at`, `generation_id` |
| `failed` | Not made: `error.code` and `error.message`. Nothing is counted |

## Fetch the PDF

- `GET /v1/renders/{id}/pdf` with your key;
- or `download_url`, a link that needs no key.

Both work for **one hour**. Then the PDF is deleted and the answer is `410 render_expired`.

> **The link is an access**
>
> `download_url` opens the PDF without a key for one hour. Do not publish it and do not write it to a log.

## What is counted and what is kept

- The document is counted once, when it is made, as with `POST /v1/render`. With the same `Idempotency-Key`, a second call returns the render already requested.
- The data sent is kept encrypted while the render is made, then erased.
- The PDF is kept encrypted for one hour, then deleted.
- The render's record (status, ids, error) can be read for 24 hours.

> At most 100 renders waiting per workspace (`429 render_queue_full`). An editor session cannot request an asynchronous render.

---

Documentation Mizanpage · Developers › API
https://mizanpage.com/en/docs/api/rendu-asynchrone/
