Skip to content

/api/attr

getBlockAttrs

  • 🔥 获取块属性
  • /api/attr/getBlockAttrs

请求

ts
/**
 * Get block attributes
 */
export interface IPayload {
    /**
     * block ID
     */
    readonly id: string;
}
json5
/**
 * schemas/kernel/api/attr/getBlockAttrs/payload.schema.json5
 * 获取块属性
 * REF: https://github.com/siyuan-note/siyuan/blob/master/API.md#get-block-attributes
 * REF: https://github.com/siyuan-note/siyuan/blob/v2.9.3/kernel/api/attr.go#L36-L51
 * @pathname: /api/attr/getBlockAttrs
 * @version: 2.9.3
 */
{
    $schema: 'https://json-schema.org/draft/2020-12/schema',
    $id: 'https://github.com/siyuan-community/siyuan-sdk/raw/main/schemas/kernel/api/attr/getBlockAttrs/payload.schema.json5',
    $comment: 'v2.9.3',
    $ref: '#/$defs/root',
    $defs: {
        root: {
            title: 'payload body',
            description: 'Get block attributes',

            type: 'object',
            additionalProperties: false,
            required: [
                'id',
            ],
            properties: {
                id: {
                    type: 'string',
                    description: 'block ID',
                    pattern: '^\\d{14}-[0-9a-z]{7}$',
                },
            },
        },
    },
}
json
{
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "$id": "https://github.com/siyuan-community/siyuan-sdk/raw/main/schemas/kernel/api/attr/getBlockAttrs/payload.schema.json",
    "$comment": "v2.9.3",
    "$ref": "#/$defs/root",
    "$defs": {
        "root": {
            "title": "payload body",
            "description": "Get block attributes",
            "type": "object",
            "additionalProperties": false,
            "required": [
                "id"
            ],
            "properties": {
                "id": {
                    "type": "string",
                    "description": "block ID",
                    "pattern": "^\\d{14}-[0-9a-z]{7}$"
                }
            }
        }
    }
}

响应

ts
/**
 * Get block attributes
 */
export interface IResponse {
    /**
     * status code
     */
    readonly code: number;
    readonly data: IData;
    /**
     * status message
     */
    readonly msg: string;
}

/**
 * Inline Attribute List (IAL)
 */
export interface IData {
    /**
     * block ID
     */
    readonly id: string;
    /**
     * The last time the block was updated
     */
    readonly updated?: string;
    [property: string]: string;
}
json5
/**
 * schemas/kernel/api/attr/getBlockAttrs/response.schema.json5
 * 获取块属性
 * REF: https://github.com/siyuan-note/siyuan/blob/master/API.md#get-block-attributes
 * REF: https://github.com/siyuan-note/siyuan/blob/v2.9.3/kernel/api/attr.go#L36-L51
 * @pathname: /api/attr/getBlockAttrs
 * @version: 2.9.3
 */
{
    $schema: 'https://json-schema.org/draft/2020-12/schema',
    $id: 'https://github.com/siyuan-community/siyuan-sdk/raw/main/schemas/kernel/api/attr/getBlockAttrs/response.schema.json5',
    $comment: 'v2.9.3',
    $ref: '#/$defs/root',
    $defs: {
        root: {
            title: 'response body',
            description: 'Get block attributes',

            type: 'object',
            additionalProperties: false,
            required: [
                'code',
                'msg',
                'data',
            ],
            properties: {
                code: {
                    type: 'integer',
                    description: 'status code',
                },
                msg: {
                    type: 'string',
                    description: 'status message',
                },
                data: {
                    $ref: '#/$defs/data',
                },
            },
        },
        data: {
            title: 'IData',
            description: 'Inline Attribute List (IAL)',

            type: 'object',
            required: [
                'id',
            ],
            // REF: https://opis.io/json-schema/2.x/object.html#propertynames
            propertyNames: {
                type: 'string',
                minLength: 1,
                // REF: https://github.com/siyuan-note/siyuan/blob/v2.9.3/app/src/util/functions.ts#L74-L76
                pattern: '^[_a-zA-Z][_.\\-0-9a-zA-Z]*$',
            },
            // REF: https://opis.io/json-schema/2.x/object.html#patternproperties
            patternProperties: {
                '^((?!id|update)[_a-zA-Z][_.\\-0-9a-zA-Z]*)': {
                    type: 'string',
                    minLength: 1,
                },
            },
            // REF: https://json-schema.org/understanding-json-schema/reference/object.html#additional-properties
            additionalProperties: {
                type: 'string',
            },
            properties: {
                id: {
                    // 块 ID
                    type: 'string',
                    description: 'block ID',
                    pattern: '^\\d{14}-[0-9a-z]{7}$',
                    examples: [
                        '20200812220555-lj3enxa',
                    ],
                },
                updated: {
                    // 块上次更新时间 YYYYMMDDhhmmss
                    type: 'string',
                    description: 'The last time the block was updated',
                    pattern: '^((?:19|20)\\d{2})(0[1-9]|1[012])(0[1-9]|[12]\\d|3[01])([01]\\d|2[0-3])([0-5]\\d)([0-5]\\d)$',
                    examples: [
                        '20210714092948',
                    ],
                },
            },
        },
    },
}
json
{
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "$id": "https://github.com/siyuan-community/siyuan-sdk/raw/main/schemas/kernel/api/attr/getBlockAttrs/response.schema.json",
    "$comment": "v2.9.3",
    "$ref": "#/$defs/root",
    "$defs": {
        "root": {
            "title": "response body",
            "description": "Get block attributes",
            "type": "object",
            "additionalProperties": false,
            "required": [
                "code",
                "msg",
                "data"
            ],
            "properties": {
                "code": {
                    "type": "integer",
                    "description": "status code"
                },
                "msg": {
                    "type": "string",
                    "description": "status message"
                },
                "data": {
                    "$ref": "#/$defs/data"
                }
            }
        },
        "data": {
            "title": "IData",
            "description": "Inline Attribute List (IAL)",
            "type": "object",
            "required": [
                "id"
            ],
            "propertyNames": {
                "type": "string",
                "minLength": 1,
                "pattern": "^[_a-zA-Z][_.\\-0-9a-zA-Z]*$"
            },
            "patternProperties": {
                "^((?!id|update)[_a-zA-Z][_.\\-0-9a-zA-Z]*)": {
                    "type": "string",
                    "minLength": 1
                }
            },
            "additionalProperties": {
                "type": "string"
            },
            "properties": {
                "id": {
                    "type": "string",
                    "description": "block ID",
                    "pattern": "^\\d{14}-[0-9a-z]{7}$",
                    "examples": [
                        "20200812220555-lj3enxa"
                    ]
                },
                "updated": {
                    "type": "string",
                    "description": "The last time the block was updated",
                    "pattern": "^((?:19|20)\\d{2})(0[1-9]|1[012])(0[1-9]|[12]\\d|3[01])([01]\\d|2[0-3])([0-5]\\d)([0-5]\\d)$",
                    "examples": [
                        "20210714092948"
                    ]
                }
            }
        }
    }
}

getBookmarkLabels

  • 🛠 获取所有书签
  • /api/attr/getBookmarkLabels

响应

ts
/**
 * Get all bookmark labels
 */
export interface IResponse {
    /**
     * status code
     */
    readonly code: number;
    /**
     * bookmark list
     */
    readonly data: string[];
    /**
     * status message
     */
    readonly msg: string;
}
json5
/**
 * schemas/kernel/api/attr/getBookmarkLabels/response.schema.json5
 * 获取所有书签
 * REF: https://github.com/siyuan-note/siyuan/blob/v2.9.9/kernel/api/attr.go#L29-L34
 * @pathname: /api/attr/getBookmarkLabels
 * @version: 2.9.9
 */
{
    $schema: 'https://json-schema.org/draft/2020-12/schema',
    $id: 'https://github.com/siyuan-community/siyuan-sdk/raw/main/schemas/kernel/api/attr/getBookmarkLabels/response.schema.json5',
    $comment: 'v2.9.9',
    $ref: '#/$defs/root',
    $defs: {
        root: {
            title: 'response body',
            description: 'Get all bookmark labels',

            type: 'object',
            additionalProperties: false,
            required: [
                'code',
                'msg',
                'data',
            ],
            properties: {
                code: {
                    type: 'integer',
                    description: 'status code',
                },
                msg: {
                    type: 'string',
                    description: 'status message',
                },
                data: {
                    // 书签列表
                    type: 'array',
                    description: 'bookmark list',
                    items: {
                        type: 'string',
                    },
                },
            },
        },
    },
}
json
{
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "$id": "https://github.com/siyuan-community/siyuan-sdk/raw/main/schemas/kernel/api/attr/getBookmarkLabels/response.schema.json",
    "$comment": "v2.9.9",
    "$ref": "#/$defs/root",
    "$defs": {
        "root": {
            "title": "response body",
            "description": "Get all bookmark labels",
            "type": "object",
            "additionalProperties": false,
            "required": [
                "code",
                "msg",
                "data"
            ],
            "properties": {
                "code": {
                    "type": "integer",
                    "description": "status code"
                },
                "msg": {
                    "type": "string",
                    "description": "status message"
                },
                "data": {
                    "type": "array",
                    "description": "bookmark list",
                    "items": {
                        "type": "string"
                    }
                }
            }
        }
    }
}

setBlockAttrs

  • 🔥 设置块属性
  • /api/attr/setBlockAttrs

请求

ts
/**
 * Set block attributes
 */
export interface IPayload {
    readonly attrs: { [key: string]: string | null };
    /**
     * block ID
     */
    readonly id: string;
}
json5
/**
 * schemas/kernel/api/attr/setBlockAttrs/payload.schema.json5
 * 设置块属性
 * REF: https://github.com/siyuan-note/siyuan/blob/master/API.md#set-block-attributes
 * REF: https://github.com/siyuan-note/siyuan/blob/v2.9.3/kernel/api/attr.go#L53-L89
 * @pathname: /api/attr/setBlockAttrs
 * @version: 2.9.3
 */
{
    $schema: 'https://json-schema.org/draft/2020-12/schema',
    $id: 'https://github.com/siyuan-community/siyuan-sdk/raw/main/schemas/kernel/api/attr/setBlockAttrs/payload.schema.json5',
    $comment: 'v2.9.3',
    $ref: '#/$defs/root',
    $defs: {
        root: {
            title: 'payload body',
            description: 'Set block attributes',

            type: 'object',
            additionalProperties: false,
            required: [
                'id',
                'attrs',
            ],
            properties: {
                id: {
                    type: 'string',
                    description: 'block ID',
                    pattern: '^\\d{14}-[0-9a-z]{7}$',
                },
                attrs: {
                    $ref: '#/$defs/attrs',
                },
            },
        },
        attrs: {
            title: 'IAttrs',
            description: 'Inline Attribute List (IAL)',

            type: 'object',
            additionalProperties: {
                type: [
                    'string',
                    'null',
                ],
            },
            // REF: https://opis.io/json-schema/2.x/object.html#propertynames
            propertyNames: {
                type: 'string',
                minLength: 1,
                // REF: https://github.com/siyuan-note/siyuan/blob/v2.9.3/app/src/util/functions.ts#L74-L76
                pattern: '^[_a-zA-Z][_.\\-0-9a-zA-Z]*$',
            },
        },
    },
}
json
{
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "$id": "https://github.com/siyuan-community/siyuan-sdk/raw/main/schemas/kernel/api/attr/setBlockAttrs/payload.schema.json",
    "$comment": "v2.9.3",
    "$ref": "#/$defs/root",
    "$defs": {
        "root": {
            "title": "payload body",
            "description": "Set block attributes",
            "type": "object",
            "additionalProperties": false,
            "required": [
                "id",
                "attrs"
            ],
            "properties": {
                "id": {
                    "type": "string",
                    "description": "block ID",
                    "pattern": "^\\d{14}-[0-9a-z]{7}$"
                },
                "attrs": {
                    "$ref": "#/$defs/attrs"
                }
            }
        },
        "attrs": {
            "title": "IAttrs",
            "description": "Inline Attribute List (IAL)",
            "type": "object",
            "additionalProperties": {
                "type": [
                    "string",
                    "null"
                ]
            },
            "propertyNames": {
                "type": "string",
                "minLength": 1,
                "pattern": "^[_a-zA-Z][_.\\-0-9a-zA-Z]*$"
            }
        }
    }
}

响应

ts
/**
 * Set block attributes
 */
export interface IResponse {
    /**
     * status code
     */
    readonly code: number;
    readonly data: null;
    /**
     * status message
     */
    readonly msg: string;
}
json5
/**
 * schemas/siyuan/api/file/putFile/response.schema.json5
 * 设置块属性
 * REF: https://github.com/siyuan-note/siyuan/blob/master/API.md#set-block-attributes
 * REF: https://github.com/siyuan-note/siyuan/blob/v2.9.3/kernel/api/attr.go#L53-L89
 * @pathname: /api/attr/setBlockAttrs
 * @version: 2.9.3
 */
{
    $schema: 'https://json-schema.org/draft/2020-12/schema',
    $id: 'https://github.com/siyuan-community/siyuan-sdk/raw/main/schemas/kernel/api/attr/setBlockAttrs/response.schema.json5',
    $comment: 'v2.9.3',
    $ref: '#/$defs/root',
    $defs: {
        root: {
            title: 'response body',
            description: 'Set block attributes',

            type: 'object',
            additionalProperties: false,
            required: [
                'code',
                'msg',
                'data',
            ],
            properties: {
                code: {
                    type: 'integer',
                    description: 'status code',
                },
                msg: {
                    type: 'string',
                    description: 'status message',
                },
                data: {
                    type: 'null',
                },
            },
        },
    },
}
json
{
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "$id": "https://github.com/siyuan-community/siyuan-sdk/raw/main/schemas/kernel/api/attr/setBlockAttrs/response.schema.json",
    "$comment": "v2.9.3",
    "$ref": "#/$defs/root",
    "$defs": {
        "root": {
            "title": "response body",
            "description": "Set block attributes",
            "type": "object",
            "additionalProperties": false,
            "required": [
                "code",
                "msg",
                "data"
            ],
            "properties": {
                "code": {
                    "type": "integer",
                    "description": "status code"
                },
                "msg": {
                    "type": "string",
                    "description": "status message"
                },
                "data": {
                    "type": "null"
                }
            }
        }
    }
}