Skip to main content

Retrying writes

Learn how to retry a write without creating it twice.


Idempotency keys​

A write that times out or loses its connection may still have happened. Send an Idempotency-Key header so you can retry it without creating it twice. These endpoints accept one:

  • POST /exports
  • POST /search-term-reports
  • POST /search-term-reports/{report_id}/run
note

Only api.onna.com honors the header. Other API addresses ignore it, so a retry there can still write twice.

Use a new unique value, such as a UUID, for each new request. When you retry, send the same key with the exact same body: keep the request you sent and resend it unchanged, since rebuilding the JSON can change its bytes. A repeat within 24 hours returns the first response instead of writing again:

POST /exports HTTP/1.1
Authorization: Bearer <token>
Idempotency-Key: "8e03978e-40d5-43e8-bc93-6894a57f9324"
Content-Type: application/json

Keys belong to the user and account that sent them. A key is 1 to 255 visible ASCII characters with no spaces, quotes or backslashes, and may be wrapped in double quotes. A key outside that format answers 422 before anything runs.

Responses to a repeated key​

  • The same key and the same body: the first response, with the same status, body and Location header.
  • 409, title Request in progress: the first request is still running. Keep retrying with the same key and back off; this can last up to 10 minutes.
  • 422, title Idempotency key reused: the key was sent with a different request. If you meant to retry, resend the original body unchanged. Use a new key only for a new request.
  • 422, title Outcome unknown: the first request failed after it may have written, was refused with an error that names something it created, or never answered within 10 minutes. Check whether the write took effect, or delete what its error named, before sending it again with a new key.

A request refused with a 4xx, or one whose error says nothing was created, frees its key, so you can retry it with the same key. A 4xx whose error names something it created, such as an export it couldn't start, keeps its key: treat it like Outcome unknown.