How to create a draft document instead of published using Sanity client mutation?
Unfortunately, there isn't a built-in way to create a document directly as a draft when using the client's create() mutation. The Sanity client's create() method will always create a published document.
Important: While you might see references to prefixing document IDs with drafts., Sanity's official documentation explicitly advises against this: "We advise against using our APIs to create document IDs prefixed with drafts. or versions. as these are used internally. Such documents may react with platform functionality in unexpected ways."
Here are the recommended approaches instead:
Option 1: Create then immediately convert to draft (via Studio) Create the document as published, then have editors open it in Sanity Studio where it will automatically create a draft version when they make edits. This is the safest approach that works with Sanity's draft system as intended.
Option 2: Use a status field
Add a status or published field to your schema to track whether content should be considered "live":
{
name: 'post',
type: 'document',
fields: [
{
name: 'title',
type: 'string'
},
{
name: 'status',
type: 'string',
options: {
list: ['draft', 'published']
},
initialValue: 'draft'
}
]
}Then filter your queries to only show published content:
*[_type == 'post' && status == 'published']Option 3: Use a separate dataset For bulk imports or programmatic content creation that needs review, consider importing to a staging dataset first, then using Sanity's dataset copy functionality to move approved content to production.
The draft system in Sanity is really designed to work through the Studio interface, where it automatically manages the relationship between published documents and their draft counterparts. Trying to manually create drafts via the API goes against how the platform is designed to work and could cause unexpected issues.
Show original thread7 replies
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.