Idempotency
A program that did not receive the response to a POST — the network dropped — cannot know whether the job started. With an Idempotency-Key it can retry safely: the second request receives the response of the first instead of creating a second object.
POST /v1/jobs
Authorization: Bearer vc_…
Idempotency-Key: 6f1c2a9e-order-4411
Content-Type: application/json
Rules
- The header is optional. Without it the request is executed as it is.
- It is accepted by every
POSTthat creates something. - The key is 1 to 255 printable ASCII characters, without spaces. A UUID, or an identifier of your own (an order number, the id of your job), works well.
- The key is remembered for 24 hours, per customer: the same key used by two customers is two different requests.
- The response repeated for a retry carries the header
Idempotent-Replayed: true. - Responses with a status below
500are remembered, errors such as400included: a request that was wrong the first time is still wrong. A500, or a failure of the service, is forgotten: retry with the same key.
Errors
| Status | Code | Meaning |
|---|---|---|
400 | idempotency_key_invalid | The key is empty, too long, or not printable ASCII. |
409 | idempotency_in_progress | The first request with this key is still running. Retry shortly. |
422 | idempotency_key_reused | The key was already used for a different request (another body or another address). Repeating is not changing one's mind: use a new key. |
A retry loop
1. Choose the key before the first attempt, and keep it for every retry of the same operation. 2. On a network failure, a 500 or a 409 idempotency_in_progress, wait and send the same request again with the same key. 3. On any other response, stop: that is the answer.