Your first post

Walk through creating a draft, publishing immediately, verifying per-target status, scheduling, cancelling, and retrying safely.

Updated

Open in ClaudeOpen in ChatGPT
On this page

This walkthrough covers the full post lifecycle through the REST API: creating a draft, publishing immediately, checking per-target execution status, scheduling for a future time or queue slot, cancelling unstarted work, and retrying a safe failure.

Before you start, make sure your API key grants post:create, post:read, post:publish, post:schedule, and post:cancel for your Brand and target account (see Authentication & Scopes), and confirm availability.publishing.available is true via GET /api/v1/accounts/{id}/capabilities.

Note

The REST API is available now. Equivalent postkub CLI commands below reflect the @postkub/cli preview client, which is not yet published to npm.

1. Create a text draft

Every post starts as a draft at revision: 1. Pass a fresh UUID in Idempotency-Key, your brandId, at least one socialAccountIds entry (1–10 unique accounts under that Brand), and text (1–5,000 characters, not whitespace-only).

curl -sS -X POST https://postkub.com/api/v1/posts \
  -H "Authorization: Bearer <API_KEY>" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: 11111111-1111-4111-8111-111111111111" \
  -d '{
    "brandId": "brand_example01",
    "socialAccountIds": ["acc_example01"],
    "text": "Our new cold brew menu is live in all branches today."
  }'

Equivalent CLI commands using per-field flags or JSON input (preview):

postkub posts create \
  --brand-id brand_example01 \
  --account-id acc_example01 \
  --text "Our new cold brew menu is live in all branches today." \
  --output json

postkub posts create \
  --json '{"brandId":"brand_example01","socialAccountIds":["acc_example01"],"text":"Our new cold brew menu is live in all branches today."}' \
  --output json

Response (201 Created):

{
  "requestId": "11111111-1111-4111-8111-111111111111",
  "post": {
    "id": "post_example123",
    "brandId": "brand_example01",
    "status": "draft",
    "revision": 1,
    "text": "Our new cold brew menu is live in all branches today.",
    "socialAccountIds": ["acc_example01"],
    "mediaAssetIds": [],
    "mediaUrls": [],
    "mediaKind": "image",
    "firstComment": null,
    "firstCommentOverrides": [],
    "authorActorType": "user",
    "authorId": "user_example01",
    "sourcePrincipalType": "api_key",
    "sourcePrincipalId": "key_example01",
    "createdAt": "2026-12-03T09:00:00.000Z",
    "updatedAt": "2026-12-03T09:00:00.000Z",
    "targets": [
      {
        "socialAccountId": "acc_example01",
        "status": "pending"
      }
    ],
    "allowedActions": ["post:read", "post:update"]
  },
  "url": "/api/v1/posts/post_example123"
}

At this stage nothing is queued or sent externally. Postkub stores your exact Unicode text (without trimming) and enforces per-platform UTF-8 byte limits when you publish or schedule (multi-byte scripts such as Thai use more UTF-8 bytes per character than ASCII). Want to attach images? See Hosted Media.

2. Publish now

Call POST /api/v1/posts/{id}/publish with a new Idempotency-Key UUID, the draft's current expectedRevision, and the subset of saved socialAccountIds you want to publish.

curl -sS -X POST https://postkub.com/api/v1/posts/post_example123/publish \
  -H "Authorization: Bearer <API_KEY>" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: 22222222-2222-4222-8222-222222222222" \
  -d '{
    "expectedRevision": 1,
    "socialAccountIds": ["acc_example01"]
  }'

Equivalent CLI command (preview; add --wait to poll until execution settles):

postkub posts publish \
  --id post_example123 \
  --expected-revision 1 \
  --account-id acc_example01 \
  --wait \
  --output json

Response (202 Accepted):

{
  "requestId": "22222222-2222-4222-8222-222222222222",
  "post": {
    "id": "post_example123",
    "brandId": "brand_example01",
    "revision": 1,
    "socialAccountIds": ["acc_example01"]
  },
  "targets": [
    {
      "socialAccountId": "acc_example01",
      "publicationId": "pub_example456",
      "revision": 1,
      "status": "queued",
      "scheduleMode": "now",
      "fireAtUtc": "2026-12-03T09:01:00.000Z",
      "localTime": null,
      "resolvedLocalTime": null,
      "timezone": null,
      "cancellationRequested": false,
      "allowedActions": ["cancel"],
      "firstCommentState": "skipped",
      "firstCommentError": null
    }
  ],
  "statusUrl": "/api/v1/posts/post_example123"
}

HTTP 202 means Postkub accepted your immutable publication intent and woke the worker—it is not proof that the social platform finished publishing.

3. Verify per-target status

Read GET /api/v1/posts/{id} (matching statusUrl) to inspect each target's live publication object:

curl -sS https://postkub.com/api/v1/posts/post_example123 \
  -H "Authorization: Bearer <API_KEY>"

Equivalent CLI command (preview):

postkub posts get --id post_example123 --output json

Example settled response (200 OK):

{
  "id": "post_example123",
  "brandId": "brand_example01",
  "status": "published",
  "revision": 1,
  "text": "Our new cold brew menu is live in all branches today.",
  "socialAccountIds": ["acc_example01"],
  "mediaAssetIds": [],
  "mediaUrls": [],
  "mediaKind": "image",
  "firstComment": null,
  "firstCommentOverrides": [],
  "authorActorType": "user",
  "authorId": "user_example01",
  "sourcePrincipalType": "api_key",
  "sourcePrincipalId": "key_example01",
  "createdAt": "2026-12-03T09:00:00.000Z",
  "updatedAt": "2026-12-03T09:01:09.000Z",
  "targets": [
    {
      "socialAccountId": "acc_example01",
      "status": "published",
      "publication": {
        "socialAccountId": "acc_example01",
        "publicationId": "pub_example456",
        "revision": 3,
        "status": "published",
        "scheduleMode": "now",
        "fireAtUtc": "2026-12-03T09:01:00.000Z",
        "localTime": null,
        "resolvedLocalTime": null,
        "timezone": null,
        "cancellationRequested": false,
        "allowedActions": [],
        "firstCommentState": "skipped",
        "firstCommentError": null
      }
    }
  ],
  "allowedActions": ["post:read"]
}

What each status means

Each target reports its own execution status inside targets[].publication.status (or pending before publication is accepted), and the top-level post.status summarizes all targets:

Target statusMeaning
pendingSaved on the draft; no publish or schedule has been accepted yet
queuedAccepted and waiting for fireAtUtc or worker pickup
processingWorker is executing or polling provider processing
publishedConfirmed published on the social platform
failedExecution failed with a known error (errorCode set); check allowedActions to see if retry is safe
cancelledUnstarted work was cancelled before external side effects
outcome_unknownProvider call started, then timed out or returned an ambiguous result; Postkub reconciles rather than double-posting
needs_reviewRequires operator or owner inspection (for example, missed the 15-minute lateness window or could not be reconciled automatically)
blockedTarget cannot execute due to a blocker such as disconnected account or policy block

Top-level post.status rolls up target states into one summary: draft, scheduled, publishing, partially_published, published, needs_attention, failed, or cancelled.

4. Schedule instead

Create a fresh draft (for example, post_example456 at revision: 1), then call POST /api/v1/posts/{id}/schedule with both post:publish and post:schedule granted.

Schedule for an explicit time (local time + IANA timezone + UTC instant)

Pass targets with each target account's wall-clock localTime (no offset), its current IANA timezone, and the exact resolved fireAtUtc. Postkub validates that all three agree so daylight-saving changes or stale timezones never cause silent time drift.

  • For an account in a regional timezone such as Asia/Bangkok: set timezone to "Asia/Bangkok", localTime to "2026-12-10T09:00:00", and fireAtUtc to "2026-12-10T02:00:00.000Z".
  • For an account configured in UTC: set timezone to "UTC", localTime to "2026-12-10T09:00:00", and fireAtUtc to "2026-12-10T09:00:00.000Z".
curl -sS -X POST https://postkub.com/api/v1/posts/post_example456/schedule \
  -H "Authorization: Bearer <API_KEY>" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: 33333333-3333-4333-8333-333333333333" \
  -d '{
    "expectedRevision": 1,
    "targets": [
      {
        "socialAccountId": "acc_example01",
        "localTime": "2026-12-10T09:00:00",
        "timezone": "Asia/Bangkok",
        "fireAtUtc": "2026-12-10T02:00:00.000Z"
      }
    ]
  }'

Equivalent CLI command using inline JSON (preview):

postkub posts schedule \
  --id post_example456 \
  --expected-revision 1 \
  --json '{"targets":[{"socialAccountId":"acc_example01","localTime":"2026-12-10T09:00:00","timezone":"Asia/Bangkok","fireAtUtc":"2026-12-10T02:00:00.000Z"}]}' \
  --output json

Schedule into the next weekly queue slot

If the account has weekly queue slots configured (see Scheduling), pass schedule: { "nextSlot": true } instead of targets to reserve the earliest unoccupied future slot automatically:

curl -sS -X POST https://postkub.com/api/v1/posts/post_example456/schedule \
  -H "Authorization: Bearer <API_KEY>" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: 44444444-4444-4444-8444-444444444444" \
  -d '{
    "expectedRevision": 1,
    "socialAccountIds": ["acc_example01"],
    "schedule": { "nextSlot": true }
  }'

Equivalent CLI command (preview):

postkub posts schedule \
  --id post_example456 \
  --expected-revision 1 \
  --next-slot \
  --account-id acc_example01 \
  --output json

Response (202 Accepted):

{
  "requestId": "44444444-4444-4444-8444-444444444444",
  "post": {
    "id": "post_example456",
    "brandId": "brand_example01",
    "revision": 1,
    "socialAccountIds": ["acc_example01"]
  },
  "targets": [
    {
      "socialAccountId": "acc_example01",
      "publicationId": "pub_example789",
      "revision": 1,
      "status": "queued",
      "scheduleMode": "next_slot",
      "fireAtUtc": "2026-12-07T02:00:00.000Z",
      "localTime": "2026-12-07T09:00:00",
      "resolvedLocalTime": "2026-12-07T09:00:00.000",
      "timezone": "Asia/Bangkok",
      "cancellationRequested": false,
      "allowedActions": ["cancel"],
      "firstCommentState": "skipped",
      "firstCommentError": null
    }
  ],
  "statusUrl": "/api/v1/posts/post_example456"
}

5. Cancel a scheduled target

To stop an unstarted queued publication, call POST /api/v1/posts/{id}/cancel with the post's expectedRevision and the socialAccountIds to cancel:

curl -sS -X POST https://postkub.com/api/v1/posts/post_example456/cancel \
  -H "Authorization: Bearer <API_KEY>" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: 55555555-5555-4555-8555-555555555555" \
  -d '{
    "expectedRevision": 1,
    "socialAccountIds": ["acc_example01"]
  }'

Equivalent CLI command (preview):

postkub posts cancel \
  --id post_example456 \
  --expected-revision 1 \
  --account-id acc_example01 \
  --output json

Response (200 OK when cancelled before provider execution started):

{
  "requestId": "55555555-5555-4555-8555-555555555555",
  "post": {
    "id": "post_example456",
    "brandId": "brand_example01",
    "revision": 1,
    "socialAccountIds": ["acc_example01"]
  },
  "targets": [
    {
      "socialAccountId": "acc_example01",
      "publicationId": "pub_example789",
      "revision": 2,
      "status": "cancelled",
      "scheduleMode": "next_slot",
      "fireAtUtc": "2026-12-07T02:00:00.000Z",
      "localTime": "2026-12-07T09:00:00",
      "resolvedLocalTime": "2026-12-07T09:00:00.000",
      "timezone": "Asia/Bangkok",
      "cancellationRequested": true,
      "allowedActions": []
    }
  ],
  "statusUrl": "/api/v1/posts/post_example456"
}

Cancellation outcomes depend on execution state:

  • 200 OK (status: "cancelled"): The target had not started provider I/O; it is cancelled immediately and its capacity and queue-slot reservation are released.
  • 202 Accepted (cancellationRequested: true): A provider call already started or the outcome is unknown; Postkub records your cancellation request and reconciles the remote state instead of falsely marking it cancelled.
  • 409 ALREADY_PUBLISHED: The post is already live on the social network; cancelling never deletes a published remote post.

6. Retry a failed target

When a target enters status: "failed" and allowedActions includes "retry", you can re-queue it with POST /api/v1/posts/{id}/retry:

curl -sS -X POST https://postkub.com/api/v1/posts/post_example123/retry \
  -H "Authorization: Bearer <API_KEY>" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: 66666666-6666-4666-8666-666666666666" \
  -d '{
    "expectedRevision": 1,
    "socialAccountIds": ["acc_example01"]
  }'

Equivalent CLI command (preview):

postkub posts retry \
  --id post_example123 \
  --expected-revision 1 \
  --account-id acc_example01 \
  --output json

Response (202 Accepted):

{
  "requestId": "66666666-6666-4666-8666-666666666666",
  "post": {
    "id": "post_example123",
    "brandId": "brand_example01",
    "revision": 1,
    "socialAccountIds": ["acc_example01"]
  },
  "targets": [
    {
      "socialAccountId": "acc_example01",
      "publicationId": "pub_example456",
      "revision": 4,
      "status": "queued",
      "scheduleMode": "now",
      "fireAtUtc": "2026-12-03T09:01:00.000Z",
      "localTime": null,
      "resolvedLocalTime": null,
      "timezone": null,
      "cancellationRequested": false,
      "allowedActions": ["cancel"]
    }
  ],
  "statusUrl": "/api/v1/posts/post_example123"
}

Postkub only allows /retry when all three safety conditions hold:

  1. The target's status is failed with a proven no-effect outcome (not outcome_unknown or needs_review).
  2. Cancellation was not requested on the target.
  3. The retry arrives within 15 minutes of the original fireAtUtc.

If any condition fails, Postkub returns 409 UNSAFE_RETRY to prevent duplicate or unexpectedly late posts. Retrying a scheduled target also requires post:schedule in addition to post:publish.

Tip

If a request times out before you receive an HTTP response, do not send a new Idempotency-Key. Look up the original request ID via GET /api/v1/requests/{requestId} or replay with the exact same key and payload—see Idempotency & Request Recovery.

  • API Reference: Posts — full request and response fields for creating, listing, updating, deleting, and archiving posts.
  • API Reference: Publications — full field reference for /publish, /schedule, /cancel, and /retry.
  • Hosted Media — attach publicly hosted HTTPS media URLs to drafts.
  • Scheduling — weekly queue slots, DST behavior, and rescheduling with replaceExisting.
  • Errors — normalized error envelope and status codes.