HomeGuidesAPI ReferenceChangelog
Terms of Use
API Reference

Idempotency

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-Key with 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.
  • DELETE requests and the /public-api/oauth/token and /public-api/oauth/revoke endpoints ignore the header.

Responses to a repeated key

SituationResponseWhat your client should do
The first request succeeded409 Conflict, errorCode idempotency_key_already_processed, header Idempotent-Replayed: trueDo 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 running409 Conflict, errorCode idempotency_key_in_progress, header Retry-AfterRetry after the number of seconds in Retry-After.
The key was already used with a different method, path, query string or body422 Unprocessable Entity, errorCode idempotency_key_payload_mismatchSend the new operation with a new key.
The key is longer than 255 characters422 Unprocessable Entity, errorCode idempotency_key_too_longUse 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 Accepted

The 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"
}