Getting started

Go from a new account to your first published or scheduled post through the API in a few minutes.

Updated

Open in ClaudeOpen in ChatGPT
On this page

Go from a fresh Postkub workspace to your first published or scheduled post in five minutes. You set up Brands, social connections, and scoped API keys once in the web app, then call the REST API from your scripts or AI agents.

Note

The REST API is available now. The postkub CLI examples shown alongside cURL on this page reflect the @postkub/cli preview client, which is not yet published to npm.

1. Set up a Brand and social account

Owner setup is always human-authenticated in the web dashboard and is never exposed to external API keys.

  1. Create an account at /signup or sign in to your workspace.
  2. Create a Brand and pick its default IANA timezone (for example, Asia/Bangkok).
  3. Connect at least one social account to that Brand via OAuth so its status is active.

Once a social account is connected, your scripts or external AI can draft, publish, and schedule to it without repeated manual steps.

2. Create a scoped API key

Open API Settings in the web dashboard and create a new API key.

  1. Give the key a clear label (for example, Production content agent) and choose an environment (development, staging, or production).
  2. Select the exact Brands and connected social accounts the key may access.
  3. Choose the actions to grant, or keep the default all-social-actions preset (a snapshot of currently supported social actions limited to your selected targets).
  4. Optionally set an expiration timestamp, then create the key.

Copy the plaintext secret (pk_<env>_<secret>) right away—Postkub stores only a salted hash and displays the secret once. Keep it in an environment variable rather than in source code or command history.

export POSTKUB_API_KEY="<API_KEY>"

See Authentication & Scopes for the full scope catalog, rotation rules, and key-safety practices.

3. Confirm your key with /api/v1/me

Call GET /api/v1/me to verify your bearer token and inspect the workspace, Brand IDs, account IDs, and actions granted to the key. Any valid key can call this endpoint, even without brand:read or account:read.

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

Equivalent CLI command (preview):

postkub whoami --output json

Example response:

{
  "principalType": "api_key",
  "workspaceId": "ws_example01",
  "user": null,
  "apiKey": {
    "id": "key_example01",
    "name": "Production content agent",
    "prefix": "pk_prd_ab12c",
    "environment": "production",
    "revision": 1,
    "expiresAt": null
  },
  "actions": [
    "account:read",
    "account:schedule",
    "brand:read",
    "post:cancel",
    "post:create",
    "post:publish",
    "post:read",
    "post:schedule",
    "post:update"
  ],
  "brandIds": ["brand_example01"],
  "accountIds": ["acc_example01"],
  "brands": [
    {
      "id": "brand_example01",
      "name": "Acme Coffee",
      "timezone": "Asia/Bangkok",
      "createdAt": "2026-12-01T08:00:00.000Z"
    }
  ],
  "accounts": [
    {
      "id": "acc_example01",
      "brandId": "brand_example01",
      "provider": "meta",
      "platform": "facebook",
      "name": "Acme Coffee Page",
      "handle": "@acmecoffee",
      "timezone": "Asia/Bangkok",
      "status": "active",
      "createdAt": "2026-12-01T08:05:00.000Z"
    }
  ]
}

4. List accounts and inspect capabilities

With account:read, you can list accounts (optionally filtered by brandId) and check what each account currently supports before submitting a publication.

curl -sS "https://postkub.com/api/v1/accounts?brandId=brand_example01" \
  -H "Authorization: Bearer <API_KEY>"

Then check capabilities for the target account:

curl -sS https://postkub.com/api/v1/accounts/acc_example01/capabilities \
  -H "Authorization: Bearer <API_KEY>"

Equivalent CLI commands (preview):

postkub accounts list --brand-id brand_example01 --output json
postkub capabilities get --account-id acc_example01 --output json

Example capability response:

{
  "accountId": "acc_example01",
  "allowedActions": [
    "account:read",
    "account:schedule",
    "brand:read",
    "post:cancel",
    "post:create",
    "post:publish",
    "post:read",
    "post:schedule",
    "post:update"
  ],
  "publishFormats": [
    {
      "format": "image",
      "available": true,
      "reason": "Live image publication is qualified for this account"
    },
    {
      "format": "video",
      "available": false,
      "reason": "Live video publication is not qualified for this account yet"
    }
  ],
  "availability": {
    "drafts": {
      "available": true,
      "reason": "Text and hosted-media drafts are enabled"
    },
    "publishing": {
      "available": true,
      "reason": "Publishing is enabled for this account"
    },
    "comments": {
      "available": false,
      "reason": "Comment actions are not granted to this key"
    },
    "firstComment": {
      "available": true,
      "reason": "A first comment can be attached to scheduled posts and is published right after the post goes out"
    },
    "insights": {
      "available": false,
      "reason": "Insight actions are not granted to this key"
    }
  }
}

Tip

Check availability.publishing.available and publishFormats before scheduling or publishing. If a capability is unavailable, Postkub tells you why upfront instead of failing silently later.

5. Create a draft

Every write request requires a client-generated UUID in the Idempotency-Key header. Creating a post saves a draft at revision: 1—nothing is sent to a social network yet, and the same draft appears immediately in the web dashboard.

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": "Fresh seasonal roast drops Friday at 09:00."
  }'

Equivalent CLI command (preview):

postkub posts create \
  --brand-id brand_example01 \
  --account-id acc_example01 \
  --text "Fresh seasonal roast drops Friday at 09:00." \
  --output json

Example 201 Created response:

{
  "requestId": "11111111-1111-4111-8111-111111111111",
  "post": {
    "id": "post_example123",
    "brandId": "brand_example01",
    "status": "draft",
    "revision": 1,
    "text": "Fresh seasonal roast drops Friday at 09:00.",
    "socialAccountIds": ["acc_example01"],
    "mediaAssetIds": [],
    "mediaUrls": [],
    "mediaKind": "image",
    "firstComment": null,
    "firstCommentOverrides": [],
    "authorActorType": "user",
    "authorId": "user_example01",
    "sourcePrincipalType": "api_key",
    "sourcePrincipalId": "key_example01",
    "createdAt": "2026-12-03T08:00:00.000Z",
    "updatedAt": "2026-12-03T08:00:00.000Z",
    "targets": [
      {
        "socialAccountId": "acc_example01",
        "status": "pending"
      }
    ],
    "allowedActions": ["post:read", "post:update"]
  },
  "url": "/api/v1/posts/post_example123"
}

Need to attach images? Pass publicly readable direct HTTPS links in mediaUrls (CLI: repeatable --media-url). See Hosted Media for URL rules.

6. Publish now or schedule it

Publishing and scheduling are separate requests that use a new Idempotency-Key UUID and the draft's current expectedRevision.

Publish immediately

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):

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

Schedule instead

To schedule for a specific time in the account's timezone, call POST /api/v1/posts/{id}/schedule with localTime, timezone, and the matching fireAtUtc instant (or pass schedule: { nextSlot: true } to reserve the account's next weekly queue slot):

curl -sS -X POST https://postkub.com/api/v1/posts/post_example123/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 for next-slot queue scheduling (preview):

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

Both /publish and /schedule return 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-03T08:01:00.000Z",
      "localTime": null,
      "resolvedLocalTime": null,
      "timezone": null,
      "cancellationRequested": false,
      "allowedActions": ["cancel"],
      "firstCommentState": "skipped",
      "firstCommentError": null
    }
  ],
  "statusUrl": "/api/v1/posts/post_example123"
}

Warning

HTTP 202 Accepted means Postkub accepted your immutable publication intent and queued it for background execution. It does not mean the social network has already published the post.

7. Check the publication result

Poll GET /api/v1/posts/{id} (the statusUrl from the 202 receipt) to track per-target execution status, or configure Webhooks to receive lifecycle events.

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

Once the worker completes publication, both the top-level status and targets[].publication.status update to published:

{
  "id": "post_example123",
  "brandId": "brand_example01",
  "status": "published",
  "revision": 1,
  "text": "Fresh seasonal roast drops Friday at 09:00.",
  "socialAccountIds": ["acc_example01"],
  "mediaAssetIds": [],
  "mediaUrls": [],
  "mediaKind": "image",
  "firstComment": null,
  "firstCommentOverrides": [],
  "authorActorType": "user",
  "authorId": "user_example01",
  "sourcePrincipalType": "api_key",
  "sourcePrincipalId": "key_example01",
  "createdAt": "2026-12-03T08:00:00.000Z",
  "updatedAt": "2026-12-03T08:01:08.000Z",
  "targets": [
    {
      "socialAccountId": "acc_example01",
      "status": "published",
      "publication": {
        "socialAccountId": "acc_example01",
        "publicationId": "pub_example456",
        "revision": 3,
        "status": "published",
        "scheduleMode": "now",
        "fireAtUtc": "2026-12-03T08:01:00.000Z",
        "localTime": null,
        "resolvedLocalTime": null,
        "timezone": null,
        "cancellationRequested": false,
        "allowedActions": [],
        "firstCommentState": "skipped",
        "firstCommentError": null
      }
    }
  ],
  "allowedActions": ["post:read"]
}

Where to go next