Start free
Docs · Idempotency

Developer docs

Guide: safe retries with Idempotency-Key

A network error after a POST leaves you not knowing whether Beplan acted. Send an Idempotency-Key and retry with the same key: you get the first answer back instead of a second post.

Read as Markdown

On this page
  1. How to use it
  2. What happens
  3. What it doesn't cover

How to use it

Any POST accepts an Idempotency-Key header: a value you make up, unique per intended action, 1 to 255 visible ASCII characters. A UUID is a good choice. The generated examples in this documentation send one on every operation that takes it.

curl -X POST "https://api.beplan.io/v1/organizations/ORGANIZATION_ID/workspaces/WORKSPACE_ID/posts/POST_ID/schedule" \
  -H "Authorization: Bearer beplan_pat_…" \
  -H "Idempotency-Key: 7d0c5c2e-1f3a-4b1e-9a51-2f8d6c4e0b17" \
  -H "Content-Type: application/json" \
  -d '{"scheduledAt": "2030-01-17T14:00:00.000Z"}'

Make the key when you decide to do the action, store it with the action, and send the same key on every retry of it. A new action gets a new key.

What happens

The key is remembered for 24 hours, per connection, together with a fingerprint of the request (the operation, the path with its query, and the exact body bytes).

Situation Answer
First time The request runs. Its answer is stored if it can be replayed (below)
Same key, same request, finished The stored status and body, with Idempotent-Replayed: true. Nothing runs again
Same key, same request, still running 409 CONFLICT with Retry-After: 1. Nothing runs
Same key, different request 409 IDEMPOTENCY_KEY_REUSED. Nothing runs
Key not 1–255 visible ASCII characters 400 VALIDATION_FAILED
Body over 1 MiB with a key 413 PAYLOAD_TOO_LARGE (the body is held to fingerprint it)

Access is checked every time, replays included: a replay from a token that was revoked meanwhile is refused like any other call.

What is stored

  • Stored and replayed: 2xx and 4xx answers with a JSON body, or a 204.
  • Never stored: 429, every 5xx, every 409 (they say "try again" or "someone else is editing"), and anything that isn't JSON. The key is released, so a retry with the same key runs again.
  • A request still marked as running after an hour (a server died mid-request) can be taken over by a retry.

Operations that never store their answer

Some answers carry signed upload URLs or a sign-in link, which must not be kept. These operations are marked x-beplan-idempotency: single-flight in the OpenAPI document and say so in the reference: POST …/media-library/uploads, POST …/media-library/raw-footage/uploads, POST …/media-library/items/{mediaId}/versions, POST …/media-library/items/{mediaId}/upload/parts, POST …/social-accounts/connect, the logo upload starts of organizations and workspaces, and a few others.

For them, the key only stops a second run from starting while the first runs (409 CONFLICT). Once the first finished, the same key runs again and returns fresh URLs.

What it doesn't cover

  • GET is safe to repeat anyway. PATCH, PUT and DELETE ignore the header. For edits, send baseUpdatedAt where the operation takes it: a stale one answers 409 POST_CHANGED_ELSEWHERE instead of overwriting.
  • Keys belong to a connection: two different tokens with the same key are two different requests.
  • After 24 hours a key is forgotten and the request runs again.