Unlock seamless workflows and faster delivery with our latest releases – get the details

How to Differentiate between an Unpublished Document and a Published Draft from the API

7 replies
Last updated: Nov 21, 2024
Is there a way to differentiate between an
unpublished
document and a
published draft
from the sanity api?
Apr 30, 2020, 8:08 PM
oh actually, just realized that the draft creates a duplicate document - very clever
Apr 30, 2020, 8:10 PM
🙌 There's more about it here: https://www.sanity.io/docs/drafts
Apr 30, 2020, 8:21 PM
thanks
user Y
! 🎉
Apr 30, 2020, 8:50 PM
In the Studio interface, though, in the document list, there is no visual way to know which are draft vs published draft, is there?
Apr 30, 2020, 9:42 PM
like this?
Apr 30, 2020, 9:42 PM
Right, but if it's already published, and now is a new draft vs a non-published draft.
Apr 30, 2020, 11:42 PM
For anyone landing on this article from the public internet, it's probably a good idea to join the slack community. In there, you'll find more similar questions to this one, and you're more likely to end up finding the solution you're looking for.
For me, it was this query to find *unpublished drafts*:

*[_type == "yourSchemaType" && _id in path("drafts.**") && count(*[^._id == "drafts." + _id]) == 0]{_id}
Nov 21, 2024, 12:32 PM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?