
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeThe issue you're experiencing is due to an incorrect reference structure when creating documents programmatically. You're using _id when you should be using _ref.
Your current code:
author: {
_id: response._id, // ❌ Wrong property name
_type: 'reference'
}This creates malformed reference data that Sanity Studio cannot recognize, which is why the selection appears empty and you can't select the referenced document.
The correct structure for a reference field is:
author: {
_type: 'reference',
_ref: response._id // âś… Correct - use _ref, not _id
}Here's the proper way to create documents with references:
import {createClient} from '@sanity/client'
const client = createClient({
projectId: 'your-project-id',
dataset: 'your-dataset-name',
useCdn: false,
apiVersion: '2023-05-03',
token: process.env.SANITY_SECRET_TOKEN
})
// 1. Create document A
const docA = await client.create({
_type: 'A',
// ... other fields
})
// 2. Create document B with reference to A
const docB = await client.create({
_type: 'B',
author: {
_type: 'reference',
_ref: docA._id // Use _ref property
}
})According to the Sanity reference type documentation, a reference field must have:
_type: 'reference' - identifies this as a reference type_ref: 'document-id' - contains the ID of the referenced documentThe _ref property is what Sanity uses to establish the relationship between documents. Using _id instead creates invalid reference data that Studio cannot interpret.
drafts. prefix)weak: true in your schema definition_ref, existing documents with _id will need to be corrected - you can do this with a migrationOnce you update your code to use _ref instead of _id, Studio will properly recognize the references and allow you to view and select the referenced documents.
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