Skip to main content

REST API:status

🌐 REST API: status

REST API 提供根据状态(草稿或已发布)过滤结果的功能。

🌐 The REST API offers the ability to filter results based on their status, draft or published.

Prerequisites

应该启用 Draft & Publish 功能。

🌐 The Draft & Publish feature should be enabled.

查询可以接受一个 status 参数以根据其状态获取文档:

🌐 Queries can accept a status parameter to fetch documents based on their status:

  • published:仅返回文档的已发布版本(默认)
  • draft:仅返回文档的草稿版本
Tip

在响应数据中,publishedAt 字段对于草稿来说是 null

🌐 In the response data, the publishedAt field is null for drafts.

Note

由于默认返回已发布版本,因此不传递状态参数等同于传递 status=published

🌐 Since published versions are returned by default, passing no status parameter is equivalent to passing status=published.



获取餐厅草稿版本

GET /api/articles?status=draft

JavaScript 查询(使用 qs 库构建):

上面的查询 URL 是使用 `qs` 库 构建的。qs 可以在你的本地机器上运行,如以下代码示例所示,或者你也可以使用我们的 交互式查询构建器 在线工具。

🌐 The query URL above was built using the `qs` library. qs can be run locally on your machine, as shown in the following code example, or you can use our interactive query builder online tool.

const qs = require('qs');
const query = qs.stringify({
status: 'draft',
}, {
encodeValuesOnly: true, // prettify URL
});

await request(`/api/articles?${query}`);
示例响应
{
"data": [
// …
{
"id": 5,
"documentId": "znrlzntu9ei5onjvwfaalu2v",
"Name": "Biscotte Restaurant",
"Description": [
{
"type": "paragraph",
"children": [
{
"type": "text",
"text": "This is the draft version."
}
]
}
],
"createdAt": "2024-03-06T13:43:30.172Z",
"updatedAt": "2024-03-06T21:38:46.353Z",
"publishedAt": null,
"locale": "en"
},
// …
],
"meta": {
"pagination": {
"page": 1,
"pageSize": 25,
"pageCount": 1,
"total": 4
}
}
}