Safe retries
If a call times out you can't tell whether it worked. An Idempotency-Key lets you send it again safely.
Idempotency-Key
Send an Idempotency-Key header on every POST, with a value that's unique to that change, such as your order number. Then, if a call times out and you don't know whether it worked, send exactly the same call again with the same Idempotency-Key. What happens next depends on how the first call went.
- The first call worked. Nothing is changed a second time. You get the first call's reply back, with the header
Idempotent-Replayed: true. This works for 24 hours. - The first call came back with an error, such as
validation_failed. Nothing was changed and we didn't keep the Idempotency-Key, so it's free to use again. Fix the request and send it with the same value. - You send a different call with an Idempotency-Key that already worked once. Nothing is changed, and you get a
conflicterror. Each change needs its own value.
Idempotency-Keys belong to your API key, so the same value sent with a different API key counts as a new one.
curl -X POST https://api.additem.to/api/v1/inventories/{inventory_id}/items \
-H "Authorization: Bearer $ADDITEM_KEY" \
-H "Idempotency-Key: order-1042-line-1" \
-H "Content-Type: application/json" \
-d '{"name": "Cordless drill", "location_path": "Garage > Shelf 2"}'
Every endpoint that takes one says so on its reference page.