# Update a document body

`PATCH /v1/documents/{id}/body`

Replaces the body with `markdown`, or applies `edits` (exact old/new string replacements against the Markdown returned by doc.get). Edits that do not match exactly once are skipped and reported in `warnings`. Pass `expectedVersion` to fail with a conflict if the body changed since you read it.

Scope: `docs:write`. Undoable.

## Request

```bash
curl -X PATCH "https://api.lydie.co/v1/documents/01JCQ3V5MZ8G4ZK2X7T9R6N1PB/body" \
  -H "Authorization: Bearer $LYDIE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "edits": [
      {
        "oldStr": "Ship the developer docs",
        "newStr": "Shipped the developer docs"
      }
    ]
  }'
```

## Path parameters

- `id` (ULID, required)

## Body

- `markdown` (string, optional)
- `edits` (BodyEditInput[], optional): (≥ 1 items)
  - `oldStr` (string, required): (≥ 1 chars)
  - `newStr` (string, required)
  - `replaceAll` (boolean, optional): Default: `false`.
- `expectedVersion` (string, optional)

## Response

- `document` (Document, required): Document metadata. The body is not part of it.
  - `id` (ULID, required)
  - `workspaceId` (string, required): (1–64 chars)
  - `parentId` (ULID, required, nullable)
  - `title` (string, required): (1–255 chars)
  - `sortKey` (string, required): (1–256 chars)
  - `properties` (object, required)
  - `createdAt` (timestamp, required)
  - `updatedAt` (timestamp, required)
  - `deletedAt` (timestamp, required, nullable)
  - `createdBy` (string, optional, nullable): (≥ 1 chars)
  - `updatedBy` (string, optional, nullable): (≥ 1 chars)
- `version` (string, required)
- `warnings` (Warning[], required)
  - `code` (string, required): One of: `no_match`, `ambiguous_match`.
  - `message` (string, required)
  - `editIndex` (integer, optional)

```json
{
  "document": {
    "id": "01JCQ3V5MZ8G4ZK2X7T9R6N1PB",
    "workspaceId": "01JCQ3TZ0WJ8K4M2X7T9R6N1PA",
    "parentId": null,
    "title": "Meeting notes",
    "sortKey": "a0",
    "properties": {
      "status": "draft"
    },
    "createdAt": "2026-11-12T09:30:00.000Z",
    "updatedAt": "2026-11-12T09:30:00.000Z",
    "deletedAt": null,
    "createdBy": null,
    "updatedBy": null
  },
  "version": "3f9c2a71",
  "warnings": [
    {
      "code": "no_match",
      "message": "string",
      "editIndex": 0
    }
  ]
}
```

Errors use the envelope described at https://developers.lydie.co/errors.md.
