---
title: "Create a post or draft"
description: "PubNio API posts.create: create a post or draft. Request fields, examples in five clients, errors, and idempotency."
---

> Documentation Index
> Fetch the complete documentation index at: https://pubnio.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Create a post or draft

Create a post or draft with [`POST /api/v1/posts`](https://pubnio.com/api/v1/docs#tag/posts/POST/api/v1/posts). Requires an API key with the `read` scope or a signed-in workspace member. Publishing or scheduling, anything but a draft, needs the `publish` scope or an owner.

## Request

Send exactly one selector for a direct post: platforms resolves the single ready account per provider (ambiguous providers return 422 with candidates), accounts selects exact account IDs, and targets selects exact destinations with an optional provider and placement. The server derives provider from accountId and defaults placement per provider. publishNow defaults to true when scheduledAt is absent. scheduledAt is the default time and targets\[].scheduledAt gives one destination its own time (null for now). Set isDraft to true to save the same body as a draft without submitting; a draft may omit the selector, and publishing it later needs no body. An omitted Idempotency-Key is generated and returned for posts and drafts; the same key and body replay for 24 hours and a changed body returns 409.

Unless `isDraft` is true, creating runs the duplicate-content guard: a destination that matches one already accepted for publishing to the same account and placement within 24 hours fails with `duplicate-content`, and `allowDuplicate: true` skips the check. A draft is checked when [`POST /api/v1/posts/{postId}/publish`](https://pubnio.com/api/v1/docs#tag/posts/POST/api/v1/posts/{postId}/publish) sends it, and that page lists what counts as a match.

| Parameter     | In    | Type | Required |
| ------------- | ----- | ---- | -------- |
| `workspaceId` | query | UUID | Yes      |

| Body field       | Type                       | Required |
| ---------------- | -------------------------- | -------- |
| `text`           | string                     | No       |
| `platforms`      | array of one of 12 strings | No       |
| `accounts`       | array of UUID              | No       |
| `targets`        | array of CreatePostTarget  | No       |
| `media`          | array of MediaInput        | No       |
| `scheduledAt`    | string                     | No       |
| `publishNow`     | boolean                    | No       |
| `isDraft`        | boolean                    | No       |
| `allowDuplicate` | boolean                    | No       |

## Response

- HTTP 201: `PostCreated` with `postId`, `isDraft`, `revision`, `text`, `media`, `targets`, `scheduledAt`, `deliveries`, `status`, `createdAt`, `updatedAt`, `idempotencyKey`.
  - `status`: `draft`, `scheduled`, `queued`, `submitting`, `confirming`, `published`, `provider_draft`, `failed`, `unresolved`, `cancelled`
- HTTP 202: `PublishAccepted` with `postId`, `idempotencyKey`, `targets`, `warnings`, `billing`.

The [OpenAPI document](https://pubnio.com/api/v1/openapi) has each field's type.

## Examples

### TypeScript

```ts
const accepted = await workspace.posts.create({
  text: "CSV exports are live. Download a week of reports in one click.",
  platforms: ["x", "linkedin"],
});
```

### Python

```python
accepted = workspace.posts.create(
    text="CSV exports are live. Download a week of reports in one click.",
    platforms=["x", "linkedin"],
)
```

### cURL

```sh
curl -X POST "https://pubnio.com/api/v1/posts?workspaceId=$WORKSPACE_ID" \
  -H "Authorization: Bearer $PUBNIO_API_KEY" \
  -H "Idempotency-Key: $IDEMPOTENCY_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text":"CSV exports are live. Download a week of reports in one click.","platforms":["x","linkedin"]}'
```

### CLI

```sh
pnio posts create --text "CSV exports are live. Download a week of reports in one click." --platform x --platform linkedin
```

### MCP execute

```js
async () => {
  // One key per intent; reuse it only to retry this same request.
  const idempotencyKey = crypto.randomUUID();
  const response = await codemode.request({
    method: "POST",
    path: "/api/v1/posts",
    query: { workspaceId: codemode.workspaceId },
    headers: { "Idempotency-Key": idempotencyKey },
    body: {
      text: "CSV exports are live. Download a week of reports in one click.",
      platforms: ["x", "linkedin"],
    },
  });
  return response.data;
};
```

## Errors

- [`insufficient-credit`](https://pubnio.com/docs/problems/insufficient-credit/): HTTP 402, Insufficient prepaid credit
- [`spend-cap-reached`](https://pubnio.com/docs/problems/spend-cap-reached/): HTTP 402, Monthly spend cap reached
- [`billing-inactive`](https://pubnio.com/docs/problems/billing-inactive/): HTTP 402, Workspace billing is inactive
- [`destination-already-submitted`](https://pubnio.com/docs/problems/destination-already-submitted/): HTTP 409, Destination already submitted
- [`duplicate-content`](https://pubnio.com/docs/problems/duplicate-content/): HTTP 409, Duplicate content
- [`idempotency-conflict`](https://pubnio.com/docs/problems/idempotency-conflict/): HTTP 409, Idempotency key already used
- [`post-revision-conflict`](https://pubnio.com/docs/problems/post-revision-conflict/): HTTP 409, Post revision changed
- [`invalid-publication`](https://pubnio.com/docs/problems/invalid-publication/): HTTP 422, Invalid publication

It also declares the problems [most operations](https://pubnio.com/docs/reference/#shared-problems) declare.

## Idempotency

Optional. A retry with the same `Idempotency-Key` returns the first result for 24 hours. Make one key per intent, such as `crypto.randomUUID()` or Python's `uuid4()`, and reuse it only to retry the same request. The TypeScript SDK makes a key for each call unless you pass `idempotencyKey`. See [Idempotency](https://pubnio.com/docs/concepts/idempotency/).

## Limits

- Field lengths and ranges are in the [OpenAPI document](https://pubnio.com/api/v1/openapi).

## Related

- [Posts operations](https://pubnio.com/docs/reference/#posts)
- [Publishing](https://pubnio.com/docs/publishing/)
- [Post lifecycle](https://pubnio.com/docs/concepts/post-lifecycle/)

Source: https://pubnio.com/docs/reference/posts-create/index.mdx
