Sanity Export Documents: OAuth vs Internal API Token Authentication
Good news! You don't need to set up OAuth for using the export documents endpoint. A simple internal API token will work perfectly fine.
Here's what you need to do:
Using an API Token with the Export Endpoint
The export endpoint accepts standard API token authentication. You can create a token through your project's API settings and include it in your request using the Authorization header with a Bearer token format.
Creating Your Token
- Go to your project at sanity.io/manage or run
npx sanity@latest managefrom your CLI - Navigate to the "API" tab
- Create a new token with appropriate permissions:
- Viewer role for read-only access (sufficient for exports)
- Or a custom role if you need specific permissions
Using the Token
Include your token in the Authorization header when making requests:
Authorization: Bearer YOUR_TOKEN_HERE
The endpoint URL format is:
https://{projectId}.api.sanity.io/{apiVersion}/data/export/{dataset}Important Security Note
Unauthenticated requests will only return publicly available documents. When you include an authentication token, you'll get access to all documents that token has permissions for, including drafts and system documents.
Alternative: Use the CLI or npm Package
For most use cases, you'll probably want to use the Sanity CLI's export functionality (sanity dataset export) or the @sanity/export npm package. These have built-in features like asset downloads, draft inclusion options, and automatic handling of cursor mode for large datasets.
The token approach is much simpler than OAuth and is the standard way to authenticate with Sanity's HTTP API for programmatic access!
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.