更新文章

基本信息

接口名称: 更新文章

接口类型: 数据更新

接口说明: 更新一篇文章

详细信息

URL

https://www.baklib.com/api/v1/articles/:id

完整URL示例

https://www.baklib.com/api/v1/articles/872dace-2aea-45aa-9517-a14ca9098bbd

HTTP请求方式

PUT

授权认证方式

默认方式,需要添加请求header

Authorization: Bearer <token>

请求参数

参数 必选 类型及范围 说明
tenant_id true String 站点id
channel_id false String 栏目id
status false Integer 发布状态,0=>'草稿',1=>'发布',默认为草稿状态。
name false String 文章标题
description false String 文章描述
identifier false String 文章唯一标识
tag_list false Array[String] 标签集
content_type false String 内容格式,支持'markdown'(即content传入markdown格式的字符串内容) 、'paragraph'(即content传入文本字符串内容)、‘raw’(即content传入baklib使用的编辑器editor.js格式的字符串内容),默认为 'paragraph'。
content false string 内容(数据类型均为字符串,与content_type对应,有三种形式,下面分别举例说明。)
access_level false Integer 访问等级
password false String 密码
fake_visits_count false Integer 虚拟访问量
id true String 文章id

示例代码

传入content_type为paragraph


var data = JSON.stringify({
  "name": "传入content_type为paragraph",
  "tenant_id": "aaa24dbe-a17b-4439-911d-176e0149cf76",
  "access_level": 0,
  "status": 0,
  "tag_list": [
    "Ruby",
    "Rails"
  ],
  "fake_visits_count": 800,
  "password": "123",
  "variables": {
    "hot": 1
  },
  "description": "这是描述",
  "content": "Hello,Baklib!",
  "content_type": "paragraph",
"channel_id":"ec9fc220-72b8-4e3e-b6d3-4b472fb38c46"
});

var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function() {
  if(this.readyState === 4) {
    console.log(this.responseText);
  }
});

xhr.open("PUT", "https://www.baklib.com/api/v1/articles/8872dace-2aea-45aa-9517-a14ca9098bbd");
xhr.setRequestHeader("Authorization", "Bearer 8486df9cb8a93ea843702141065c4a8b714602b45e7c4a6bb26a26ea3d69de6");
xhr.setRequestHeader("Content-Type", "application/json");


xhr.send(data);

返回结果


{
    "code": 0,
    "status": "success",
    "message": {
        "id": "8872dace-2aea-45aa-9517-a14ca9098bbd",
        "parent_id": "ec9fc220-72b8-4e3e-b6d3-4b472fb38c46",
        "name": "传入content_type为paragraph",
        "identifier": "207c",
        "description": "这是描述",
        "content": {
            "time": 1668674073000,
            "version": "2.18.0-5.8",
            "blocks": [
                {
                    "type": "paragraph",
                    "data": {
                        "text": "Hello,Baklib!"
                    }
                }
            ]
        },
        "ordinal": 0,
        "status": 0,
        "status_name": "草稿",
        "kind": 2,
        "kind_name": "文章",
        "slug": "unclassified/207c",
        "tenant_id": "aaa24dbe-a17b-4439-911d-176e0149cf76",
        "visits_count": 0,
        "fake_visits_count": 800,
        "created_at": "2022-11-09T10:57:20.634+08:00",
        "updated_at": "2022-11-17T16:34:33.581+08:00",
        "created_by": "822ca2a8-b3b7-4d7c-aaed-8cd3b221373f",
        "updated_by": "822ca2a8-b3b7-4d7c-aaed-8cd3b221373f",
        "password": "123",
        "access_level": 0,
        "template": "article.default",
        "variables": {},
        "variables_description": [],
        "tag_list": [
            "Ruby",
            "Rails"
        ],
        "frontend_url": "XXX",
        "edit_url": "XXX"
    }
}

传入content_type为markdown

var data = JSON.stringify({
  "name": "hi page 2",
  "tenant_id": "aaa24dbe-a17b-4439-911d-176e0149cf76",
  "access_level": 0,
  "status": 1,
  "tag_list": [
    "Ruby",
    "DAG"
  ],
  "fake_visits_count": 800,
  "password": "123",
  "variables": {
    "hot": 1
  },
  "description": "这是描述",
  "content": "一段文字的开始<b>hello</b>",
  "content_type": "markdown",
"channel_id":"ec9fc220-72b8-4e3e-b6d3-4b472fb38c46"
});

var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function() {
  if(this.readyState === 4) {
    console.log(this.responseText);
  }
});

xhr.open("PUT", "https://www.baklib.com/api/v1/articles/8872dace-2aea-45aa-9517-a14ca9098bbd");
xhr.setRequestHeader("Authorization", "XXX");
xhr.setRequestHeader("Content-Type", "application/json");



xhr.send(data);

返回结果


{
    "code": 0,
    "status": "success",
    "message": {
        "id": "8872dace-2aea-45aa-9517-a14ca9098bbd",
        "parent_id": "ec9fc220-72b8-4e3e-b6d3-4b472fb38c46",
        "name": "hi page 2",
        "identifier": "207c",
        "description": "这是描述",
        "content": {
            "time": 1668596479000,
            "version": "2.18.0-5.8",
            "blocks": [
                {
                    "type": "markdown",
                    "data": {
                        "text": "一段文字的开始<b>hello</b>"
                    }
                }
            ]
        },
        "ordinal": 0,
        "status": 1,
        "status_name": "发布",
        "kind": 2,
        "kind_name": "文章",
        "slug": "unclassified/207c",
        "tenant_id": "aaa24dbe-a17b-4439-911d-176e0149cf76",
        "visits_count": 0,
        "fake_visits_count": 800,
        "created_at": "2022-11-09T10:57:20.634+08:00",
        "updated_at": "2022-11-16T19:01:19.377+08:00",
        "created_by": "822ca2a8-b3b7-4d7c-aaed-8cd3b221373f",
        "updated_by": "822ca2a8-b3b7-4d7c-aaed-8cd3b221373f",
        "password": "123",
        "access_level": 0,
        "template": "article.default",
        "variables": {},
        "variables_description": [],
        "tag_list": [
            "Ruby",
            "DAG"
        ],
        "frontend_url": "XXX",
        "edit_url": "XXX"
    }
}

传入content_type为raw

var data = JSON.stringify({
  "name": "传入content_type为raw",
  "tenant_id": "aaa24dbe-a17b-4439-911d-176e0149cf76",
  "access_level": 0,
  "status": 0,
  "tag_list": [
    "Ruby",
    "Rails"
  ],
  "fake_visits_count": 800,
  "password": "123",
  "variables": {
    "hot": 1
  },
  "description": "这是描述",
  "content": "{\"time\":1668669785851,\"blocks\":[{\"id\":\"guNSvTDzsg\",\"type\":\"paragraph\",\"data\":{\"text\":\"Hello, Baklib!\",\"alignment\":\"align-left\"}},{\"id\":\"tRi5OCbGaX\",\"type\":\"qiniuImage\",\"data\":{\"url\":\"http://dev.bk-cdn.com/t/aaa24dbe-a17b-4439-911d-176e0149cf76/u/822ca2a8-b3b7-4d7c-aaed-8cd3b221373f/1668668621876/v2-454fba3b1159d364b448f77e092aef74.jpg\",\"caption\":\"说明\",\"withBorder\":false,\"withBackground\":false,\"stretched\":false,\"isHistoryImage\":false}},{\"id\":\"f_J2OncGRk\",\"type\":\"paragraph\",\"data\":{\"text\":\"\",\"alignment\":\"align-left\"}}],\"version\":\"2.22.2\"}",
  "content_type": "raw",
"channel_id":"ec9fc220-72b8-4e3e-b6d3-4b472fb38c46"
});

var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function() {
  if(this.readyState === 4) {
    console.log(this.responseText);
  }
});

xhr.open("PUT", "https://www.baklib.com/api/v1/articles/8872dace-2aea-45aa-9517-a14ca9098bbd");
xhr.setRequestHeader("Authorization", "Bearer 8486df9cb8a93ea843702141065c4a8b714602b45e7c4a6bb26a26ea3d69de6");
xhr.setRequestHeader("Content-Type", "application/json");

xhr.send(data);

返回结果


{
    "code": 0,
    "status": "success",
    "message": {
        "id": "8872dace-2aea-45aa-9517-a14ca9098bbd",
        "parent_id": "ec9fc220-72b8-4e3e-b6d3-4b472fb38c46",
        "name": "传入content_type为raw",
        "identifier": "207c",
        "description": "这是描述",
        "content": {
            "time": 1668669785851,
            "blocks": [
                {
                    "id": "guNSvTDzsg",
                    "type": "paragraph",
                    "data": {
                        "text": "Hello, Baklib!",
                        "alignment": "align-left"
                    }
                },
                {
                    "id": "tRi5OCbGaX",
                    "type": "qiniuImage",
                    "data": {
                        "url": "http://dev.bk-cdn.com/t/aaa24dbe-a17b-4439-911d-176e0149cf76/u/822ca2a8-b3b7-4d7c-aaed-8cd3b221373f/1668668621876/v2-454fba3b1159d364b448f77e092aef74.jpg",
                        "caption": "说明",
                        "withBorder": false,
                        "withBackground": false,
                        "stretched": false,
                        "isHistoryImage": false
                    }
                },
                {
                    "id": "f_J2OncGRk",
                    "type": "paragraph",
                    "data": {
                        "text": "",
                        "alignment": "align-left"
                    }
                }
            ],
            "version": "2.22.2"
        },
        "ordinal": 0,
        "status": 0,
        "status_name": "草稿",
        "kind": 2,
        "kind_name": "文章",
        "slug": "unclassified/207c",
        "tenant_id": "aaa24dbe-a17b-4439-911d-176e0149cf76",
        "visits_count": 0,
        "fake_visits_count": 800,
        "created_at": "2022-11-09T10:57:20.634+08:00",
        "updated_at": "2022-11-17T16:39:09.891+08:00",
        "created_by": "822ca2a8-b3b7-4d7c-aaed-8cd3b221373f",
        "updated_by": "822ca2a8-b3b7-4d7c-aaed-8cd3b221373f",
        "password": "123",
        "access_level": 0,
        "template": "article.default",
        "variables": {},
        "variables_description": [],
        "tag_list": [
            "Ruby",
            "Rails"
        ],
        "frontend_url": "XXX",
        "edit_url": "XXX"
    }
}

返回字段说明

返回值字段 字段类型 说明
code Integer 状态码
status String 返回状态
message Hash 返回数据主体
    id String 文章id
    parent_id String 栏目id
    name String 文章标题
    identifier String 栏目唯一标识符
    description String 文章描述
    content Jsonb 文章内容
        time Integer 文章创建时间码
        verison String 编辑器相关版本
        blocks Array[String] 对应编辑器中显示的区块
            type String 内容格式类型(paragraph=>段落,quote=>引用,qiniuImage=>图片)
            id String 区块id
            data Jsonb 区块数据
                text String 文本
                alignment String 对齐方式
                url String 图片地址(传图片时)
                caption String 图片说明(传图片时)
                withBorder Boolean 是否加边框(传图片时)
                withBackground Boolean 是否为背景(传图片时)
                stretched Boolean 是否拉伸(传图片时)
                isHistoryImage Boolean 是否为历史图片(传图片时)
    ordinal String 文章排序
    status Integer 文章状态, 0=> '草稿',1=>'已发布';默认为草稿状态。
    status_name String 栏目状态中文名称
    kind Integer 文章类型标志
    kind_name String 文章类型名称
    slug String 文章路径
    tenant_id String 站点id
    visit_count Integer 访问总数
    fake_visits_count Integer 虚拟访问量
    created_at Datetime 创建时间
    updated_at Datetime 更新时间
    created_by String 创建者id
    updated_by String 更新者id
    password String 密码
    access_level Integer 访问等级
    template String 文章模板
    variables Jsonb 其他变量
    variables_description Array 变量描述
    tag_list Array 标签结果集
    frontend_url String 前端访问地址
    edit_url String 编辑地址
2022-11-23
0 0