Idempotency keys
The Cint Exchange API uses idempotency keys to prevent accidental duplication of requests. The goal is to prevent accidental duplication of calls and prevent unintended consequences. In the example below, the idempotency key helps the system recognize that it's still the same request for the same project.
If a request fails and requires a retry, the retry must use the same idempotency key as the initial request to avoid collisions or race conditions.
Generally, on the Cint Exchange requests that create or modify objects will require an Idempotency-Key header.
Creating idempotency keys
The idempotency key should be a randomly-generated UUID unique to each request.
On macOS or Linux, you can use uuidgen to create a key, then include the key in the header of your request.
Example of creating a project with an idempotency key
IDEMPOTENCY_KEY=$(uuidgen)
curl -X POST 'https://api.cint.com/v1/projects' \
-H 'Authorization: Bearer <YOUR_API_KEY>' \
-H 'Content-Type: application/json' \
-H "Idempotency-Key: $IDEMPOTENCY_KEY" \
-d '{
"name": "New Market Research",
"country": "US"
}'
Requests that require an idempotency key
Requests that create an object, such as a project, target group, or report, require an Idempotency-Key header. This ensures that you get a single object, regardless of how many times you retry the request.
Further reading
For more information on the concept of idempotency in APIs, we recommend these industry-standard resources:
- Stripe: Idempotent Requests and their blog post on the topic
- Square: Idempotency