Clarification on creating drafts from a published document in Sanity.io.
Great question! Let me break down how drafts work and address your specific concerns about converting published documents to drafts.
Understanding Drafts vs Published Documents
In Sanity, drafts and published documents are separate entities in your dataset. A draft has an _id prefixed with drafts. (e.g., drafts.abc-123), while the published version has the plain ID (e.g., abc-123). When both exist, you have a published document with unpublished changes.
Using createIfNotExists to Create a Draft
Yes, using createIfNotExists with the drafts. prefix is the correct way to create a draft from an existing published document! It doesn't create an unrelated document—as long as you use the right ID format, Sanity recognizes the relationship.
Here's how to do it:
// To convert a published document to draft state
const publishedId = 'abc-123'; // your published document ID
client.createIfNotExists({
_id: `drafts.${publishedId}`,
...publishedDocumentData // copy the published document's data
})When you create a draft with _id: drafts.abc-123, Sanity understands this is the draft version of the published document abc-123. When someone publishes from the Studio, it will merge the draft with the published version.
You Cannot Patch a Published Document into a Draft
You're correct—you cannot use patch to convert a published document into a draft state. The draft/published relationship is based on having two separate documents with the proper ID convention, not a status field you can patch.
The Workflow
- Create the draft using
createIfNotExistswith thedrafts.prefix - The published document remains unchanged and live
- In the Studio, editors will see the draft indicator
- When they publish from the Studio, the draft overwrites the published version
Important Consideration
One thing to be aware of: if external systems update the published document while a draft exists, publishing the draft can overwrite those external changes. Make sure your workflow accounts for this—you might want to copy the latest published data when creating the draft to avoid losing recent updates.
So yes, createIfNotExists with the drafts. prefix is exactly the right approach for what you're trying to do!
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.