---
title: "Edit a draft"
description: "PubNio API posts.update: edit a 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.

# Edit a draft

Edit a draft with [`PATCH /api/v1/posts/{postId}`](https://pubnio.com/api/v1/docs#tag/posts/PATCH/api/v1/posts/{postId}). Requires an API key with the `read` scope or a signed-in workspace member.

## Request

Edits a draft; a submitted post returns 409 post_submitted. Omitted fields are preserved; supplied media and target arrays replace the saved arrays. Send expectedRevision to guard against editing an older draft.

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

| Body field         | Type                       | Required |
| ------------------ | -------------------------- | -------- |
| `text`             | string                     | No       |
| `media`            | array of MediaInput        | No       |
| `scheduledAt`      | string or null             | No       |
| `platforms`        | array of one of 12 strings | No       |
| `accounts`         | array of UUID              | No       |
| `targets`          | array of CreatePostTarget  | No       |
| `expectedRevision` | integer                    | No       |

## Response

- HTTP 200: `Post` with `postId`, `isDraft`, `revision`, `text`, `media`, `targets`, `scheduledAt`, `deliveries`, `status`, `createdAt`, `updatedAt`.
  - `status`: `draft`, `scheduled`, `queued`, `submitting`, `confirming`, `published`, `provider_draft`, `failed`, `unresolved`, `cancelled`

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

## Examples

### TypeScript

```ts
const post = await workspace.posts.update(postId, {
  text: "Launch moved to Thursday.",
  expectedRevision: 2,
});
```

### Python

```python
post = workspace.posts.update(
    post_id,
    text="Launch moved to Thursday.",
    expected_revision=2,
)
```

### cURL

```sh
curl -X PATCH "https://pubnio.com/api/v1/posts/$POST_ID?workspaceId=$WORKSPACE_ID" \
  -H "Authorization: Bearer $PUBNIO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text":"Launch moved to Thursday.","expectedRevision":2}'
```

### CLI

```sh
pnio posts update "$POST_ID" --text "Launch moved to Thursday." --revision 2
```

### MCP execute

```js
async () => {
  const postId = "<postId>";
  const response = await codemode.request({
    method: "PATCH",
    path: `/api/v1/posts/${postId}`,
    query: { workspaceId: codemode.workspaceId },
    body: { text: "Launch moved to Thursday.", expectedRevision: 2 },
  });
  return response.data;
};
```

## Errors

- [`post-revision-conflict`](https://pubnio.com/docs/problems/post-revision-conflict/): HTTP 409, Post revision changed
- [`post-submitted`](https://pubnio.com/docs/problems/post-submitted/): HTTP 409, Post already submitted
- [`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

No key. Send `expectedRevision` so a stale retry fails instead of applying twice.

## 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-update/index.mdx
