Where to place data import file and why documents aren't appearing in Studio
Looking at the guide you're following, I can help clarify the confusion about file placement and why your documents aren't appearing in Studio.
Where to put your import script:
Your import script (dataCall.js) should NOT go in the schema folder. The schema folder is specifically for defining your content types. Instead, you should:
- Create your import script in the root of your Sanity project or in a separate
/scriptsfolder - Run it as a standalone Node.js script from your terminal, not as part of the schema
For example:
my-sanity-project/ ├── schemas/ │ └── schema.js (your schema definitions only) ├── scripts/ │ └── dataCall.js (your import script) └── sanity.config.js
Why documents aren't showing in Studio:
The most likely issue is that your document _type doesn't match your schema. When you create documents, the _type field must exactly match a document type name defined in your schema. For example:
// In your schema
{
type: 'document',
name: 'catBreed', // This name matters!
fields: [...]
}
// In your import script
{
_id: 'imported-cat-1',
_type: 'catBreed', // Must match the schema name exactly
// ... other fields
}How to properly run the import:
- Install the Sanity client in your project:
npm install @sanity/client node-fetch- Create a separate import script (e.g.,
scripts/import.js):
const sanityClient = require('@sanity/client')
const fetch = require('node-fetch')
const client = sanityClient({
projectId: 'your-project-id',
dataset: 'your-dataset',
token: 'your-write-token',
useCdn: false
})
// Your fetch and transform logic here
// Then use client.createOrReplace() to create documents- Run it from your terminal:
node scripts/import.jsCommon gotchas:
- Make sure your token has write permissions (generate one at manage.sanity.io)
- Verify the
_typein your documents matches your schema exactly (case-sensitive) - Check that your schema is properly registered in
sanity.config.js - If documents exist in queries but not in Studio, restart your Studio (
sanity dev)
The guide you're following shows the complete process - the key is that importing is a separate operation from defining schemas. You define the schema first, then run a standalone script to populate data that conforms to that schema.
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.