Safely retry POST, PUT and PATCH requests without running them twice
A network error or a timeout does not tell your client whether the platform received the request. If the client retries, the platform may process the same operation twice: for example, credit a driver's wallet twice. The Idempotency-Key header lets you retry safely: the platform runs an operation only once per key.
Available since version 3.269.0. Requests without the header behave as before.
When to use it
Send an Idempotency-Key with any POST, PUT or PATCH request that must not run twice when your client retries it after a timeout or a network error, for example:
- wallet top-ups (
add-balance) - creating transactions
- starting charging sessions
How to send it
- Send the header
Idempotency-Keywith a value of up to 255 characters. A UUID is recommended. - Generate a new key for each operation, and send the same key for every retry of that operation.
- A key is remembered for 1 hour after its request succeeds.
- Keys belong to the API key that sent them. OAuth access tokens and impersonated calls share the keys of their API key.
- A failed request (any non-2xx response) releases its key, so you can retry it with the same key.
DELETErequests and the/public-api/oauth/tokenand/public-api/oauth/revokeendpoints ignore the header.
Responses to a repeated key
| Situation | Response | What your client should do |
|---|---|---|
| The first request succeeded | 409 Conflict, errorCode idempotency_key_already_processed, header Idempotent-Replayed: true | Do not retry. Read the resource to get its current state: the response does not repeat the original body, so a replayed create does not return the new resource id. |
| The first request is still running | 409 Conflict, errorCode idempotency_key_in_progress, header Retry-After | Retry after the number of seconds in Retry-After. |
| The key was already used with a different method, path, query string or body | 422 Unprocessable Entity, errorCode idempotency_key_payload_mismatch | Send the new operation with a new key. |
| The key is longer than 255 characters | 422 Unprocessable Entity, errorCode idempotency_key_too_long | Use a shorter key. |
Example: wallet top-up
The first request credits the wallet:
curl -X POST "https://{your-domain}/public-api/actions/users/v1.0/{id}/add-balance" \
-H "Authorization: Bearer {token}" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: 3f9c2a7e-6b1d-4c8e-9a52-1d0e7b4f8c31" \
-d '{ ... }'HTTP/1.1 202 AcceptedThe client times out and sends the same request again with the same key. The platform does not credit the wallet a second time:
HTTP/1.1 409 Conflict
Content-Type: application/json
Idempotent-Replayed: true
{
"errorCode": "idempotency_key_already_processed"
}