# Update Post Content — Slab

> Replace or edit a post's body via the updatePostContent GraphQL mutation. Content must be supplied as a Quill delta (see https://quilljs.com/docs/delta/) wrapped in an {"ops":[...]} object, passed as a JSON string — the API rejects a…

- Key: `slab-update-post-content`
- Type: Action (Write)
- Version: 0.0.1
- App: Slab (`slab`) — https://pipedream.com/apps/slab.md
- This page (HTML): https://pipedream.com/apps/slab/actions/update-post-content
- Hints: open-world
- Source: https://github.com/PipedreamHQ/pipedream/blob/master/components/slab/actions/update-post-content/update-post-content.mjs

## Description

Replace or edit a post's body via the `updatePostContent` GraphQL mutation. Content must be supplied as a Quill delta (see https://quilljs.com/docs/delta/) wrapped in an `{"ops":[...]}` object, passed as a JSON string — the API rejects a native/unwrapped delta object at the GraphQL layer. IMPORTANT: Slab derives the post's displayed title from the first line of its content — there is no independent title field after creation. An op with `{"retain":0}` (or no leading retain) inserts at the very start WITHOUT deleting anything — it pushes the existing content later in the document, so it can change what displays as the title without removing the old title text (which still exists, just no longer on the first line). To actually replace the title, delete the existing title's range — `{"delete":N}` where N is the old title line's length — then insert the replacement. To append body text while preserving the title, first read the post's current `content` (via **Search Posts** or **Get Posts**) and lead with a `retain` count covering the existing title line's length. This is a distinct endpoint from **Update Post** (which handles metadata/access only, and cannot change title). Run **Search Posts** first to obtain the post ID. Example (append after a 20-character title line): postId `abc123`, delta `{"ops":[{"retain":20},{"insert":"Additional body text.\n"}]}` — a non-error response confirms the edit was accepted. CRITICAL: this mutation applies your delta positionally against whatever the post's content actually is at the moment the call runs — there is no version check, and the response reflects the pre-edit snapshot, not the result. Always re-read the post's current `content` (**Search Posts** or **Get Posts**) immediately before computing a delta, and if you need to make a second edit to the same post, re-read again first — never compute a new delta from an earlier read or from this action's own response. Offsets computed against a stale snapshot land in the wrong place and silently corrupt the document instead of erroring; they do not queue safely. [See the documentation](https://studio.apollographql.com/public/Slab/variant/current/schema/reference/objects/RootMutationType#updatePostContent).

## Props

| Prop | Type | Required | Description |
|---|---|---|---|
| `postId` | `string` | Yes | ID of the post whose content to update. Run Search Posts first to obtain the ID. |
| `delta` | `string` | Yes | Quill delta describing the content change, as a JSON string wrapped in {"ops":[...]}. To preserve the post's title (its first content line), lead with {"retain":N} where N is that line's length in characters before your insert. Example (append after a 20-character title line): {"ops":[{"retain":20},{"insert":"\nThis guide covers setup."}]}. Example (replace a range, not touching the title): {"ops":[{"retain":25},{"delete":3},{"insert":"new"}]}. Compute N and any retain/delete counts from a content you just read for this specific call — a value carried over from an earlier read or a prior call to this action will target the wrong position. Validated as JSON with an ops array in run(), then sent to the API as a JSON string. |

## Run it

**MCP**

```ts
import { Client } from "@modelcontextprotocol/sdk/client/index.js"
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js"
import { PipedreamClient } from "@pipedream/sdk"

const pd = new PipedreamClient({
  projectId: process.env.PIPEDREAM_PROJECT_ID!,
  clientId: process.env.PIPEDREAM_CLIENT_ID!,
  clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
  projectEnvironment: "production",
})

const accessToken = await pd.rawAccessToken

const transport = new StreamableHTTPClientTransport(
  new URL("https://remote.mcp.pipedream.net/v3"),
  {
    requestInit: {
      headers: {
        Authorization: `Bearer ${accessToken}`,
        "x-pd-project-id": process.env.PIPEDREAM_PROJECT_ID!,
        "x-pd-environment": "production",
        "x-pd-external-user-id": "{external_user_id}", // any stable ID for this user in your system
        "x-pd-app-slug": "slab",
      },
    },
  },
)

const mcp = new Client({ name: "my-agent", version: "1.0.0" })
await mcp.connect(transport)

const { tools } = await mcp.listTools()

// listTools() hands your model this tool's input schema, so it can
// fill the arguments itself:
const result = await mcp.callTool({
  name: "slab-update-post-content",
  arguments: {
    postId: "Post ID",
    delta: "Delta",
  },
})
```

**TypeScript**

```ts
import { PipedreamClient } from "@pipedream/sdk"

const pd = new PipedreamClient({
  projectId: process.env.PIPEDREAM_PROJECT_ID!,
  clientId: process.env.PIPEDREAM_CLIENT_ID!,
  clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
  projectEnvironment: "production",
})

const result = await pd.actions.run({
  id: "slab-update-post-content",
  externalUserId: "{external_user_id}", // any stable ID for this user in your system
  configuredProps: {
    slab: { authProvisionId: "apn_xxxxxxx" },
    postId: "Post ID",
    delta: "Delta",
  },
})

console.log(result)
```

**cURL**

```bash
curl -X POST https://api.pipedream.com/v1/connect/{project_id}/actions/run \
  -H "Content-Type: application/json" \
  -H "X-PD-Environment: production" \
  -H "Authorization: Bearer {access_token}" \
  -d '{
    "external_user_id": "{external_user_id}",
    "id": "slab-update-post-content",
    "configured_props": {
      "slab": { "authProvisionId": "apn_xxxxxxx" },
      "postId": "Post ID",
      "delta": "Delta"
    }
  }'
```

---

- App: https://pipedream.com/apps/slab.md · All apps: https://pipedream.com/apps
