2022-02-24 23:36:43 +08:00
[中文 ](https://github.com/siyuan-note/siyuan/blob/master/API_zh_CN.md )
2022-02-24 23:36:06 +08:00
2022-02-24 23:23:13 +08:00
* [Specification ](#Specification )
* [Parameters and return values ](#Parameters-and-return-values )
2022-02-24 23:30:46 +08:00
* [Authentication ](#Authentication )
* [Notebooks ](#Notebooks )
* [List notebooks ](#List-notebooks )
* [Open a notebook ](#Open-a-notebook )
* [Close a notebook ](#Close-a-notebook )
* [Rename a notebook ](#Rename-a-notebook )
* [Create a notebook ](#Create-a-notebook )
* [Remove a notebook ](#Remove-a-notebook )
* [Get notebook configuration ](#Get-notebook-configuration )
* [Save notebook configuration ](#Save-notebook-configuration )
* [Documents ](#Documents )
* [Create a document with Markdown ](#Create-a-document-with-Markdown )
* [Rename a document ](#Rename-a-document )
* [Remove a document ](#Remove-a-document )
2023-02-02 11:06:10 +08:00
* [Move documents ](#Move-documents )
2022-02-24 23:30:46 +08:00
* [Get human-readable path based on path ](#Get-human-readable-path-based-on-path )
2022-03-13 10:54:39 +08:00
* [Get human-readable path based on ID ](#Get-human-readable-path-based-on-ID )
2022-02-24 23:30:46 +08:00
* [Assets ](#Assets )
* [Upload assets ](#Upload-assets )
* [Blocks ](#Blocks )
* [Insert blocks ](#Insert-blocks )
* [Prepend blocks ](#Prepend-blocks )
* [Append blocks ](#Append-blocks )
* [Update a block ](#Update-a-block )
* [Delete a block ](#Delete-a-block )
2023-04-06 18:29:44 +08:00
* [Move a block ](#Move-a-block )
2022-06-27 23:03:31 +08:00
* [Get a block kramdown ](#Get-a-block-kramdown )
2023-05-13 21:50:32 +08:00
* [Get child blocks ](#get-child-blocks )
2023-06-13 09:52:41 +08:00
* [Transfer block ref ](#transfer-block-ref )
2022-02-24 23:30:46 +08:00
* [Attributes ](#Attributes )
* [Set block attributes ](#Set-block-attributes )
* [Get block attributes ](#Get-block-attributes )
2021-09-17 11:38:54 +08:00
* [SQL ](#SQL )
2022-02-24 23:30:46 +08:00
* [Execute SQL query ](#Execute-SQL-query )
* [Templates ](#Templates )
* [Render a template ](#Render-a-template )
2023-03-24 15:00:36 +08:00
* [Render Sprig ](#Render-Sprig )
2022-03-24 00:25:41 +08:00
* [File ](#File )
2022-06-05 11:53:53 +08:00
* [Get file ](#Get-file )
* [Put file ](#Put-file )
2023-03-15 22:19:25 +08:00
* [Remove file ](#Remove-file )
2023-05-23 09:01:37 +08:00
* [Rename file ](#Rename-file )
2023-03-24 11:40:12 +08:00
* [List files ](#List-files )
2022-02-24 23:30:46 +08:00
* [Export ](#Export )
* [Export Markdown ](#Export-Markdown )
2023-07-28 16:48:17 +08:00
* [Export Files and Folders ](#Export-files-and-folders )
2023-05-12 11:35:14 +08:00
* [Conversion ](#Conversion )
* [Pandoc ](#Pandoc )
2022-06-05 11:53:53 +08:00
* [Notification ](#Notification )
* [Push message ](#Push-message )
* [Push error message ](#Push-error-message )
2023-07-10 23:21:04 +08:00
* [Network ](#Network )
* [Forward proxy ](#Forward-proxy )
2022-02-24 23:30:46 +08:00
* [System ](#System )
* [Get boot progress ](#Get-boot-progress )
* [Get system version ](#Get-system-version )
* [Get the current time of the system ](#Get-the-current-time-of-the-system )
2021-09-17 10:40:22 +08:00
---
2022-02-24 23:23:13 +08:00
## Specification
2021-09-17 12:04:12 +08:00
2022-02-24 23:23:13 +08:00
### Parameters and return values
2021-09-17 10:40:22 +08:00
2022-02-24 23:23:13 +08:00
* Endpoint: `http://127.0.0.1:6806`
* Both are POST methods
2022-03-24 00:25:41 +08:00
* An interface with parameters is required, the parameter is a JSON string, placed in the body, and the header
Content-Type is `application/json`
2022-02-24 23:23:13 +08:00
* Return value
2021-09-17 10:40:22 +08:00
2022-02-24 23:23:13 +08:00
````json
{
"code": 0,
"msg": "",
"data": {}
}
````
2021-09-17 10:40:22 +08:00
2022-03-24 00:25:41 +08:00
* `code` : non-zero for exceptions
* `msg` : an empty string under normal circumstances, an error text will be returned under abnormal conditions
* `data` : may be `{}` , `[]` or `NULL` , depending on the interface
2021-09-17 10:40:22 +08:00
2022-02-24 23:23:13 +08:00
### Authentication
2021-09-17 10:40:22 +08:00
2022-02-24 23:23:13 +08:00
View API token in < kbd > Settings - About</ kbd > , request header: `Authorization: Token xxx`
2021-09-17 10:40:22 +08:00
2022-02-24 23:23:13 +08:00
## Notebooks
2021-09-17 10:40:22 +08:00
2022-02-24 23:23:13 +08:00
### List notebooks
2021-09-17 10:40:22 +08:00
* `/api/notebook/lsNotebooks`
2022-02-24 23:23:13 +08:00
* No parameters
* Return value
2021-09-17 10:40:22 +08:00
```json
{
"code": 0,
"msg": "",
"data": {
2021-09-20 22:01:00 +08:00
"notebooks": [
2021-09-20 21:57:02 +08:00
{
2022-01-26 21:56:37 +08:00
"id": "20210817205410-2kvfpfn",
2022-02-24 23:23:13 +08:00
"name": "Test Notebook",
2022-01-26 21:56:37 +08:00
"icon": "1f41b",
"sort": 0,
"closed": false
2021-09-20 21:57:02 +08:00
},
{
2022-01-26 21:56:37 +08:00
"id": "20210808180117-czj9bvb",
2022-02-24 23:23:13 +08:00
"name": "SiYuan User Guide",
2022-01-26 21:56:37 +08:00
"icon": "1f4d4",
"sort": 1,
"closed": false
2021-09-20 21:57:02 +08:00
}
2021-09-17 10:40:22 +08:00
]
}
}
```
2022-02-24 23:23:13 +08:00
### Open a notebook
2021-09-17 10:40:22 +08:00
2021-09-17 11:38:54 +08:00
* `/api/notebook/openNotebook`
2022-02-24 23:23:13 +08:00
* Parameters
2021-09-17 11:38:54 +08:00
```json
{
"notebook": "20210831090520-7dvbdv0"
}
```
2022-02-24 23:23:13 +08:00
* `notebook` : Notebook ID
* Return value
2021-09-17 11:38:54 +08:00
```json
{
"code": 0,
"msg": "",
"data": null
}
```
2021-09-17 10:40:22 +08:00
2022-02-24 23:23:13 +08:00
### Close a notebook
2021-09-17 10:40:22 +08:00
2021-09-17 11:38:54 +08:00
* `/api/notebook/closeNotebook`
2022-02-24 23:23:13 +08:00
* Parameters
2021-09-17 11:38:54 +08:00
```json
{
"notebook": "20210831090520-7dvbdv0"
}
```
2022-02-24 23:23:13 +08:00
* `notebook` : Notebook ID
* Return value
2021-09-17 11:38:54 +08:00
```json
{
"code": 0,
"msg": "",
"data": null
}
```
2021-09-17 10:40:22 +08:00
2022-02-24 23:23:13 +08:00
### Rename a notebook
2021-09-17 10:40:22 +08:00
2021-09-17 11:38:54 +08:00
* `/api/notebook/renameNotebook`
2022-02-24 23:23:13 +08:00
* Parameters
2021-09-17 10:40:22 +08:00
2021-09-17 11:38:54 +08:00
```json
{
"notebook": "20210831090520-7dvbdv0",
2022-02-24 23:23:13 +08:00
"name": "New name for notebook"
2021-09-17 11:38:54 +08:00
}
```
2022-02-24 23:23:13 +08:00
* `notebook` : Notebook ID
* Return value
2021-09-17 11:38:54 +08:00
```json
{
"code": 0,
"msg": "",
"data": null
}
```
2022-02-24 23:23:13 +08:00
### Create a notebook
2021-09-17 11:38:54 +08:00
* `/api/notebook/createNotebook`
2022-02-24 23:23:13 +08:00
* Parameters
2021-09-17 11:38:54 +08:00
```json
{
2022-02-24 23:23:13 +08:00
"name": "Notebook name"
2021-09-17 11:38:54 +08:00
}
```
2022-02-24 23:23:13 +08:00
* Return value
2021-09-17 11:38:54 +08:00
```json
{
"code": 0,
"msg": "",
2022-01-26 22:01:26 +08:00
"data": {
"notebook": {
"id": "20220126215949-r1wvoch",
2022-02-24 23:23:13 +08:00
"name": "Notebook name",
2022-01-26 22:01:26 +08:00
"icon": "",
"sort": 0,
"closed": false
}
}
2021-09-17 11:38:54 +08:00
}
```
2021-09-17 11:58:41 +08:00
2022-02-24 23:23:13 +08:00
### Remove a notebook
2021-09-17 10:40:22 +08:00
2021-09-17 11:38:54 +08:00
* `/api/notebook/removeNotebook`
2022-02-24 23:23:13 +08:00
* Parameters
2021-09-17 11:38:54 +08:00
```json
{
"notebook": "20210831090520-7dvbdv0"
}
```
2022-02-24 23:23:13 +08:00
* `notebook` : Notebook ID
* Return value
2021-09-17 11:38:54 +08:00
```json
{
"code": 0,
"msg": "",
"data": null
}
```
2021-09-17 10:40:22 +08:00
2022-02-24 23:23:13 +08:00
### Get notebook configuration
2021-09-17 10:40:22 +08:00
2021-09-17 11:38:54 +08:00
* `/api/notebook/getNotebookConf`
2022-02-24 23:23:13 +08:00
* Parameters
2021-09-17 10:40:22 +08:00
2021-09-17 11:38:54 +08:00
```json
{
"notebook": "20210817205410-2kvfpfn"
}
```
2021-09-17 10:40:22 +08:00
2022-02-24 23:23:13 +08:00
* `notebook` : Notebook ID
* Return value
2021-09-17 10:40:22 +08:00
2021-09-17 11:38:54 +08:00
```json
{
"code": 0,
"msg": "",
"data": {
"box": "20210817205410-2kvfpfn",
"conf": {
2022-02-24 23:23:13 +08:00
"name": "Test Notebook",
2021-09-17 11:38:54 +08:00
"closed": false,
"refCreateSavePath": "",
"createDocNameTemplate": "",
"dailyNoteSavePath": "/daily note/{{now | date \"2006/01\"}}/{{now | date \"2006-01-02\"}}",
"dailyNoteTemplatePath": ""
},
2022-02-24 23:23:13 +08:00
"name": "Test Notebook"
2021-09-17 11:38:54 +08:00
}
}
```
2022-02-24 23:23:13 +08:00
### Save notebook configuration
2021-09-17 11:38:54 +08:00
* `/api/notebook/setNotebookConf`
2022-02-24 23:23:13 +08:00
* Parameters
2021-09-17 10:40:22 +08:00
```json
{
2021-09-17 11:38:54 +08:00
"notebook": "20210817205410-2kvfpfn",
"conf": {
2022-02-24 23:23:13 +08:00
"name": "Test Notebook",
2021-09-17 11:38:54 +08:00
"closed": false,
"refCreateSavePath": "",
"createDocNameTemplate": "",
"dailyNoteSavePath": "/daily note/{{now | date \"2006/01\"}}/{{now | date \"2006-01-02\"}}",
"dailyNoteTemplatePath": ""
}
2021-09-17 10:40:22 +08:00
}
```
2022-02-24 23:23:13 +08:00
* `notebook` : Notebook ID
* Return value
2021-09-17 10:40:22 +08:00
```json
{
"code": 0,
"msg": "",
2021-09-17 11:38:54 +08:00
"data": {
2022-02-24 23:23:13 +08:00
"name": "Test Notebook",
2021-09-17 11:38:54 +08:00
"closed": false,
"refCreateSavePath": "",
"createDocNameTemplate": "",
"dailyNoteSavePath": "/daily note/{{now | date \"2006/01\"}}/{{now | date \"2006-01-02\"}}",
"dailyNoteTemplatePath": ""
}
2021-09-17 10:40:22 +08:00
}
```
2022-02-24 23:23:13 +08:00
## Documents
2021-09-17 10:40:22 +08:00
2022-02-24 23:23:13 +08:00
### Create a document with Markdown
2021-09-17 10:40:22 +08:00
* `/api/filetree/createDocWithMd`
2022-02-24 23:23:13 +08:00
* Parameters
2021-09-17 10:40:22 +08:00
```json
{
2021-09-21 23:15:02 +08:00
"notebook": "20210817205410-2kvfpfn",
2021-09-17 10:40:22 +08:00
"path": "/foo/bar",
"markdown": ""
}
```
2022-02-24 23:23:13 +08:00
* `notebook` : Notebook ID
2022-03-24 00:25:41 +08:00
* `path` : Document path, which needs to start with / and separate levels with / (path here corresponds to the
database hpath field)
2022-02-24 23:23:13 +08:00
* `markdown` : GFM Markdown content
* Return value
2021-09-17 10:40:22 +08:00
```json
{
"code": 0,
"msg": "",
"data": "20210914223645-oj2vnx2"
}
```
2022-02-24 23:23:13 +08:00
* `data` : Created document ID
2023-05-28 21:59:48 +08:00
* If you use the same `path` to call this interface repeatedly, the existing document will not be overwritten
2021-09-17 10:40:22 +08:00
2022-02-24 23:23:13 +08:00
### Rename a document
2021-09-17 10:40:22 +08:00
2021-09-17 11:43:47 +08:00
* `/api/filetree/renameDoc`
2022-02-24 23:23:13 +08:00
* Parameters
2021-09-17 11:43:47 +08:00
```json
{
"notebook": "20210831090520-7dvbdv0",
"path": "/20210902210113-0avi12f.sy",
2022-02-24 23:23:13 +08:00
"title": "Document new title"
2021-09-17 11:43:47 +08:00
}
```
2022-02-24 23:23:13 +08:00
* `notebook` : Notebook ID
* `path` : Document path
* Return value
2021-09-17 11:43:47 +08:00
```json
{
"code": 0,
"msg": "",
"data": null
}
```
2021-09-17 10:40:22 +08:00
2022-02-24 23:23:13 +08:00
### Remove a document
2021-09-17 10:40:22 +08:00
2021-09-17 11:43:47 +08:00
* `/api/filetree/removeDoc`
2022-02-24 23:23:13 +08:00
* Parameters
2021-09-17 11:43:47 +08:00
```json
{
"notebook": "20210831090520-7dvbdv0",
"path": "/20210902210113-0avi12f.sy"
}
```
2022-02-24 23:23:13 +08:00
* `notebook` : Notebook ID
* `path` : Document path
* Return value
2021-09-17 10:40:22 +08:00
2021-09-17 11:43:47 +08:00
```json
{
"code": 0,
"msg": "",
"data": null
}
```
2021-09-17 11:58:41 +08:00
2023-02-02 11:06:10 +08:00
### Move documents
2021-09-17 22:03:31 +08:00
2023-02-02 11:06:10 +08:00
* `/api/filetree/moveDocs`
2022-02-24 23:23:13 +08:00
* Parameters
2021-09-17 22:03:31 +08:00
```json
{
2023-02-02 11:06:10 +08:00
"fromPaths": ["/20210917220056-yxtyl7i.sy"],
2021-09-17 22:03:31 +08:00
"toNotebook": "20210817205410-2kvfpfn",
"toPath": "/"
}
```
2023-02-02 11:06:10 +08:00
* `fromPaths` : Source paths
2022-02-24 23:23:13 +08:00
* `toNotebook` : Target notebook ID
* `toPath` : Target path
* Return value
2021-09-17 22:03:31 +08:00
```json
{
"code": 0,
"msg": "",
"data": null
}
```
2022-03-13 10:54:39 +08:00
### Get human readable path based on path
2021-09-17 22:07:55 +08:00
* `/api/filetree/getHPathByPath`
2022-02-24 23:23:13 +08:00
* Parameters
2021-09-17 22:07:55 +08:00
```json
{
"notebook": "20210831090520-7dvbdv0",
"path": "/20210917220500-sz588nq/20210917220056-yxtyl7i.sy"
}
```
2022-02-24 23:23:13 +08:00
* `notebook` : Notebook ID
* `path` : Document path
* Return value
2021-09-17 22:07:55 +08:00
```json
{
"code": 0,
"msg": "",
"data": "/foo/bar"
}
```
2022-03-13 10:54:39 +08:00
### Get human readable path based on ID
* `/api/filetree/getHPathByID`
* Parameters
```json
{
"id": "20210917220056-yxtyl7i"
}
```
2023-03-15 22:19:25 +08:00
* `id` : Block ID
2022-03-13 10:54:39 +08:00
* Return value
```json
{
"code": 0,
"msg": "",
"data": "/foo/bar"
}
```
2022-02-24 23:23:13 +08:00
## Assets
2021-09-17 10:40:22 +08:00
2022-02-24 23:23:13 +08:00
### Upload assets
2021-09-17 10:40:22 +08:00
* `/api/asset/upload`
2022-02-24 23:23:13 +08:00
* The parameter is an HTTP Multipart form
2021-09-17 10:40:22 +08:00
2023-02-23 10:20:21 +08:00
* `assetsDirPath` : The folder path where assets are stored, with the data folder as the root path, for example:
* `"/assets/"` : workspace/data/assets/ folder
* `"/assets/sub/"` : workspace/data/assets/sub/ folder
2021-09-17 10:40:22 +08:00
2023-02-23 10:20:21 +08:00
Under normal circumstances, it is recommended to use the first method, which is stored in the assets folder
2023-06-26 18:31:30 +08:00
of the workspace, putting in a subdirectory has some side effects, please refer to the assets chapter of the user
guide.
2022-02-24 23:23:13 +08:00
* `file[]` : Uploaded file list
* Return value
2021-09-17 10:40:22 +08:00
```json
{
"code": 0,
"msg": "",
"data": {
"errFiles": [""],
"succMap": {
"foo.png": "assets/foo-20210719092549-9j5y79r.png"
}
}
}
```
2022-02-24 23:23:13 +08:00
* `errFiles` : List of filenames with errors in upload processing
2022-03-24 00:25:41 +08:00
* `succMap` : For successfully processed files, the key is the file name when uploading, and the value is
assets/foo-id.png, which is used to replace the asset link address in the existing Markdown content with the
uploaded address
2021-09-17 10:40:22 +08:00
2022-02-24 23:23:13 +08:00
## Blocks
2021-12-30 12:07:21 +08:00
2022-02-24 23:23:13 +08:00
### Insert blocks
2021-12-30 12:07:21 +08:00
* `/api/block/insertBlock`
2022-02-24 23:23:13 +08:00
* Parameters
2021-12-30 12:07:21 +08:00
```json
{
"dataType": "markdown",
"data": "foo**bar**{: style=\"color: var(--b3-font-color8);\"}baz",
2023-05-17 09:38:12 +08:00
"nextID": "",
"previousID": "20211229114650-vrek5x6",
"parentID": ""
2021-12-30 12:07:21 +08:00
}
```
2022-02-24 23:23:13 +08:00
* `dataType` : The data type to be inserted, the value can be `markdown` or `dom`
* `data` : Data to be inserted
2023-05-17 09:38:12 +08:00
* `nextID` : The ID of the next block, used to anchor the insertion position
2022-02-24 23:23:13 +08:00
* `previousID` : The ID of the previous block, used to anchor the insertion position
2023-05-17 09:38:12 +08:00
* `parentID` : The ID of the parent block, used to anchor the insertion position
`nextID` , `previousID` , and `parentID` must have at least one value, using
priority: `nextID` > `previousID` > `parentID`
2022-02-24 23:23:13 +08:00
* Return value
2021-12-30 12:07:21 +08:00
```json
{
"code": 0,
"msg": "",
"data": [
{
"doOperations": [
{
"action": "insert",
2022-02-24 23:34:56 +08:00
"data": "< div data-node-id = \"20211230115020-g02dfx0 \" data-node-index = \"1 \" data-type = \"NodeParagraph \" class = \"p \">< div contenteditable = \"true \" spellcheck = \"false \"> foo< strong style = \"color: var ( --b3-font-color8 ); \"> bar</ strong > baz</ div >< div class = \"protyle-attr \" contenteditable = \"false \"></ div ></ div > ",
"id": "20211230115020-g02dfx0",
"parentID": "",
"previousID": "20211229114650-vrek5x6",
"retData": null
}
2021-12-30 12:07:21 +08:00
],
"undoOperations": null
}
]
}
```
2022-02-24 23:23:13 +08:00
* `action.data` : DOM generated by the newly inserted block
* `action.id` : ID of the newly inserted block
2021-12-30 12:07:21 +08:00
2022-02-24 23:23:13 +08:00
### Prepend blocks
2022-01-08 00:52:42 +08:00
* `/api/block/prependBlock`
2022-02-24 23:23:13 +08:00
* Parameters
2022-01-08 00:52:42 +08:00
```json
{
"data": "foo**bar**{: style=\"color: var(--b3-font-color8);\"}baz",
"dataType": "markdown",
"parentID": "20220107173950-7f9m1nb"
}
```
2022-02-24 23:23:13 +08:00
* `dataType` : The data type to be inserted, the value can be `markdown` or `dom`
* `data` : Data to be inserted
* `parentID` : The ID of the parent block, used to anchor the insertion position
* Return value
2022-01-08 00:52:42 +08:00
```json
{
"code": 0,
"msg": "",
"data": [
{
"doOperations": [
{
"action": "insert",
"data": "< div data-node-id = \"20220108003710-hm0x9sc \" data-node-index = \"1 \" data-type = \"NodeParagraph \" class = \"p \">< div contenteditable = \"true \" spellcheck = \"false \"> foo< strong style = \"color: var ( --b3-font-color8 ); \"> bar</ strong > baz</ div >< div class = \"protyle-attr \" contenteditable = \"false \"></ div ></ div > ",
"id": "20220108003710-hm0x9sc",
"parentID": "20220107173950-7f9m1nb",
"previousID": "",
"retData": null
}
],
"undoOperations": null
}
]
}
```
2022-02-24 23:23:13 +08:00
* `action.data` : DOM generated by the newly inserted block
* `action.id` : ID of the newly inserted block
2022-01-08 00:52:42 +08:00
2022-02-24 23:23:13 +08:00
### Append blocks
2022-01-08 00:52:42 +08:00
* `/api/block/appendBlock`
2022-02-24 23:23:13 +08:00
* Parameters
2022-01-08 00:52:42 +08:00
```json
{
"data": "foo**bar**{: style=\"color: var(--b3-font-color8);\"}baz",
"dataType": "markdown",
"parentID": "20220107173950-7f9m1nb"
}
```
2022-02-24 23:23:13 +08:00
* `dataType` : The data type to be inserted, the value can be `markdown` or `dom`
* `data` : Data to be inserted
* `parentID` : The ID of the parent block, used to anchor the insertion position
* Return value
2022-01-08 00:52:42 +08:00
```json
{
"code": 0,
"msg": "",
"data": [
{
"doOperations": [
{
"action": "insert",
"data": "< div data-node-id = \"20220108003642-y2wmpcv \" data-node-index = \"1 \" data-type = \"NodeParagraph \" class = \"p \">< div contenteditable = \"true \" spellcheck = \"false \"> foo< strong style = \"color: var ( --b3-font-color8 ); \"> bar</ strong > baz</ div >< div class = \"protyle-attr \" contenteditable = \"false \"></ div ></ div > ",
"id": "20220108003642-y2wmpcv",
"parentID": "20220107173950-7f9m1nb",
"previousID": "20220108003615-7rk41t1",
"retData": null
}
],
"undoOperations": null
}
]
}
```
2022-02-24 23:23:13 +08:00
* `action.data` : DOM generated by the newly inserted block
* `action.id` : ID of the newly inserted block
2022-01-08 00:52:42 +08:00
2022-02-24 23:23:13 +08:00
### Update a block
2021-12-30 16:39:09 +08:00
* `/api/block/updateBlock`
2022-02-24 23:23:13 +08:00
* Parameters
2021-12-30 16:39:09 +08:00
```json
{
"dataType": "markdown",
"data": "foobarbaz",
"id": "20211230161520-querkps"
}
```
2022-02-24 23:23:13 +08:00
* `dataType` : The data type to be updated, the value can be `markdown` or `dom`
* `data` : Data to be updated
* `id` : ID of the block to be updated
* Return value
2021-12-30 16:39:09 +08:00
```json
{
"code": 0,
"msg": "",
"data": [
{
"doOperations": [
{
"action": "update",
2022-02-24 23:34:56 +08:00
"data": "< div data-node-id = \"20211230161520-querkps \" data-node-index = \"1 \" data-type = \"NodeParagraph \" class = \"p \">< div contenteditable = \"true \" spellcheck = \"false \"> foo< strong > bar</ strong > baz</ div >< div class = \"protyle-attr \" contenteditable = \"false \"></ div ></ div > ",
"id": "20211230161520-querkps",
"parentID": "",
"previousID": "",
"retData": null
}
],
2021-12-30 16:39:09 +08:00
"undoOperations": null
}
]
}
```
2022-02-24 23:23:13 +08:00
* `action.data` : DOM generated by the updated block
2021-12-30 16:39:09 +08:00
2022-02-24 23:23:13 +08:00
### Delete a block
2021-12-30 16:45:00 +08:00
* `/api/block/deleteBlock`
2022-02-24 23:23:13 +08:00
* Parameters
2021-12-30 16:45:00 +08:00
```json
{
"id": "20211230161520-querkps"
}
```
2022-02-24 23:23:13 +08:00
* `id` : ID of the block to be deleted
* Return value
2021-12-30 16:45:00 +08:00
```json
{
"code": 0,
"msg": "",
"data": [
{
"doOperations": [
{
"action": "delete",
"data": null,
"id": "20211230162439-vtm09qo",
"parentID": "",
"previousID": "",
"retData": null
}
],
"undoOperations": null
}
]
}
```
2023-04-06 18:29:44 +08:00
### Move a block
* `/api/block/moveBlock`
* Parameters
```json
{
"id": "20230406180530-3o1rqkc",
"previousID": "20230406152734-if5kyx6",
"parentID": "20230404183855-woe52ko"
}
```
2023-05-12 11:35:14 +08:00
* `id` : Block ID to move
* `previousID` : The ID of the previous block, used to anchor the insertion position
* `parentID` : The ID of the parent block, used to anchor the insertion position, `previousID` and `parentID` cannot
be empty at the same time, if they exist at the same time, `previousID` will be used first
2023-04-06 18:29:44 +08:00
* Return value
```json
{
"code": 0,
"msg": "",
"data": [
{
"doOperations": [
{
"action": "move",
"data": null,
"id": "20230406180530-3o1rqkc",
"parentID": "20230404183855-woe52ko",
"previousID": "20230406152734-if5kyx6",
"nextID": "",
"retData": null,
"srcIDs": null,
"name": "",
"type": ""
}
],
"undoOperations": null
}
]
}
```
2022-06-27 23:03:31 +08:00
### Get a block kramdown
* `/api/block/getBlockKramdown`
* Parameters
```json
{
"id": "20201225220954-dlgzk1o"
}
```
2023-02-23 10:20:21 +08:00
* `id` : ID of the block to be got
2022-06-27 23:03:31 +08:00
* Return value
```json
{
"code": 0,
"msg": "",
"data": {
"id": "20201225220954-dlgzk1o",
"kramdown": "* {: id=\"20201225220954-e913snx\"}Create a new notebook, create a new document under the notebook\n {: id=\"20210131161940-kfs31q6\"}\n* {: id=\"20201225220954-ygz217h\"}Enter < kbd > /</ kbd > in the editor to trigger the function menu\n {: id=\"20210131161940-eo0riwq\"}\n* {: id=\"20201225220954-875yybt\"}((20200924101200-gss5vee \"Navigate in the content block\")) and ((20200924100906-0u4zfq3 \"Window and tab\"))\n {: id=\"20210131161940-b5uow2h\"}"
}
}
```
2023-02-23 10:20:21 +08:00
2023-05-13 21:50:32 +08:00
### Get child blocks
* `/api/block/getChildBlocks`
* Parameters
```json
{
"id": "20230506212712-vt9ajwj"
}
```
2023-05-17 09:38:12 +08:00
* `id` : Parent block ID
* The blocks below a heading are also counted as child blocks
2023-05-13 21:50:32 +08:00
* Return value
```json
{
"code": 0,
"msg": "",
"data": [
{
"id": "20230512083858-mjdwkbn",
"type": "h",
"subType": "h1"
},
{
"id": "20230513213727-thswvfd",
"type": "s"
},
{
"id": "20230513213633-9lsj4ew",
"type": "l",
"subType": "u"
}
]
}
```
2023-06-13 09:52:41 +08:00
### Transfer block ref
* `/api/block/transferBlockRef`
* Parameters
```json
{
"fromID": "20230612160235-mv6rrh1",
"toID": "20230613093045-uwcomng",
"refIDs": ["20230613092230-cpyimmd"]
}
```
2023-06-26 18:31:30 +08:00
* `fromID` : Def block ID
* `toID` : Target block ID
* `refIDs` : Ref block IDs point to def block ID, optional, if not specified, all ref block IDs will be transferred
2023-06-13 09:52:41 +08:00
* Return value
```json
{
"code": 0,
"msg": "",
"data": null
}
```
2022-02-24 23:23:13 +08:00
## Attributes
2021-09-17 10:40:22 +08:00
2022-02-24 23:30:46 +08:00
### Set block attributes
2021-09-17 10:40:22 +08:00
* `/api/attr/setBlockAttrs`
2022-02-24 23:23:13 +08:00
* Parameters
2021-09-17 10:40:22 +08:00
```json
{
"id": "20210912214605-uhi5gco",
"attrs": {
2022-02-24 23:34:56 +08:00
"custom-attr1": "line1\nline2"
2021-09-17 10:40:22 +08:00
}
}
```
2022-02-24 23:23:13 +08:00
* `id` : Block ID
* `attrs` : Block attributes, custom attributes must be prefixed with `custom-`
* Return value
2021-09-17 10:40:22 +08:00
```json
{
"code": 0,
"msg": "",
"data": null
}
```
2022-02-24 23:23:13 +08:00
### Get block attributes
2021-09-17 10:40:22 +08:00
* `/api/attr/getBlockAttrs`
2022-02-24 23:23:13 +08:00
* Parameters
2021-09-17 10:40:22 +08:00
```json
{
"id": "20210912214605-uhi5gco"
}
```
2022-02-24 23:23:13 +08:00
* `id` : Block ID
* Return value
2021-09-17 10:40:22 +08:00
```json
{
"code": 0,
"msg": "",
"data": {
"custom-attr1": "line1\nline2",
"id": "20210912214605-uhi5gco",
2022-02-24 23:23:13 +08:00
"title": "PDF Annotation Demo",
2021-09-17 10:40:22 +08:00
"type": "doc",
"updated": "20210916120715"
}
}
```
2021-09-17 11:38:54 +08:00
## SQL
2022-02-24 23:23:13 +08:00
### Execute SQL query
2021-09-17 11:38:54 +08:00
2021-12-31 16:25:56 +08:00
* `/api/query/sql`
2022-02-24 23:23:13 +08:00
* Parameters
2021-09-17 11:38:54 +08:00
```json
{
"stmt": "SELECT * FROM blocks WHERE content LIKE'%content%' LIMIT 7"
}
```
2022-02-24 23:23:13 +08:00
* `stmt` : SQL statement
* Return value
2021-09-17 11:38:54 +08:00
```json
{
"code": 0,
"msg": "",
"data": [
2022-02-24 23:23:13 +08:00
{ "col": "val" }
2021-09-17 11:38:54 +08:00
]
}
```
2021-09-17 11:58:41 +08:00
2022-02-24 23:23:13 +08:00
## Templates
2021-09-17 10:40:22 +08:00
2022-02-24 23:23:13 +08:00
### Render a template
2021-09-17 10:40:22 +08:00
2022-07-29 23:50:22 +08:00
* `/api/template/render`
* Parameters
```json
{
"id": "20220724223548-j6g0o87",
"path": "F:\\SiYuan\\data\\templates\\foo.md"
}
```
2023-02-23 10:20:21 +08:00
* `id` : The ID of the document where the rendering is called
* `path` : Template file absolute path
2022-07-29 23:50:22 +08:00
* Return value
```json
{
"code": 0,
"msg": "",
"data": {
"content": "< div data-node-id = \"20220729234848-dlgsah7 \" data-node-index = \"1 \" data-type = \"NodeParagraph \" class = \"p \" updated = \"20220729234840 \">< div contenteditable = \"true \" spellcheck = \"false \"> foo</ div >< div class = \"protyle-attr \" contenteditable = \"false \"> </ div ></ div > ",
"path": "F:\\SiYuan\\data\\templates\\foo.md"
}
}
```
2022-03-24 00:16:17 +08:00
2023-05-13 21:50:32 +08:00
### Render Sprig
2023-03-24 15:00:36 +08:00
* `/api/template/renderSprig`
* Parameters
```json
{
"template": "/daily note/{{now | date \"2006/01\"}}/{{now | date \"2006-01-02\"}}"
}
```
2023-03-29 10:45:15 +08:00
* `template` : template content
2023-03-24 15:00:36 +08:00
* Return value
```json
{
"code": 0,
"msg": "",
"data": "/daily note/2023/03/2023-03-24"
}
```
2022-03-24 00:16:17 +08:00
## File
### Get file
* `/api/file/getFile`
* Parameters
2022-03-24 00:25:41 +08:00
``json {
"path": "/data/20210808180117-6v0mkxr/20200923234011-ieuun1p.sy"
}
``
* `path` : the file path under the workspace path
2022-03-24 00:16:17 +08:00
* Return value
File content
### Put file
* `/api/file/putFile`
* The parameter is an HTTP Multipart form
2022-03-24 00:25:41 +08:00
* `path` : the file path under the workspace path
* `isDir` : whether to create a folder, when `true` only create a folder, ignore `file`
* `modTime` : last access and modification time, Unix time
* `file` : the uploaded file
2023-03-15 22:19:25 +08:00
* Return value
2022-03-24 00:16:17 +08:00
```json
{
"code": 0,
"msg": "",
"data": null
}
```
2021-09-17 10:40:22 +08:00
2023-03-15 22:19:25 +08:00
### Remove file
* `/api/file/removeFile`
* Parameters
```json
{
"path": "/data/20210808180117-6v0mkxr/20200923234011-ieuun1p.sy"
}
```
2023-03-29 10:45:15 +08:00
* `path` : the file path under the workspace path
2023-03-15 22:19:25 +08:00
* Return value
```json
{
"code": 0,
"msg": "",
"data": null
}
```
2023-05-23 09:01:37 +08:00
### Rename file
* `/api/file/renameFile`
* Parameters
```json
{
"path": "/data/assets/image-20230523085812-k3o9t32.png",
"newPath": "/data/assets/test-20230523085812-k3o9t32.png"
}
```
2023-06-26 18:31:30 +08:00
* `path` : the file path under the workspace path
* `newPath` : the new file path under the workspace path
2023-05-23 09:01:37 +08:00
* Return value
```json
{
"code": 0,
"msg": "",
"data": null
}
```
2023-03-24 11:40:12 +08:00
### List files
* `/api/file/readDir`
* Parameters
```json
{
2023-08-10 10:57:01 +08:00
"path": "/data/20210808180117-6v0mkxr/20200923234011-ieuun1p"
2023-03-24 11:40:12 +08:00
}
```
2023-08-10 10:57:28 +08:00
* `path` : the dir path under the workspace path
2023-03-24 11:40:12 +08:00
* Return value
```json
{
"code": 0,
"msg": "",
"data": [
2023-08-10 10:57:01 +08:00
{
"isDir": true,
"isSymlink": false,
"name": "20210808180303-6yi0dv5",
"updated": 1691467624
},
{
"isDir": false,
"isSymlink": false,
"name": "20210808180303-6yi0dv5.sy",
"updated": 1663298365
}
2023-03-24 11:40:12 +08:00
]
}
```
2023-03-15 22:19:25 +08:00
2022-02-24 23:23:13 +08:00
## Export
2021-09-17 10:40:22 +08:00
2022-02-24 23:23:13 +08:00
### Export Markdown
2021-09-17 10:40:22 +08:00
* `/api/export/exportMdContent`
2022-02-24 23:23:13 +08:00
* Parameters
2021-09-17 10:40:22 +08:00
```json
{
"id": ""
}
```
2022-02-24 23:23:13 +08:00
* `id` : ID of the doc block to export
* Return value
2021-09-17 10:40:22 +08:00
```json
{
"code": 0,
"msg": "",
"data": {
2022-02-24 23:34:56 +08:00
"hPath": "/Please Start Here",
"content": "## 🍫 Content Block\n\nIn SiYuan, the only important core concept is..."
2021-09-17 10:40:22 +08:00
}
}
```
2022-02-24 23:23:13 +08:00
* `hPath` : human-readable path
* `content` : Markdown content
2021-09-17 10:40:22 +08:00
2023-07-28 16:48:17 +08:00
### Export files and folders
* `/api/export/exportResources`
* Parameters
```json
{
"paths": [
"/conf/appearance/boot",
"/conf/appearance/langs",
"/conf/appearance/emojis/conf.json",
"/conf/appearance/icons/index.html",
],
"name": "zip-file-name"
}
```
* `paths` : A list of file or folder paths to be exported, the same filename/folder name will be overwritten
* `name` : (Optional) The exported file name, which defaults to `export-YYYY-MM-DD_hh-mm-ss.zip` when not set
* Return value
```json
{
"code": 0,
"msg": "",
"data": {
"path": "temp/export/zip-file-name.zip"
}
}
```
* `path` : The path of `*.zip` file created
* The directory structure in `zip-file-name.zip` is as follows:
* `zip-file-name`
* `boot`
* `langs`
* `conf.json`
* `index.html`
2023-05-12 11:35:14 +08:00
## Conversion
### Pandoc
* `/api/convert/pandoc`
* Working directory
2023-06-26 18:31:30 +08:00
* Executing the pandoc command will set the working directory to `workspace/temp/convert/pandoc/${dir}`
2023-05-12 11:35:14 +08:00
* API [`Put file` ](#put-file ) can be used to write the file to be converted to this directory first
* Then call the API for conversion, and the converted file will also be written to this directory
* Finally, call the API [`Get file` ](#get-file ) to get the converted file
* Or call the API [Create a document with Markdown ](#Create-a-document-with-Markdown )
* Or call the internal API `importStdMd` to import the converted folder directly
* Parameters
```json
{
2023-06-26 18:31:30 +08:00
"dir": "test",
2023-05-12 11:35:14 +08:00
"args": [
"--to", "markdown_strict-raw_html",
"foo.epub",
"-o", "foo.md"
]
}
```
* `args` : Pandoc command line parameters
* Return value
```json
{
"code": 0,
"msg": "",
2023-06-26 18:31:30 +08:00
"data": {
"path": "/temp/convert/pandoc/test"
}
2023-05-12 11:35:14 +08:00
}
```
2023-06-26 18:31:30 +08:00
* `path` : the path under the workspace
2023-05-12 11:35:14 +08:00
2022-06-05 11:53:53 +08:00
## Notification
### Push message
* `/api/notification/pushMsg`
* Parameters
```json
{
"msg": "test",
"timeout": 7000
}
```
* `timeout` : The duration of the message display in milliseconds. This field can be omitted, the default is 7000
milliseconds
* Return value
```json
{
"code": 0,
"msg": "",
"data": {
"id": "62jtmqi"
}
}
```
* `id` : Message ID
### Push error message
* `/api/notification/pushErrMsg`
* Parameters
```json
{
"msg": "test",
"timeout": 7000
}
```
* `timeout` : The duration of the message display in milliseconds. This field can be omitted, the default is 7000
milliseconds
* Return value
```json
{
"code": 0,
"msg": "",
"data": {
"id": "qc9znut"
}
}
```
2023-03-15 22:19:25 +08:00
* `id` : Message ID
2022-06-05 11:53:53 +08:00
2023-07-10 23:21:04 +08:00
## Network
### Forward proxy
2023-07-11 15:01:03 +08:00
* `/api/network/forwardProxy`
2023-07-10 23:21:04 +08:00
* Parameters
```json
{
"url": "https://b3log.org/siyuan/",
"method": "GET",
"timeout": 7000,
"contentType": "text/html",
"headers": [
{
"Cookie": ""
}
],
"payload": {}
}
```
* `url` : URL to forward
* `method` : HTTP method, default is `POST`
* `timeout` : timeout in milliseconds, default is `7000`
* `contentType` : Content-Type, default is `application/json`
* `headers` : HTTP headers
* `payload` : HTTP payload, object or string
* Return value
```json
{
"code": 0,
"msg": "",
"data": {
"body": "",
"contentType": "text/html",
"elapsed": 1976,
"headers": {
},
"status": 200,
"url": "https://b3log.org/siyuan"
}
}
```
2022-02-24 23:23:13 +08:00
## System
2021-09-17 10:40:22 +08:00
2022-02-24 23:23:13 +08:00
### Get boot progress
2021-09-17 11:54:13 +08:00
* `/api/system/bootProgress`
2022-02-24 23:23:13 +08:00
* No parameters
* Return value
2021-09-17 11:54:13 +08:00
```json
{
"code": 0,
"msg": "",
"data": {
2022-02-24 23:34:56 +08:00
"details": "Finishing boot...",
"progress": 100
2021-09-17 11:54:13 +08:00
}
}
```
2021-09-17 11:58:41 +08:00
2022-02-24 23:23:13 +08:00
### Get system version
2021-09-17 10:40:22 +08:00
2021-09-17 11:54:13 +08:00
* `/api/system/version`
2022-02-24 23:23:13 +08:00
* No parameters
* Return value
2021-09-17 10:40:22 +08:00
2021-09-17 11:54:13 +08:00
```json
{
"code": 0,
"msg": "",
"data": "1.3.5"
}
```
2022-02-24 23:23:13 +08:00
### Get the current time of the system
2021-09-17 11:58:41 +08:00
* `/api/system/currentTime`
2022-02-24 23:23:13 +08:00
* No parameters
* Return value
2021-09-17 11:58:41 +08:00
```json
{
"code": 0,
"msg": "",
"data": 1631850968131
}
```
2022-02-24 23:23:13 +08:00
* `data` : Precision in milliseconds