Retry requests safely
How-to guide2 min read
If a request times out, you can't tell whether Notriv received it. Retrying could send the document twice. An Idempotency-Key header prevents that: send the same key again and you get the first response back, with nothing done twice.
How to use it
Pick a unique value per action (a UUID, or your own ID such as the deal ID) and send it with every POST:
// The library adds a key automatically and retries for you.
// Pass your own to make retries safe across restarts:
await notriv.envelopes.create(params, { idempotencyKey: `deal-${deal.id}-agreement` })Rules
- A replayed response has the header
Idempotent-Replayed: true. - Keys last 24 hours.
- Reusing a key with a different request body fails with
idempotency_key_reused. - If the first request is still running, you get
409. Wait a moment and retry. - Server errors (5xx) are not stored, so retrying with the same key does the work.
Tip
Retry on network errors,
429 and 5xx, waiting a little longer each time. Don't retry other 4xx errors: fix the request instead.Next steps
Was this page helpful?