
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeTo call the Sanity Export Data API using Node.js, you'll need to authenticate your request with an API token. Here's how to get set up:
You need to create an API token in your Sanity project management interface:
Access Sanity Manage by running npx sanity@latest manage from your project directory, or access it from your Studio menu
Navigate to the "API" tab
Create a new token and assign it appropriate permissions:
Copy the token and store it securely in your environment variables
Here's how to call the export API in Node.js:
import https from 'https';
const projectId = 'your-project-id';
const dataset = 'production'; // or your dataset name
const token = process.env.SANITY_API_TOKEN; // Store your token in env vars
const apiVersion = 'v2021-03-25';
const options = {
hostname: `${projectId}.api.sanity.io`,
path: `/${apiVersion}/data/export/${dataset}`,
method: 'GET',
headers: {
'Authorization': `Bearer ${token}`
}
};
const req = https.request(options, (res) => {
res.on('data', (chunk) => {
// Process NDJSON stream
console.log(chunk.toString());
});
});
req.on('error', (error) => {
console.error(error);
});
req.end();For most export use cases, you might find it easier to use the Sanity CLI's built-in export command, which handles authentication automatically if you're logged in:
sanity dataset export production export.ndjsonThe full Export API documentation is available at the Sanity Export API reference.
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