Zum Inhalt springen

Idempotency and concurrency

Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.

Two headers keep your integration safe when a network drops a connection or two systems edit the same resource: Idempotency-Key on creation and If-Match on updates. The API reference marks both as required on the operations that need them.

POST /v1/posts and POST /v1/webhook-subscriptions require an Idempotency-Key header. Use one new key (a UUID works) per logical operation and reuse it only to retry that same operation:

Terminal window
curl https://api.thesocialmediapp.com/v1/posts \
-H "Authorization: Bearer $TSMA_API_KEY" \
-H "Idempotency-Key: 6f1c2b0e-8d4a-4f7e-9a51-3c2d1e0f9b87" \
-H "Content-Type: application/json" \
-d @post.json
  1. Once the first request has finished and its answer is stored, a retry with the same key and the same body returns that stored answer with the header Idempotent-Replayed: true and creates nothing.
  2. A retry that arrives while the first request with the same key is still running is refused at once with 409 idempotency_in_progress, "retryable": true and a Retry-After header (seconds). Nothing runs and nothing is stored for it: wait that long, then retry with the same key.
  3. The same key with a different body is refused with 409 idempotency_conflict.
  4. If the key cannot be checked at that moment, the request is refused with 503 common_commit_failed (retryable, with Retry-After) and nothing runs: retry with the same key after the delay.
  5. A request without the header is refused with 400 idempotency_key_required; a key longer than 128 characters with 400 idempotency_key_length.

Rules worth knowing:

  • Two requests with the same key never run at the same time. The key is held from the moment a request arrives until its answer is stored (or until it fails), so a retry after a timeout gets 409 idempotency_in_progress while the first request runs, and the stored answer once it has finished with a 2xx, even when your client gave up waiting.
  • A workspace can run only a few creates at the same time. A further create while those run is refused with 429 common_rate_limited (retryable, with Retry-After) and nothing runs: retry it with the same key after the delay.
  • One rare case remains: if the server or its database fails at the instant between the end of the creation and the storing of its answer, a retry with the same key can run again. A client that must be certain reads back first (GET /v1/posts, or the list of webhook subscriptions) before it retries.
  • A key belongs to your organization and to the API key that sent it. The same key sent with another API key of the organization is 409 idempotency_conflict, never a replay of someone else’s response.
  • Only a successful answer (2xx) is stored. After an error, fix the request and send it again: with the same key if nothing was created, or with a new key for a new operation.
  • A stored answer is kept for 7 days. After that the key is free again, so do not rely on a key to deduplicate for longer.
  • A replayed POST /v1/webhook-subscriptions returns "secret": null: the signing secret is shown only on the original answer. If you lost it, rotate the secret (see Webhooks).

Changed 2026-11: a retry that arrives while the first request with the same key is still running is now refused with 409 idempotency_in_progress (retryable, with Retry-After) instead of running a second time. Two different errors share the 409 status on creation, so branch on code, not on the status alone: retry idempotency_in_progress with the same key after the delay, and never retry idempotency_conflict unchanged.

Resources that can change carry a version and an ETag header. Send the version back in If-Match when you change one; the API refuses the change if someone else changed the resource since you read it.

Terminal window
curl -X PATCH https://api.thesocialmediapp.com/v1/posts/3f2b8c1e-5d4a-4e7b-9c61-2a8f0d7e4b19 \
-H "Authorization: Bearer $TSMA_API_KEY" \
-H 'If-Match: "3"' \
-H "Content-Type: application/json" \
-d '{ "base_text": "Our winter menu is here." }'

If-Match accepts the version as 3, "3" or W/"3"; * is refused. It is required on:

Operation
PATCH /v1/posts/{id} Change a post
DELETE /v1/posts/{id} Delete a post
POST /v1/posts/{id}/reschedule Move a scheduled post
PATCH /v1/media/{id} Change a media file’s alt text
PATCH /v1/webhook-subscriptions/{id} Change a webhook subscription

Without the header the answer is 428 common_if_match_required; with a stale version it is 412 (for example post_version_mismatch). Read the resource again, apply your change to the fresh copy, then retry with its new version. A successful update answers with the new ETag.

Some operations take the version in the body instead of a header: scheduling and publishing a post take post_version (see Posts).