Idempotency-Key header:
When to use one
Every endpoint accepts the header, but it matters most for requests that would do something twice if repeated:- sending an email or SMS message, such as
POST /email_templates/:id/send - tracking an event with
POST /businesses/:id/track. Each tracked event starts every trigger that matches it, so a duplicate event sends the trigger’s messages again. - creating records with the endpoints that don’t match on your own identifier, such as
POST /businesses/:id/customers
external_id.
How a key behaves
- The first request runs. When it finishes, Pocketflows stores the response. That includes a partially successful customer batch.
- A repeat returns the stored response. Any later request with the same key, method, path and parameters gets the same status and body back, without running again.
- Some errors are stored too. Errors that stop the request before or while it runs, such as a
400for invalid parameters, a404, a429or a5xx, aren’t stored, so retrying with the same key runs the request again. But a422that an endpoint returns after checking your data can be stored, and then every retry with that key gets the same422. After fixing the request, send it with a new key: the key is tied to the method, path and parameters it was first used with anyway. - A mismatch is rejected. A request that reuses a key with a different method, path or parameters
returns
409with an empty body. - A request in progress is protected. While the first request with a key is still running, another
request with that key returns
409with an empty body. Wait, then retry.