Getting latest draft via HTTP API
Absolutely! You can get draft content through the HTTP API using the perspective parameter. Sanity has built-in support for this via their Perspectives feature.
Here's how it works:
Using the previewDrafts perspective
The easiest way to get the latest draft is to use the previewDrafts perspective, which prioritizes draft documents over published versions:
/v2025-02-19/data/query/YOUR_DATASET?query=*[]&perspective=previewDrafts
This will return draft versions when they exist, and fall back to published content when no draft is available.
Available perspectives
You have several options depending on your needs:
previewDrafts- Returns drafts when available, falls back to published (perfect for preview environments)published- Returns only published content (default as of API version 2025-02-19)raw- Returns all documents including both drafts and published versionsdrafts- Returns content as if all drafts were published (useful for preview)
Important notes
- CDN caching: When using draft perspectives, you must set
useCdn: falsein your client configuration or avoid the CDN in your HTTP requests, since draft content should never be cached - Authentication: You'll need an authenticated request (with a valid token) to access draft content
- Draft ID pattern: Draft documents have IDs prefixed with
drafts.(e.g.,drafts.post-123vspost-123)
Using with the JS/TS client
If you're using @sanity/client, you can configure it like this:
import {createClient} from '@sanity/client'
const client = createClient({
projectId: 'your-project-id',
dataset: 'your-dataset',
useCdn: false, // Required for drafts
perspective: 'previewDrafts',
token: 'your-token' // Required for authentication
})This is similar to how other headless CMSs handle drafts (like Contentful's preview API, Strapi's publicationState=preview, or Storyblok's version=draft), but Sanity's perspective system is more flexible and works consistently across all queries.
Check out the full Perspectives documentation and the guide on presenting and previewing content for more details!
Show original thread1 reply
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.