Document Service API: Usage with Draft & Publish
By default the Document Service API returns the draft version of a document when the Draft & Publish feature is enabled. This page describes how to use the status
parameter to:
- return the published version of a document,
- count documents depending on their status,
- and directly publish a document while creating it or updating it.
Note
Passing { status: 'draft' }
to a Document Service API query returns the same results as not passing any status
parameter.
Get the published version with findOne()
findOne()
queries return the draft version of a document by default.
To return the published version while finding a specific document with the Document Service API, pass 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
// …
}