Guides
Idempotency
An integration that times out cannot tell a lost request from a lost reply. With an Idempotency-Key it doesn't have to: send the same call again and nothing happens twice.
Sending a key
Add an Idempotency-Key header to any POST, PUT, PATCH or DELETE. The first request with that key runs; every repeat gets the first request's answer back instead of running again. A second upload of the same file, or a second approval, never happens.
curl -X POST "https://docuflow.pendral.io/api/v2/documents/{documentId}/approve" \-H "Authorization: Bearer $DOCUFLOW_API_KEY" \-H "Content-Type: application/json" \-H "Idempotency-Key: approve-clx9k2m4p0001qh8z3v7d5f2a" \-d '{}'
The rules
- The key
- Up to 255 characters. Derive it from the thing you are doing (a document id, a job id) so a rerun of the same job sends the same key.
- Scope
- A key belongs to the credential that sent it, the method and the path. Two integrations choosing the same string, or one key reused on two endpoints, never collide.
- Replays
- A repeat gets the stored status and body, with an
Idempotent-Replay: trueheader so you can tell it apart from a fresh run.Kept for 24 hours. - What is not stored
5xxand429responses. The failure was about the moment, not the request, so the key is released and a retry with it runs for real. Every other answer, refusals included, is what a retry sees again.- Uploads
- JSON bodies are compared by content. A multipart upload is recognised by its size and media type instead of its bytes, so the same file retried with the same key is the same request.
When the key is refused
- 409conflict
- The first request with this key is still running.Wait a moment and send it again.
- 422idempotency_conflict
- The key was already used with a different request body.A bug in the caller: use a new key per distinct request.
When the store is unavailable
If the idempotency store cannot be reached the request is served rather than refused: the header is a promise not to duplicate, not a precondition for the call.
The SDK does this for you
The TypeScript SDK sends a key on every write and reuses it across its own retries. Pass
idempotencyKey to keep the same key across yours.