POST creates a duplicate item or sends the same alert twice, charging twice. The Idempotency-Key header solves this.
Where to use it
On two routes, and only on them:POST /establishments/{establishment}/itemsPOST /establishments/{establishment}/items/{item}/events
How to use it
Generate a unique value for each operation you intend to perform (a UUID v4 will do) and send it inIdempotency-Key. The value has 1 to 255 visible ASCII characters. On a network failure, repeat the request with the same key and the same body.
What happens
- The first response is stored for 24 hours: a success (2xx) as much as a business-rule refusal, that is, any error with its own
code, such asinsufficient_credits,dispatch_in_progressordispatch_too_soon. - A repetition with the same key and the same body gets the stored response, byte for byte, with the header
Idempotent-Replayed: trueand the originalContent-Language. Nothing is processed again and nothing is charged again. - A stored refusal is not retried. To try again for real (for example, after buying credits), send a new key.
validation_failed,forbiddenand server errors (5xx) are not stored: fix and repeat, with the same key if you like.- A replay counts towards the rate limit (see Conventions).
Storing business-rule refusals too differs from some payment APIs, which only store successes. Here, a refusal such as
dispatch_too_soon repeated with the same key stays refused even after the seconds have passed: use a new key.