Idempotency
Make retries safe with the Idempotency-Key header.
A network can drop your request or its answer. If you repeat a call that changes data, you want it to run once, not twice. The Idempotency-Key header gives you that.
How to use it#
Send a unique value, such as a UUID, in the Idempotency-Key header on a POST, PATCH or DELETE. If you retry, send the same key and the same request.
curl -X POST https://api.seemly.com/v1/lists \
-H "Authorization: Bearer $SEEMLY_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: $(uuidgen)" \
-d '{"name": "Launch readers"}'const response = await fetch("https://api.seemly.com/v1/lists", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.SEEMLY_API_KEY}`,
"Content-Type": "application/json",
"Idempotency-Key": crypto.randomUUID(),
},
body: JSON.stringify({
"name": "Launch readers"
}),
});
const result = await response.json();
console.log(response.status, result);import os
import uuid
import requests
response = requests.post(
"https://api.seemly.com/v1/lists",
headers={
"Authorization": f"Bearer {os.environ['SEEMLY_API_KEY']}",
"Idempotency-Key": str(uuid.uuid4()),
},
json={
"name": "Launch readers",
},
)
print(response.status_code, response.json())Which operations need it#
- Required on bulk, import and send operations (
bulk_upsert_subscribers,bulk_update_subscribers,create_import,request_send). Without the header the answer isidempotency_key_required. - Supported on every other operation that creates or changes something. Each operation page says which.
- Not needed on the read-style POSTs, which change nothing:
estimate_audience,render_design,render_mailing,preview_sendandfind_subscriber_by_email. Send a key on any POST that creates or changes data. - Reads and operations that are naturally repeatable (such as
unsubscribe_subscriberandadd_subscriber_tags) give the same result when you repeat them, with or without a key.
What happens on a retry#
| Situation | Answer |
|---|---|
| Same key, same request, the first call finished | The stored answer, with the header Idempotent-Replay: true. Nothing runs again. |
| Same key, the first call is still running | 409 request_in_progress with Retry-After. Wait and repeat. |
| Same key, a different request | 409 idempotency_key_reused. Use a new key for a new request. |
| The first call failed with a 5xx | Not stored. Repeating runs the request again. |
Details#
- A key is remembered for 24 hours and belongs to the credential that used it. Another key cannot see or reuse it.
- Two requests are the same when the method, path, query and body match; the order of JSON fields does not matter.
- An answer that contains a secret shown only once (a webhook signing secret) is never stored for replay, so a replay cannot expose it. Keep the secret from the first answer.
- A dry run (
dry_run=true) never consumes a key. - Use a fresh key per logical action, not one key for a whole script.