
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeThe issue you're encountering is that you're trying to import and use the Sanity client incorrectly within the Structure Builder. The getDocument method doesn't exist directly on the client import - you need to properly instantiate the client first.
Here's how to fix it:
Option 1: Create a properly configured client instance
import {createClient} from '@sanity/client'
const client = createClient({
projectId: 'your-project-id',
dataset: 'your-dataset',
useCdn: false, // Use false for fresh data in the Studio
apiVersion: '2024-01-01' // Use current date
})
client.fetch(`*[_id == "tags"][0]`).then(tags => {
console.log(tags.tagArray)
})Option 2: Use the client that's already available in Studio context
If you're working within a Structure Builder configuration file, you can access the client through the context:
import {structureTool} from 'sanity/structure'
export default {
plugins: [
structureTool({
structure: (S, context) => {
// Access client from context
const {getClient} = context
const client = getClient({apiVersion: '2024-01-01'})
// Now fetch your data
client.fetch(`*[_id == "tags"][0]`).then(tags => {
console.log(tags.tagArray)
})
return S.list()
.title('Content')
.items([...])
}
})
]
}Important notes:
fetch() not getDocument() - you query documents using GROQ queriesprojectId, dataset, and apiVersionThe createClient function is the correct way to instantiate the Sanity Client, which then gives you access to methods like fetch() for querying your content.
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