Skip to main content
An idempotency key lets you retry a request without it happening twice. Send it in the Idempotency-Key header:
Generate one key for each operation you want to happen once, for example a UUID created when you queue the job, and send the same key on every retry of that operation.

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
The sync endpoints are already safe to repeat, because they match records by 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 400 for invalid parameters, a 404, a 429 or a 5xx, aren’t stored, so retrying with the same key runs the request again. But a 422 that an endpoint returns after checking your data can be stored, and then every retry with that key gets the same 422. 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 409 with 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 409 with an empty body. Wait, then retry.
Keys are scoped to a project, and test and live mode are separate projects, so a key used in test mode can be used again in live mode. Keys don’t expire.