Documents

Endpoints and resources

Documents

Read descriptions and session notes as blocks, Markdown or text. Replace canonical blocks or change one exact passage.

Documents contain World page descriptions or session notes. GET requests need campaign:read. Writes need campaign:write, both read scopes and current paid editing access. Read the full document as blocks with the same key before editing it.

Read formats and fields

Both document GET routes accept only the optional format query parameter: blocks, markdown or text. It defaults to blocks. Do not repeat the parameter. No request body is used.

Field Type Description
data.blocks array of objects Present only for format=blocks. Canonical editor blocks for a private-content key; a read-only public projection otherwise.
data.markdown string Present only for format=markdown. Rendered Markdown.
data.text string Present only for format=text. Rendered text without heading or bold markers or images; list and table markers can remain.
data.profile string world-description-v1, text-session-v1 or session-summary-v1.
data.schema_version integer Always 1. Describes the editor document schema.
data.editable boolean True when canonical blocks validate, the key has private reading and write scopes, and the document's lifecycle permits editing. Current subscription access is still checked on writes.

Every format includes an ETag. For an edit, use the ETag from the blocks read. Markdown and text ETags describe different representations. Public reads remove GM-only sections and flatten entity links and detection placeholders into text; do not use that projection as an edit baseline.

Read an entity document

GET/api/public/v2/entities/{kind}/{id}/document

Requires campaign:read. Path kind is character, location, faction, item or custom; id is the entity UUID. Query format follows the table above. Returns the description with profile world-description-v1. An empty description has blocks: [].

Request
curl -i "https://app.saga20.com/api/public/v2/entities/character/a4f1b6d2-0e5c-4b7a-8c33-1d9e2f7a6b50/document?format=blocks" \
  -H "Authorization: Bearer $SAGA20_API_KEY"
Response
{
  "data": {
    "blocks": [
      {"id":"n1","type":"paragraph","props":{},"content":[{"type":"text","text":"Nyra guards the gate.","styles":{}}],"children":[]}
    ],
    "profile": "world-description-v1",
    "schema_version": 1,
    "editable": true
  }
}

Read a session document

GET/api/public/v2/sessions/{id}/document

Requires campaign:read. Path id is the session UUID. Query format follows the shared table. Text sessions return profile text-session-v1; recording summaries and notes from imported transcripts use session-summary-v1. For an import, check processing before reading its generated notes.

A text session permits notes editing while neither status nor summary_status is processing. An audio session, or a session with an unset type, permits editing only when both statuses are completed. Reading a supported document can still work while editable is false.

Request
curl -i "https://app.saga20.com/api/public/v2/sessions/7b1e3f0a-52c4-4d1e-9a2b-3c8f6d1a9e41/document?format=blocks" \
  -H "Authorization: Bearer $SAGA20_API_KEY"
Response
{
  "data": {
    "blocks": [
      {"id":"n1","type":"paragraph","props":{},"content":[{"type":"text","text":"The gate is sealed.","styles":{}}],"children":[]}
    ],
    "profile": "session-summary-v1",
    "schema_version": 1,
    "editable": true
  }
}

Read Markdown or text

Use these formats for display, search in your own tool or an export. They are read only. Supported legacy text can still render when a blocks request returns 422 with document_not_editable; such a document has editable: false. If rendering also fails, edit the notes in Saga20.

Markdown request
curl "https://app.saga20.com/api/public/v2/sessions/7b1e3f0a-52c4-4d1e-9a2b-3c8f6d1a9e41/document?format=markdown" \
  -H "Authorization: Bearer $SAGA20_API_KEY"
Markdown response
{"data":{"markdown":"The gate is sealed.","profile":"session-summary-v1","schema_version":1,"editable":true}}
Text request
curl "https://app.saga20.com/api/public/v2/sessions/7b1e3f0a-52c4-4d1e-9a2b-3c8f6d1a9e41/document?format=text" \
  -H "Authorization: Bearer $SAGA20_API_KEY"
Text response
{"data":{"text":"The gate is sealed.","profile":"session-summary-v1","schema_version":1,"editable":true}}

Full document body

PUT replaces the entire canonical block array. Start from the latest private blocks read and keep the content you want to retain. Send only blocks in the outer JSON object. All writes use Content-Type: application/json, an Idempotency-Key and the latest document ETag in If-Match. Mutation routes accept no query parameters, including format.

Field Type Description
blocks array of objects Required. At most 5,000 top-level blocks and 1,000,000 UTF-8 bytes for the serialized array. Send a smaller document if validation rejects its size. [] clears the document.
blocks[].id string Optional stable block identifier, 1 to 200 characters. Retain existing ids; include ids on new blocks if you want later text edits.
blocks[].type string Required supported editor block type.
blocks[].props object Type-specific properties. A paragraph can use {}. Preserve existing properties when retaining a block.
blocks[].content array or string Inline content for text blocks. The example uses text nodes with type, text and styles. Tables have structured table content; images and dividers omit content or use null.
blocks[].children array of objects Optional nested blocks.

Supported text blocks are paragraph, heading, bulletListItem, numberedListItem, checkListItem, quote, toggleListItem, divider and table. Text nodes accept the styles bold, italic, underline, strike and code as booleans, and textColor and backgroundColor as strings. An individual text value is limited to 100,000 characters; split longer text across blocks. Reuse the structures returned by a read for links, tables and images.

dmSection is supported only on World page descriptions. Keep existing GM-only blocks inside GM sections. A legacy private section without stable ids must stay intact, or be removed in a separate edit that leaves public content unchanged. Images already attached to the document may be retained; you cannot introduce new image URLs. Detection placeholders cannot be introduced in an edit.

Replace an entity document

PUT/api/public/v2/entities/{kind}/{id}/document

Requires campaign:write and both read scopes. Path parameters are the supported entity kind and UUID id. The body is the full document schema above. SAGA20_ETAG holds the exact quoted ETag from this entity's private blocks read.

The 200 acknowledgement has id, revision, canonical_hash, reconciliation_state and resource_url in data, plus meta.replayed. Reconciliation is pending or complete; the document has been committed in either case. Read resource_url for current blocks and the next ETag. The returned revision and canonical_hash are not values for If-Match.

Request
curl -X PUT "https://app.saga20.com/api/public/v2/entities/character/a4f1b6d2-0e5c-4b7a-8c33-1d9e2f7a6b50/document" \
  -H "Authorization: Bearer $SAGA20_API_KEY" \
  -H "Content-Type: application/json" \
  -H "If-Match: $SAGA20_ETAG" \
  -H "Idempotency-Key: greywatch-nyra-document-20261001" \
  --data '{"blocks":[{"id":"n1","type":"paragraph","props":{},"content":[{"type":"text","text":"Nyra guards the gate.","styles":{}}],"children":[]}]}'
Response
{
  "data": {
    "id": "a4f1b6d2-0e5c-4b7a-8c33-1d9e2f7a6b50",
    "revision": "b6a310f4-ae8e-4af1-9855-2485f5f096d8",
    "canonical_hash": "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12a4414f28b6e5778c79b8a108",
    "reconciliation_state": "pending",
    "resource_url": "/api/public/v2/entities/character/a4f1b6d2-0e5c-4b7a-8c33-1d9e2f7a6b50/document"
  },
  "meta": {"replayed": false}
}

Replace a session document

PUT/api/public/v2/sessions/{id}/document

Requires campaign:write and both read scopes. Path id is a session UUID. Send the same full document body and the ETag from this session's private blocks read. A session that is not ready for notes editing returns 409 with document_busy; wait until its notes are ready.

The acknowledgement uses the same fields as an entity document write. GM sections are not supported in session documents.

Request
curl -X PUT "https://app.saga20.com/api/public/v2/sessions/7b1e3f0a-52c4-4d1e-9a2b-3c8f6d1a9e41/document" \
  -H "Authorization: Bearer $SAGA20_API_KEY" \
  -H "Content-Type: application/json" \
  -H "If-Match: $SAGA20_ETAG" \
  -H "Idempotency-Key: greywatch-session-document-20261001" \
  --data '{"blocks":[{"id":"n1","type":"paragraph","props":{},"content":[{"type":"text","text":"The gate is sealed.","styles":{}}],"children":[]}]}'
Response
{
  "data": {
    "id": "7b1e3f0a-52c4-4d1e-9a2b-3c8f6d1a9e41",
    "revision": "6b988a59-6e1c-4c65-b13f-39c5f5a8ea2e",
    "canonical_hash": "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12a4414f28b6e5778c79b8a108",
    "reconciliation_state": "pending",
    "resource_url": "/api/public/v2/sessions/7b1e3f0a-52c4-4d1e-9a2b-3c8f6d1a9e41/document"
  },
  "meta": {"replayed": false}
}

Text replacement body

PATCH changes one direct text node inside one block. Read canonical blocks to find its block_id. The old text must appear exactly once among that block's direct text nodes. It cannot span text nodes, linked names, formatting boundaries or table cells. Use PUT for a structural edit.

Field Type Description
operation string Required. Exactly replace_text.
block_id string Required, 1 to 200 characters with non-whitespace text. Identifies exactly one block in the document.
old_text string Required, 1 to 1,000,000 characters. Must match one direct text range.
new_text string Required, up to 1,000,000 characters. An empty string removes the matched passage. The resulting document must pass the full block validator, including the individual text limit.

Unknown fields and query parameters are rejected. Text and styles outside the match stay in place. If no unique match exists, Saga20 returns 409 with ambiguous_text_match; read again and choose a unique block and passage.

Replace text in an entity document

PATCH/api/public/v2/entities/{kind}/{id}/document

Requires campaign:write and both read scopes. Path parameters are the supported entity kind and UUID id. Send the text replacement body above, a new Idempotency-Key and the ETag from this entity's latest private blocks read. A passage within a GM section stays there.

The 200 acknowledgement has the same fields as a PUT document write.

Request
curl -X PATCH "https://app.saga20.com/api/public/v2/entities/character/a4f1b6d2-0e5c-4b7a-8c33-1d9e2f7a6b50/document" \
  -H "Authorization: Bearer $SAGA20_API_KEY" \
  -H "Content-Type: application/json" \
  -H "If-Match: $SAGA20_ETAG" \
  -H "Idempotency-Key: greywatch-nyra-passage-20261001" \
  --data '{"operation":"replace_text","block_id":"n1","old_text":"guards the gate","new_text":"opened the gate"}'
Response
{
  "data": {
    "id": "a4f1b6d2-0e5c-4b7a-8c33-1d9e2f7a6b50",
    "revision": "42eb63da-482f-42c1-a3e4-725a1daf67ab",
    "canonical_hash": "713b1278e9a3907fd3bbf1c1a952d615082bbdf941a02e85c73aa0e3fa1920cc",
    "reconciliation_state": "pending",
    "resource_url": "/api/public/v2/entities/character/a4f1b6d2-0e5c-4b7a-8c33-1d9e2f7a6b50/document"
  },
  "meta": {"replayed": false}
}

Replace text in a session document

PATCH/api/public/v2/sessions/{id}/document

Requires campaign:write and both read scopes. Path id is a session UUID. Use the same text replacement schema and this session's latest private blocks ETag. The session lifecycle must permit editing, just as for PUT.

The 200 acknowledgement points to the session document. Read that URL again before your next edit.

Request
curl -X PATCH "https://app.saga20.com/api/public/v2/sessions/7b1e3f0a-52c4-4d1e-9a2b-3c8f6d1a9e41/document" \
  -H "Authorization: Bearer $SAGA20_API_KEY" \
  -H "Content-Type: application/json" \
  -H "If-Match: $SAGA20_ETAG" \
  -H "Idempotency-Key: greywatch-session-passage-20261001" \
  --data '{"operation":"replace_text","block_id":"n1","old_text":"The gate is sealed.","new_text":"The gate is open."}'
Response
{
  "data": {
    "id": "7b1e3f0a-52c4-4d1e-9a2b-3c8f6d1a9e41",
    "revision": "6af1386f-ea53-40e3-86d1-5ce937a49ac6",
    "canonical_hash": "713b1278e9a3907fd3bbf1c1a952d615082bbdf941a02e85c73aa0e3fa1920cc",
    "reconciliation_state": "pending",
    "resource_url": "/api/public/v2/sessions/7b1e3f0a-52c4-4d1e-9a2b-3c8f6d1a9e41/document"
  },
  "meta": {"replayed": false}
}