Idempotency and recovery
The durable request contract for every Postkub mutation - Idempotency-Key, replays, revisions, and how to recover a lost response safely.
Updated
On this page
Every Postkub mutation requires a client-generated UUID in the Idempotency-Key header. The API stores each accepted mutation together with its result, so repeating the same request returns the original outcome instead of creating a duplicate post, publication, or reply.
The Idempotency-Key header
Generate one UUID per logical mutation before you send it, keep it until you know the final outcome, and reuse that exact value for every retry of the same mutation. The header is required on every mutation endpoint under /api/v1, including post create, update, delete, and archive, publish, schedule, cancel, and retry, thread updates, comment replies, and the owner administration endpoints for API keys and webhooks.
POST /api/v1/posts HTTP/1.1
Authorization: Bearer <API_KEY>
Idempotency-Key: 7f6b9d2a-4c1e-4a58-9d0f-2e7a1b3c4d5e
Content-Type: application/json
The value must be a valid UUID. A missing or malformed header fails with 400 VALIDATION_ERROR before anything executes. Scope strings, IDs, and limits are documented in the API reference; this page owns the request semantics that all of those endpoints share.
How replays work
The API binds your key to three things: the resource path, the operation, and a canonical hash of the payload. When you repeat a request with the same key and the same payload, the stored result is returned with the original status code - the mutation is never executed twice.
Two details of the canonical payload comparison matter in practice:
- The target lists
brandIds,accountIds,actions, andsocialAccountIdscompare as sets. Sending the same accounts in a different order still counts as the same request. - The order of media (
mediaAssetIds,mediaUrls) is part of the intent. Reordering media with the same key is a conflict, because media sequence is content.
The stored record is namespaced to your workspace and your principal (the specific API key or the signed-in owner session). Two different keys never share or expose each other's records, even when they belong to the same owner. A replay also re-checks current authority first: a revoked or expired key cannot replay its old requests and receives 401 KEY_REVOKED or 401 KEY_EXPIRED.
If the same key arrives with a different path, operation, or payload, the API rejects it:
{
"error": {
"code": "IDEMPOTENCY_CONFLICT",
"message": "Idempotency key reused with different resource, operation or payload",
"details": null,
"retryable": false
},
"requestId": "7f6b9d2a-4c1e-4a58-9d0f-2e7a1b3c4d5e"
}
When that happens, do not retry the old key. Generate a fresh UUID and send the corrected request as a new mutation.
201 and 202 mean different things
- 201 Created - a record now exists. Creating a draft post returns
201with the post projection. - 202 Accepted - asynchronous work has been accepted, nothing has happened on the social platform yet. Publishing, scheduling, cancelling, retrying, and comment replies return
202with a receipt that shows the per-target status.
Acceptance is never provider success. A 202 from POST /api/v1/posts/{id}/publish means Postkub queued the work; the targets move through queued, publishing, and then published, failed, or an attention state. Poll GET /api/v1/posts/{id} or read the activity log to follow the outcome.
A replay returns the original status code. If your first publish attempt was accepted with 202, replaying the same key returns 202 with the same receipt, not a second publication.
Revisions: expectedRevision
Every change to an existing resource carries expectedRevision in the body - the post revision, the thread revision, the account schedule-settings revision. This is an optimistic concurrency guard against two writers editing the same record:
- Omitting it returns
428 REVISION_REQUIRED. Fix the request; do not retry it unchanged. - Sending a revision that no longer matches returns
409 REVISION_CONFLICTwith the authorized current value indetails.currentRevision. Re-read the record, merge your change, and send a new request with a new idempotency key. - An identical replay resolves before the revision check. If the first attempt was accepted, retrying the same key returns the original result even though the revision has since moved on.
Recovering a lost response
If a request times out or the connection drops before you see the response, the mutation may still have succeeded. Never assume failure. Look the request up:
GET /api/v1/requests/7f6b9d2a-4c1e-4a58-9d0f-2e7a1b3c4d5e HTTP/1.1
Authorization: Bearer <API_KEY>
A stored request returns 200 with the original metadata and result:
{
"requestId": "7f6b9d2a-4c1e-4a58-9d0f-2e7a1b3c4d5e",
"status": "accepted",
"statusCode": 202,
"operation": "v1:posts:publish",
"path": "/api/v1/posts/post_123/publish",
"createdAt": "2026-12-01T09:00:00.000Z",
"result": { "requestId": "7f6b9d2a-4c1e-4a58-9d0f-2e7a1b3c4d5e" }
}
The statusCode field is the status code the original request returned, and result is the stored response body. The lookup re-projects the stored result through your current authority: if your key has been rescoped and can no longer receive the full stored body, the result is sanitized to an identifier-and-revision receipt; if you can no longer access the resource at all, the lookup answers 404. A key that holds no draft or media action is denied with 403 before any record is read. Only your own principal's records are visible - a key cannot look up its owner's session requests or another key's requests.
A 404 is not permission to resubmit
A 404 from the request lookup means "no accepted record found for this UUID" - it does not prove the mutation was rejected. The original request may still be in flight, or it may have been lost after acceptance. Resubmitting the same payload under a new UUID creates a second, independent mutation: two posts, two publications, or two replies.
The safe sequence after a lost response is always:
- Repeat the identical request with the same
Idempotency-Key. This is always safe. - If that still fails, look the request up with
GET /api/v1/requests/{requestId}. - Only generate a new key after you have confirmed from a read (
GET /api/v1/posts/{id}, the publication targets, orGET /api/v1/replies/{id}) that the original mutation produced no effect.
Unknown provider outcomes
Social platforms occasionally fail in ways where Postkub cannot tell whether the provider applied the change. Postkub marks such targets with an attention state (for example outcome_unknown or needs_review) rather than guessing. Treat an unknown outcome the same way you treat a lost response: reconcile from reads before any new mutation.
- Read
GET /api/v1/posts/{id}and inspect the per-target status. - For comment replies, read
GET /api/v1/replies/{id}, which returns the execution status and attempt history. - Never repeat an ambiguous publish or reply with a new key. A provider-level retry is a separate guarded action:
POST /api/v1/posts/{id}/retryis only accepted for failures that Postkub has proven had no effect, within the original schedule window.
Error codes on this path
| Code | HTTP | Meaning | What to do |
|---|---|---|---|
VALIDATION_ERROR | 400 | Missing or malformed Idempotency-Key, or invalid body | Fix the request; a new key is fine because nothing executed |
IDEMPOTENCY_CONFLICT | 409 | Key reused with a different path, operation, or payload | New UUID for the new mutation |
REVISION_REQUIRED | 428 | expectedRevision missing | Add the current revision and send as a new mutation |
REVISION_CONFLICT | 409 | Stored revision is newer than expectedRevision | Re-read, merge, resend with a new key |
LOCK_TIMEOUT | 409 | Another request holds the lock; retryable: true | Retry the same key after a short delay |
DATABASE_TIMEOUT | 503 | Request timed out server-side; retryable: true | Retry the same key |
INTERNAL_ERROR | 500 | Unexpected server failure | Retry the same key; the outcome stays safe |
The full error catalog, the response envelope, and retryable semantics live in Errors.
