# Posting

`create_post` does the whole post in one call: its `when` publishes it now, at a time, at the next free time of each connection's posting times, or saves a draft. One post can go to several connections; each connection's copy has its own status and error, and the call answers the post as `get_post` shows it.

## Post one

| Step | Call | What happens |
|---|---|---|
| Check it | `create_post` with `dryRun: true` | Text, files and options against each connection's rules. Nothing is saved. |
| Post it | `create_post` | `when`: `now`, `next_slot`, `{ at }` (read in `timezone` without an offset) or `{ inMinutes }`; `draft` saves a draft, sent later with `publish_post`. Left out, 60 minutes ahead. `connections` takes channel names (`linkedin`) or ids; files go in `mediaItems` by public `url`. |
| Follow it | `get_post`, or the `post.published` and `post.failed` events | Each connection's copy reads `scheduled`, `publishing`, `published` or `failed`. |

`now` can answer while a copy still reads `publishing`. Say it went out only when `get_post` reads `published`, or `post.published` arrives.

## Many at once

| Call | Takes | Answers |
|---|---|---|
| `bulk_create_posts` | Up to 5,000 posts, each a `create_post` body with its own `when` | One result per item, in order (`rowIndex` from 1). Past 500 items, `202` with an import: follow it with `get_post_import` until `finishedAt`. |
| `import_posts` | A CSV, up to 5,000 rows | The same results. The same file again within 24 hours makes no post twice. |

- An item with `when` `now`, `next_slot` or `{ at }` is published, and the call asks the `publish` scope. An AI app asks the person first.
- `dryRun: true` checks every item and saves nothing.
- An item refused for its own reason is its own result; the others are still made. Send an `Idempotency-Key`, so a retried call makes each post once.

## Queues and times

- `list_queues` lists a connection's posting times; `get_next_queue_slot` reads the next free one. To use it, send `when: next_slot` (create_post or publish_post), never the time you read: it picks again as it saves, so two posts never take one time.
- `update_queue` with `reshuffleExisting: true` moves the posts waiting in the queue onto its new times.
- `timezone` is an IANA zone (`America/New_York`). A known alias is stored by its canonical name; an offset such as `+05:30` is refused with `400`.

## Statuses

| Field | Values |
|---|---|
| Post `status` | `draft`, `pending_approval`, `scheduled`, `publishing`, `published`, `partial`, `failed`, `cancelled` |
| Copy `status` | `pending`, `scheduled`, `publishing`, `published`, `failed`, `cancelled` |
| Copy `platformStatus` | `held` by a posting limit, `paused` in the connection's publishing cooldown, `creator_drafts` sent to the creator's TikTok drafts |

There is no retrying status: a copy tried again by itself stays `scheduled`, with `error.code` saying why it is late. `heldUntil` and `pausedUntil` say when a held or paused copy goes out. A copy the platform removed after it went out keeps `published` and carries `removedAt`.

## How it behaves

- Each connection has its own posting limits; a post over the hourly limit waits and goes out by itself. See [Rate limits](rate-limits.md), Posting limits.
- When posts to a connection are refused as spam or abuse, or many fail within an hour, the connection enters a publishing cooldown: 10 minutes, doubling each time inside a day, up to 24 hours. Its copies show `platformStatus: paused` and `pausedUntil`, and go out by themselves after it. Nothing ends it early.
- A failed or partial post is sent again with `publish_post`: only its failed copies go.
- `update_posts` with `action: "cancel"` stops a scheduled post and keeps it to change and schedule again; `unpublish_post` takes a published copy down.

## If it fails

Read each copy's `error.code` in the table below and do what its kind says. `error.nextOperation` names the call that fixes it, when one does. A refused call answers the [Errors](errors.md) envelope.

## Error codes

A copy's `error.code`, a bulk or import row's error and a refused post call each carry one of these codes. Branch on the kind; `message` is for people.

| Kind | Do | Codes |
|---|---|---|
| `retries` | The copy stays `scheduled` and is tried again by itself. Do nothing. | `processing`, `rate_limited`, `transient` |
| `held` | Held on purpose: it goes out by itself when the hold ends (`heldUntil`, `pausedUntil` or the reason named). Never retry or send it again. | `delete_held`, `plan_paused`, `publishing_paused` |
| `wait` | Wait for the limit to pass (`Retry-After`, `pausedUntil` or the time in `message`), then publish_post again. | `going_out`, `in_progress`, `platform_error`, `platform_rate_limit`, `publishing_unavailable`, `quota_exhausted`, `still_processing`, `tiktok_at_capacity`, `tiktok_daily_limit`, `user_abuse` |
| `retry` | publish_post again: it checks first and never posts twice. | `ambiguous_account`, `container_expired`, `post_conflict`, `queue_unavailable`, `save_unavailable`, `system_error`, `unconfirmed`, `unknown` |
| `edit` | Change the post, its options or its accounts (update_post), then publish_post again. | `account_not_enabled`, `content_refused`, `default_queue`, `duplicate_content`, `format_unsupported`, `invalid_post`, `invalid_target`, `media_missing`, `media_rejected`, `mention_unresolved`, `paid_partnership_login`, `platform_rejected`, `queue_slot_conflict`, `slot_taken`, `subtitles_invalid`, `unsupported_platform`, `user_content` |
| `person` | A person's step (reconnect the account, billing, the account on the platform): `nextOperation` names the tool when one does it; else ask the person. | `account_disconnected`, `account_issue`, `account_not_found`, `account_permission`, `account_restricted`, `auth_expired`, `brand_closed`, `cancelled_disconnected`, `plan_limit_messages`, `platform_scope_missing`, `reconnect_required`, `skipped_reauth`, `spend_limit`, `usage_empty` |
| `support` | Tell the person to contact support. | `billable_disabled`, `media_unavailable`, `provider_limit`, `wallet_frozen` |
| `done` | Final: nothing to retry. | `already_published`, `content_not_retained`, `invalid_state`, `remote_missing` |
