Idempotency
Retry a send safely without notifying anyone twice.
Networks fail after a request has already arrived. Send an Idempotency-Key header with POST /v1/notifications and a retry of the same request never notifies anyone twice. The key is any string of 1 to 255 characters; use something tied to the event, like an order id.
⫻
curl
What Push does with the key#
| Situation | Response |
|---|---|
| First accepted request with this key | 202 Accepted. The notification is sent and the key is stored with it. |
| Same key, same body | 200 OK with the original id, status, attempts and mode. Nothing new is sent or charged. |
| Same key, different body | 409 IDEMPOTENCY_CONFLICT. Nothing is sent. |
| Same key while the first request is still running | The second request waits for the first to finish. If the first was accepted, the second gets its 200 OK replay, or 409 IDEMPOTENCY_CONFLICT if the body differs. If the first failed, the second is handled as a new request. |
| Key shorter than 1 or longer than 255 characters | 400 VALIDATION_ERROR. |
A replayed response looks like this:
⫻
200 OK
What counts as the same body#
Push compares the validated request, after defaults are filled in. Key order, whitespace and spelling out a default (for example "urgency": "normal") do not make a body different. Changing any value does.
Scope and lifetime#
- Keys belong to the project, not to the API key: every key of a project, live or test, shares the same keys.
- Only an accepted send stores the key. A request that failed with
400,402,422or429did not use it up, so you can fix the cause and retry with the same key. - A key is remembered for as long as its notification exists, which is up to 90 days.
500 INTERNAL_ERROR response says it in its message: try again with the same Idempotency-Key. If the first request did go through, the retry gets the original response instead of a second notification.A safe retry loop#
Retry network errors, 429 and 5xx with the same key, and wait for Retry-After on 429. Do not retry other 4xx blindly: the request itself is wrong and will fail the same way. A 409 means the key was already used with a different body: a bug to fix, not something to retry.
⫻
JavaScript