---
title: "Publish a saved draft"
description: "PubNio API posts.publish: publish a saved 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.

# Publish a saved draft

Publish a saved draft with [`POST /api/v1/posts/{postId}/publish`](https://pubnio.com/api/v1/docs#tag/posts/POST/api/v1/posts/{postId}/publish). Requires an API key with the `publish` scope or a signed-in workspace owner.

## Request

Publishes the saved revision named by expectedRevision and returns one accepted target per destination. Publish to Facebook Page feed, Reels, or Stories; Instagram feed, carousels, Reels, or Stories; LinkedIn text or single-image posts; Pinterest image, carousel, or video Pins; TikTok public videos or photo posts; Threads text, image, video, carousel, threads, or first comments; X text or threads; and YouTube videos or Shorts. Send one media array of \{ mediaId \} or \{ url \} selections. Schedule each destination independently.

Publishing refuses a destination whose content matches one already accepted for publishing to the same account and placement in the last 24 hours: the same text, thread or article, and media in order. Settings and times do not count, failed and cancelled deliveries do not match, and re-uploaded bytes get a new media ID that does not match. The call fails with `duplicate-content` naming each matching `postId` and `targetId`; send `allowDuplicate: true` to publish anyway.

Pick destinations with `accounts` (every draft placement of each account, each account once) or with `targets`, never both; otherwise the call fails with `invalid-publication`. With `expectedRevision`, a draft edited since you read it fails with `post-revision-conflict` and names `currentRevision`. A deleted draft returns `not-found`.

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

| Body field         | Type                          | Required |
| ------------------ | ----------------------------- | -------- |
| `expectedRevision` | integer                       | No       |
| `scheduledAt`      | string                        | No       |
| `accounts`         | array of UUID                 | No       |
| `targets`          | array of DestinationSelection | No       |
| `allowDuplicate`   | boolean                       | No       |

## Response

- 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.publish(postId, { expectedRevision: 2 });
```

### Python

```python
accepted = workspace.posts.publish(post_id, expected_revision=2)
```

### cURL

```sh
curl -X POST "https://pubnio.com/api/v1/posts/$POST_ID/publish?workspaceId=$WORKSPACE_ID" \
  -H "Authorization: Bearer $PUBNIO_API_KEY" \
  -H "Idempotency-Key: $IDEMPOTENCY_KEY" \
  -H "Content-Type: application/json" \
  -d '{"expectedRevision":2}'
```

### CLI

```sh
pnio posts publish "$POST_ID" --revision 2
```

### MCP execute

```js
async () => {
  const postId = "<postId>";
  // 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/${postId}/publish`,
    query: { workspaceId: codemode.workspaceId },
    headers: { "Idempotency-Key": idempotencyKey },
    body: { expectedRevision: 2 },
  });
  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

Required. 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-publish/index.mdx
