Skip to main content

Idempotent requests in the REST Admin API

Legacy

The REST Admin API is a legacy API as of October 1, 2024. All apps and integrations should be built with the GraphQL Admin API. For details and migration steps, visit our migration guide.

The REST Admin API supports idempotency, which allows you to safely retry API requests that might have failed due to connection issues, without causing duplication or conflicts.


Anchor to What is an idempotency key?What is an idempotency key?

An idempotency key (unique_token) is a unique string identifier generated by your app. Shopify uses this identifier to recognize subsequent retries of the same request.


Anchor to How idempotent requests workHow idempotent requests work

If an API request is disrupted in transit, then you might not receive a response. By including an idempotency key in your request, repeated requests with the same parameters will be executed only once, no matter how many times the request is retried.

For example, you might be using the REST Admin API's Payment resource to process a payment in Shopify. If you don't receive a response due to a network connection error, then you can retry the request with the same unique_token to guarantee that only one payment is processed:

POST /admin/checkouts/#{token}/payments.json HTTP/1.1
Host: shop-name.myshopify.com
Content-Type: application/json
X-Shopify-Access-Token: #{shopify_access_token}

{
"payment": {
"request_details": {
"ip_address": "123.1.1.1",
"accept_language": "en-US,en;q=0.8,fr;q=0.6",
"user_agent": "Mozilla\/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/54.0.2840.98 Safari\/537.36"
},
"amount": "1675.99",
"session_id": #{id},
"unique_token": "client-side-idempotency-key"
}
}
Tip

You can use any unique identifier for your idempotency key, but we recommend using a randomly generated universally unique identifier (UUID) to avoid collisions.


Anchor to Requests that accept idempotency keysRequests that accept idempotency keys

POST requests that process credit card payments, create billing attempts for subscriptions, or capture revenue details accept idempotency keys. GET and DELETE requests are idempotent by definition, and don't require you to send an idempotency key as part of the request.


Was this page helpful?