---
title: "Replace a single section by heading"
method: PATCH
path: "/api/workspaces/{slug}/doc/sections"
tags: ["Doc body"]
---

# Replace a single section by heading

`PATCH /api/workspaces/{slug}/doc/sections`

## Request

- Base URL: `https://trydock.ai`
- URL: `https://trydock.ai/api/workspaces/{slug}/doc/sections`
- Auth: HTTP bearer

Targeted-edit counterpart to PUT /doc (full replacement) and POST /doc/sections (append). Finds the FIRST heading whose plain text matches `heading` (case-sensitive, trimmed), then replaces everything from that heading up to the next heading at the same or shallower level. `markdown` is the FULL replacement INCLUDING the heading line; pass an empty string to delete the section. Returns 404 when no matching heading exists, by design, so a misremembered heading fails loudly. Same byte/depth/node-count guard as PUT /doc; same writeDocBody attribution path.

## Path parameters

- `slug` string, required

## Request body

- object
  - `heading` string, required
  - `markdown` string, required
  - `allowBlockLoss` boolean
  - `ifUnmodifiedSince` string
  - `ifSectionHash` string

## Response `200`

Replaced.

- object
  - `content` unknown
  - `markdown` string: CommonMark + GFM. Returned when `?format=markdown` (or `Accept: text/markdown` with no `?format`).
  - `text` string: Plain text, formatting marks stripped. Returned when `?format=text` (or `Accept: text/plain` with no `?format`).
  - `updatedAt` string, date-time, required
  - `updatedBy` string, required

## Other responses

- `400`: Body shape failed validation, OR doc body exceeded byte/depth/node-count cap after the section was substituted.
- `404`: No heading on the doc matches `heading` exactly.

---

[API](https://skmtc.dev/trydock/apis/dock-rest-api.md) - [All operations](https://skmtc.dev/trydock/apis/dock-rest-api/llms.txt) - [OpenAPI document](https://skmtc.dev/trydock/apis/dock-rest-api/revisions/dd96ae96a412?raw)
