Document Service API: 下書きと公開の扱い
下書きと公開 が有効なとき、Document Service API は既定でドキュメントの下書き版を返します。このページでは status パラメータで次を行う方法を説明します。
- ドキュメントの公開版を返す
- ステータスに応じてドキュメントを数える
- 作成または更新と同時に公開する
Note
Document Service API のクエリに { status: 'draft' } を渡した結果は、status を省略した場合と同じです。
findOne() で公開版を取得する
findOne() は既定でドキュメントの下書き版を返します。
Document Service API で 特定のドキュメントを取得 するときに公開版が欲しい場合は、status: 'published' を渡します。
Example request
await strapi.documents('api::restaurant.restaurant').findOne({
documentId: 'a1b2c3d4e5f6g7h8i9j0klm',
status: 'published'
});
Example response
{
documentId: "a1b2c3d4e5f6g7h8i9j0klm",
name: "Biscotte Restaurant",
publishedAt: "2024-03-14T15:40:45.330Z",
locale: "en", // default locale
// …
}
findFirst() で公開版を取得する
findFirst() は既定でドキュメントの下書き版を返します。
Document Service API で 最初のドキュメントを取得 するときに公開版が欲しい場合は、status: 'published' を渡します。
リクエスト例
const document = await strapi.documents("api::restaurant.restaurant").findFirst({
status: 'published',
});