SiYuan API
by @xybio
思源笔记 - SiYuan API Skill,支持笔记本、文档、块、资源、数据库/属性视图和 SQL 操作。Local-only SiYuan API integration for notebooks, documents, blocks, assets, database/attribute views, and SQL operations.
clawhub install siyuan-api📖 About This Skill
name: siyuan-api description: Local SiYuan API integration for notebook/document/block/asset operations and SQL search. Uses only local HTTP endpoints and environment-based token auth. homepage: https://github.com/siyuan-note/siyuan metadata: openclaw: primaryEnv: SIYUAN_API_TOKEN requires: env: - SIYUAN_API_TOKEN - SIYUAN_API_URL
SiYuan Skill
本技能用于调用本地运行的 SiYuan HTTP API,支持笔记本、文档、块、资源、SQL 查询等常见操作。 它只描述调用规范和示例,不包含可执行安装脚本或第三方依赖。
Security Scope
127.0.0.1, localhost, or user-provided local URL).SIYUAN_API_TOKEN in logs.Configuration
Configuration can be provided via environment variables in your shell, for example:
export SIYUAN_API_TOKEN=your_token_here
export SIYUAN_API_URL=http://127.0.0.1:6806
SIYUAN_API_TOKEN (required): from SiYuan Settings > About.SIYUAN_API_URL (optional): defaults to http://127.0.0.1:6806.Typical Use Cases
API References
Common Examples
List Notebooks
const SIYUAN_API_TOKEN = process.env.SIYUAN_API_TOKEN;
const SIYUAN_API_URL = process.env.SIYUAN_API_URL || 'http://127.0.0.1:6806';fetch(${SIYUAN_API_URL}/api/notebook/lsNotebooks, {
method: 'POST',
headers: {
'Authorization': 'token ' + SIYUAN_API_TOKEN,
'Content-Type': 'application/json'
},
body: JSON.stringify({})
})
Create Document with Markdown
const SIYUAN_API_TOKEN = process.env.SIYUAN_API_TOKEN;
const SIYUAN_API_URL = process.env.SIYUAN_API_URL || 'http://127.0.0.1:6806';fetch(${SIYUAN_API_URL}/api/filetree/createDocWithMd, {
method: 'POST',
headers: {
'Authorization': 'token ' + SIYUAN_API_TOKEN,
'Content-Type': 'application/json'
},
body: JSON.stringify({
notebook: '笔记本ID',
path: '/文档路径',
markdown: '# 文档标题\n\n正文内容...'
})
})
Append Block
const SIYUAN_API_TOKEN = process.env.SIYUAN_API_TOKEN;
const SIYUAN_API_URL = process.env.SIYUAN_API_URL || 'http://127.0.0.1:6806';fetch(${SIYUAN_API_URL}/api/block/appendBlock, {
method: 'POST',
headers: {
'Authorization': 'token ' + SIYUAN_API_TOKEN,
'Content-Type': 'application/json'
},
body: JSON.stringify({
parentID: '父块ID',
dataType: 'markdown',
data: '追加的内容'
})
})
SQL Query
const SIYUAN_API_TOKEN = process.env.SIYUAN_API_TOKEN;
const SIYUAN_API_URL = process.env.SIYUAN_API_URL || 'http://127.0.0.1:6806';fetch(${SIYUAN_API_URL}/api/query/sql, {
method: 'POST',
headers: {
'Authorization': 'token ' + SIYUAN_API_TOKEN,
'Content-Type': 'application/json'
},
body: JSON.stringify({
stmt: 'SELECT id, content FROM blocks WHERE content LIKE "%关键词%" LIMIT 10'
})
})
Notes
createDocWithMd on the same path does not overwrite existing documents.custom-.POST and return { code, msg, data }.Authorization: token (lowercase token).⚙️ Configuration
Configuration can be provided via environment variables in your shell, for example:
export SIYUAN_API_TOKEN=your_token_here
export SIYUAN_API_URL=http://127.0.0.1:6806
SIYUAN_API_TOKEN (required): from SiYuan Settings > About.SIYUAN_API_URL (optional): defaults to http://127.0.0.1:6806.📋 Tips & Best Practices
createDocWithMd on the same path does not overwrite existing documents.custom-.POST and return { code, msg, data }.Authorization: token (lowercase token).