
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeThe issue you're experiencing is likely due to the API perspective you're using. Your query *[_type=='article' && !(_id in path('drafts.*'))] is correctly written to filter out drafts, but it might not be working as expected because of how Sanity's API handles perspectives.
As of the recent API changes (v2025-02-19), the default perspective for API queries is now published, which means you shouldn't be seeing drafts at all by default. However, if you're explicitly using the previewDrafts perspective or have authentication credentials in your query, the API will automatically return drafts instead of published documents when both exist.
You have a few options:
1. Use the published perspective explicitly
Add the perspective parameter to your API URL:
https://*******.api.sanity.io/v1/data/query/pre-prod?query=*[_type=='article']&perspective=published
When using the published perspective, you don't need the draft filter at all - the API will only return published documents automatically.
2. If you need the previewDrafts perspective but want to exclude drafts
Your filter syntax needs a small adjustment. Try using path('drafts.**') (with double asterisks):
*[_type=='article' && !(_id in path('drafts.**'))]3. Alternative draft filtering approach
You can also filter by checking if the _id starts with "drafts.":
*[_type=='article' && !(_id match 'drafts.*')]The draft documents system in Sanity stores drafts and published versions as separate documents. When you use previewDrafts perspective (common in preview environments), Sanity intelligently returns the draft version when it exists, otherwise falling back to the published version. This is great for previews but can be confusing when you explicitly want to exclude drafts.
The most reliable approach is to use the perspective=published parameter, which ensures you only get published content without needing any draft filtering in your query.
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.
Content operations
Content backend


The only platform powering content operations
By Industry


Tecovas strengthens their customer connections
Build and Share

Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag store