
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeBased on the documentation I reviewed, I need to give you an important heads-up about using dots in document IDs like private.document-xxxxx:
Documents with dots in their IDs become private and only accessible via authenticated requests. This is a critical limitation that fundamentally changes how your content works in Sanity.
While you can technically create documents with custom IDs like private.document-xxxxx, the official documentation actually recommends against using custom IDs for most use cases. Instead, they suggest creating a custom field in your schema to store identifiers.
Here's why: once you set a document ID with a dot pattern, that document won't be publicly queryable without authentication. This might be what you want, but it's often an unexpected side effect.
If you genuinely need custom document IDs with dots, here are the legitimate ways to create them:
import {createClient} from '@sanity/client'
const client = createClient({
projectId: 'your-project-id',
dataset: 'your-dataset',
token: 'your-token', // Required for write operations
apiVersion: '2025-01-01'
})
await client.create({
_id: 'private.document-xxxxx',
_type: 'yourDocumentType',
// ... other fields
})sanity documents create --id 'private.document-xxxxx'Append ;desiredId to the Studio URL when creating a new document:
http://localhost:3333/structure/yourDocumentType;private.document-xxxxx
Initial Value Templates are configured in sanity.config.ts using document.newDocumentOptions, and while the documentation shows they can set initial values, they cannot reliably set custom _id values with dots because:
Initial Value Templates are better suited for setting field values, not document IDs.
Instead of custom IDs with dots, consider:
Option 1: Use a custom field
defineField({
name: 'customIdentifier',
type: 'string',
validation: Rule => Rule.required()
})Then query by this field instead of _id.
Option 2: Use a naming convention without dots
Use underscores or hyphens instead: private_document-xxxxx or private-document-xxxxx. These won't trigger the privacy behavior.
Option 3: Use proper access control If you need private documents, use Sanity's access control features rather than relying on ID patterns.
a-zA-Z0-9._- (up to 128 characters)_id never changesdrafts. prefix is reserved by SanityThe bottom line: if you're just looking for a way to organize or identify documents, use a custom field instead. Custom IDs with dots should only be used when you specifically need the privacy behavior they provide.
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