Guide
Idempotent Requests
Some of our API endpoints support idempotency - the ability to submit a request multiple times while guaranteeing that the request will only be processed once.
Idempotency is important in workflows such as order submission and payment processing where a network timeout can leave the application in an awkward position of not knowing the outcome of the request, but allowing the user to retry could result in duplicate orders or payments.
Where an endpoint supports idempotency, it will be specifically highlighted. Attempting to make an idempotent request against an endpoint that does not support it has no effect.
Making An Idempotent Request
To make an idempotent request send a unique value in the Idempotency-Key header. We recommend generating a v4 UUID.
When the request is received by the API the following preconditions are enforced:
- The HTTP verb is
POSTorPATCH - The request is associated with an authenticated entity
- The supplied
Idempotency-Keyis no more than 255 characters in length - If the
Idempotency-Keyhas been seen before for the same authenticated entity, HTTP method and request URI, the normalized request input is identical to the previous request
Failing to adhere to the above preconditions will result in the request being rejected and the API will treat the request as if it never happened.
Processing Idempotent Requests
If the above preconditions are met the API will attempt to return the previous successful response that matches the Idempotency-Key.
Immediately before sending the response, the API will set the Idempotent-Replayed: 1 response header to allow the client to determine if the request has previously been processed and it is receiving the "replayed" response.
If there is no matching (existing) response in the 2xx status range, the API will process the request normally and will not set the Idempotent-Replayed header.
Idempotency Key Validity
Unless an endpoint states otherwise, idempotency keys are tied to the authenticated entity, HTTP method and full request URI, and are valid for 24 hours after the first request is successfully processed. This allows multiple entities and endpoints to use the same key without the risk of collisions.
For endpoints using this standard validity window, sending a previously-used idempotency key after 24 hours will result in the request being processed again.
Loyalty balance top-up, redemption, revocation and reversal endpoints are an exception. A successful key remains associated with its loyalty balance operation for the lifetime of that operation. Never reuse a key for a different intended mutation, even after 24 hours.
A durable loyalty replay returns the original successful receipt and rechecks current merchant access. It does not repeat a mutation, audit or notification. After an uncertain response, retry the identical request with the same key or use the operation lookup endpoint. Keep all input fields identical when retrying with the same key, including fields the endpoint ignores. Changing them causes a conflict.