Quickstart
This walks through the API in five requests: check your token, create a page, read it, add a line to it and comment on it. Each step shows the request and what Lyra answers.
Before you start
Section titled “Before you start”-
Create an API token in Settings → API tokens.
-
Put it in your shell:
Terminal window export LYRA_TOKEN="lyra_pat_..."
The curl steps use jq to pick ids out of the answers.
With curl
Section titled “With curl”1. Check the token
Section titled “1. Check the token”curl -s "https://app.lyra-docs.com/api/v1/me" \ -H "Authorization: Bearer $LYRA_TOKEN"Lyra answers with you and the organization the token works in:
{ "id": "01a237c4-f581-73f7-ba96-b7f0e0868dc4", "name": "Sam", "email": "sam@example.com", "organization": { "id": "01a237c6-4b08-70a5-aae5-5841df10d92c", "name": "Acme", "role": "admin" }, "token": { "id": "01a237c7-57cc-76f4-a833-68cbb161491d", "expiresAt": "2027-01-01T17:22:20.748Z" }}2. Create a page
Section titled “2. Create a page”Send the page’s title and its content as Markdown. With no parentId or teamspaceId, the page goes into your private pages.
PAGE_ID=$(curl -s -X POST "https://app.lyra-docs.com/api/v1/pages" \ -H "Authorization: Bearer $LYRA_TOKEN" \ -H "Content-Type: application/json" \ -d '{ "title": "Release notes", "icon": "📦", "markdown": "## Version 1.4\n\n- Faster search\n- Diagrams follow dark mode" }' | jq -r '.page.id')echo "$PAGE_ID"The answer has the new page, with its id and url. It also has warnings, a list of lines Lyra read differently from what it looks like you meant, and built, which counts blocks other than plain text, such as cards. Both are empty here:
{ "page": { "id": "01a237d0-74ca-7487-b030-904b78865b52", "title": "Release notes", "icon": "📦", "kind": "doc", "url": "https://app.lyra-docs.com/p/01a237d0-74ca-7487-b030-904b78865b52", "parentId": null, "teamspaceId": null, "role": "full", "...": "..." }, "built": {}, "warnings": []}3. Read it with block ids
Section titled “3. Read it with block ids”Every block on a page has an id. Ask for them with withIds=true:
curl -s "https://app.lyra-docs.com/api/v1/pages/$PAGE_ID/markdown?withIds=true" \ -H "Authorization: Bearer $LYRA_TOKEN" | jq -r '.markdown'Each block starts with a <!-- block:ID --> line:
<!-- block:de94c0f6-6733-4539-bf0c-fdc0b213d5e1 -->## Version 1.4
<!-- block:9a4339f2-dbfc-462a-9fe3-d90691c82d49 -->- Faster search<!-- block:69aa4259-5361-446f-b3c0-1e0da763e49a -->- Diagrams follow dark mode4. Add a line
Section titled “4. Add a line”Change a page by block id rather than sending the whole page again, so people editing it at the same time keep their work. This adds a list item after the last block:
LAST_BLOCK=$(curl -s "https://app.lyra-docs.com/api/v1/pages/$PAGE_ID/markdown?withIds=true" \ -H "Authorization: Bearer $LYRA_TOKEN" | jq -r '.markdown' | grep -o 'block:[^ ]*' | tail -1 | cut -d: -f2)
curl -s -X POST "https://app.lyra-docs.com/api/v1/pages/$PAGE_ID/edits" \ -H "Authorization: Bearer $LYRA_TOKEN" \ -H "Content-Type: application/json" \ -d "{\"edits\": [{\"op\": \"insert\", \"afterBlockId\": \"$LAST_BLOCK\", \"markdown\": \"- Export to PDF\"}]}"The answer lists, for each edit, the ids of the blocks it added:
{ "edits": [ { "op": "insert", "blockIds": ["460b7c59-9640-4e2b-a719-4f949422648b"], "built": {}, "warnings": [] } ]}Other edits are replace and delete for one block, replace_all for the whole page, and set_cells, insert_row and delete_row for tables. One request can hold up to 100 edits. They apply in order and as one change: if one fails, none of them are made.
5. Comment on a line
Section titled “5. Comment on a line”Start a comment thread on the words “Faster search”. blockId says which block the quoted words are in:
SEARCH_BLOCK=$(curl -s "https://app.lyra-docs.com/api/v1/pages/$PAGE_ID/markdown?withIds=true" \ -H "Authorization: Bearer $LYRA_TOKEN" | jq -r '.markdown' | grep -o 'block:[^ ]*' | sed -n 2p | cut -d: -f2)
curl -s -X POST "https://app.lyra-docs.com/api/v1/pages/$PAGE_ID/threads" \ -H "Authorization: Bearer $LYRA_TOKEN" \ -H "Content-Type: application/json" \ -d "{\"markdown\": \"Can we ship this on **Thursday**?\", \"blockId\": \"$SEARCH_BLOCK\", \"quote\": \"Faster search\"}"{ "threadId": "01a237e4-cca7-73b7-ba50-443f49b4bf22", "commentId": "01a237e4-cca7-73b7-ba50-43a5ffdf250f" }Open the page’s url in Lyra to see the new line and the comment. Leave out blockId and quote to comment on the whole page.
Clean up
Section titled “Clean up”Move the page to the trash. You can restore it with POST /pages/{pageId}/restore.
curl -s -X POST "https://app.lyra-docs.com/api/v1/pages/$PAGE_ID/trash" \ -H "Authorization: Bearer $LYRA_TOKEN" | jq '{id, inTrash}'With JavaScript
Section titled “With JavaScript”The same steps in JavaScript, using fetch. Save it as quickstart.mjs and run it with Node 18 or later: node quickstart.mjs. It reads LYRA_TOKEN from the environment, like the curl steps.
const base = 'https://app.lyra-docs.com'const token = process.env.LYRA_TOKEN
async function lyra(method, path, body) { const response = await fetch(`${base}/api/v1${path}`, { method, headers: { Authorization: `Bearer ${token}`, ...(body ? { 'Content-Type': 'application/json' } : {}), }, body: body ? JSON.stringify(body) : undefined, }) if (response.status === 204) return null const data = await response.json() if (!response.ok) throw new Error(`${data.error.code}: ${data.error.message}`) return data}
const me = await lyra('GET', '/me')console.log(`Signed in as ${me.name} in ${me.organization.name}`)
const { page, warnings } = await lyra('POST', '/pages', { title: 'Release notes', markdown: '## Version 1.4\n\n- Faster search\n- Diagrams follow dark mode',})console.log(`Created ${page.url}`, warnings)
const { markdown } = await lyra('GET', `/pages/${page.id}/markdown?withIds=true`)const blockIds = [...markdown.matchAll(/<!-- block:(\S+) -->/g)].map((match) => match[1])
const { edits } = await lyra('POST', `/pages/${page.id}/edits`, { edits: [{ op: 'insert', afterBlockId: blockIds.at(-1), markdown: '- Export to PDF' }],})console.log('Added block', edits[0].blockIds)
const thread = await lyra('POST', `/pages/${page.id}/threads`, { markdown: 'Can we ship this on **Thursday**?', blockId: blockIds[1], quote: 'Faster search',})console.log('Started thread', thread.threadId)It prints:
Signed in as Sam in AcmeCreated https://app.lyra-docs.com/p/01a237d2-418a-7590-8722-29b690eb4c58 []Added block [ '7dbe0353-bac1-4d58-b97d-d28de869c11b' ]Started thread 01a237d2-41c0-7618-a593-d79f4da963aaThe lyra helper turns an error answer into an exception that names its code, such as page_not_found. Errors lists them.
- Paging for lists longer than one answer
- The reference for every endpoint, including databases and file uploads
- Rate limits before you run a script on a schedule