# Create a document

`POST /v1/documents`

Creates a document in a workspace, optionally under a parent and with an initial Markdown body. Without afterId/beforeId it is appended as the last child.

Scope: `docs:write`. Undoable.

## Request

```bash
curl -X POST "https://api.lydie.co/v1/documents" \
  -H "Authorization: Bearer $LYDIE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "workspaceId": "01JCQ3TZ0WJ8K4M2X7T9R6N1PA",
    "title": "Meeting notes",
    "markdown": "# Meeting notes\n\n- Ship the developer docs"
  }'
```

## Body

- `workspaceId` (string, required): (1–64 chars)
- `id` (ULID, optional): Client-minted id. Generated when omitted.
- `parentId` (ULID, optional, nullable): Default: `null`.
- `title` (string, optional): Default: `"Untitled"`. (1–255 chars)
- `properties` (object, optional): Default: `{}`.
- `markdown` (string, optional): Initial body as Lydie Markdown.
- `teamspaceId` (string, optional, nullable): Hosted: the teamspace a top-level page goes into (null or absent: the creator's private section). Ignored for child pages, which share their parent's space, and in local mode. (1–64 chars)
- `afterId` (ULID, optional): Place directly after this sibling.
- `beforeId` (ULID, optional): Place directly before this sibling.
- `sortKey` (string, optional): Explicit fractional key. Overrides afterId/beforeId; recorded by clients so replays converge. (1–256 chars)

## Response

- `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)

```json
{
  "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
}
```

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