Export API reference
Reference documentation for the export HTTP endpoint.
The Export API lets you export all the non-deleted documents in a dataset, including drafts, release versions, and asset documents.
Authentication
- Requests without a token return only publicly available documents. To export drafts and private documents, authenticate the request.
Base API server URL
Sanity project base URL
https://{projectId}.api.sanity.io/{apiVersion}Variables
- projectIdstringdefault:
"your-project-id"Sanity project ID
- apiVersionstringdefault:
"v2025-02-19"API version
Endpoints
Export documents in a dataset
/data/export/{dataset}The Export API lets you export all the non-deleted documents in a dataset, including drafts, release versions, and asset documents.
By default, this endpoint returns all the documents a user can access as a newline-delimited JSON (NDJSON) stream. The documents are in the state they were in when the request was made and are not affected by any changes in the dataset that happened after the request was made. The stream doesn't return documents in any guaranteed order.
In most cases, use the sanity datasets export CLI command or the @sanity/export npm package instead. Those have built-in features such as asset downloads and an option to exclude drafts. @sanity/export also supports cursor mode (mode: 'cursor') and follows the cursors for you.
Cursor mode for large datasets
For datasets with many documents (typically tens of thousands), network or other instabilities can cause the export stream to time out or be interrupted. In these cases, you can send a request with a nextCursor query parameter set to an empty string. The export runs for up to 30 seconds and returns documents ordered by _id. If the time runs out before the export finishes, the stream ends with a {"nextCursor": "..."} object. The cursor is an encoded representation of a position in an ordered document list of the dataset.
You can initiate a new export request with this value as the nextCursor parameter value to continue the export manually. The export is complete when a stream ends without a nextCursor object and without an error object (see below). The final request can return an empty stream. Note that any changes made between requests in "cursor mode" are reflected in the export, which can lead to inconsistencies, for example, if references have been changed in the dataset.
Errors during the stream
The response status is sent before the stream starts. If an error occurs after the first document is sent, the status stays 200 and the stream ends with an error object instead of a document, for example {"error":{"description":"Internal server error","type":"internalError"}}. Check the last line of every stream for an error key before treating the export as complete.
Authentication
An unauthenticated request returns only publicly available documents. If you include an authentication token, the export contains the documents that this token can access (for example, drafts, release versions, and system documents).
An unauthenticated request to a private dataset doesn't return an error. It returns a 200 response with an empty stream.
Path parameters
The name of the dataset to export.
Query parameters
- typesstring
A comma-separated list of document types to include in the export. Each value must match a document's
_typeexactly; wildcards aren't supported. To include asset documents, addsanity.imageAssetorsanity.fileAsset.An empty value (
types=) exports all document types.Example:post,author,sanity.imageAsset - nextCursorstring
The cursor to continue the export from. Set to an empty string to start a new export in "cursor mode".
Cursor mode inserts a
{"nextCursor": "..."}object into the stream. - tagstring
A tag to identify the request in request logs.
Responses
Returns an NDJSON stream of documents.
If an error occurs after the stream starts, the status stays 200 and the stream ends with an error object.
- string (binary)
A stream of documents in NDJSON format.
application/x-ndjson{"_id":"doc-5","_type":"counter","count":10}
{"_id":"doc-6","_type":"counter","count":11}
Returned when the request sets `nextCursor` and the time window ends before the export finishes. Send the `nextCursor` value in the next request to continue.
{"_id":"doc-5","_type":"counter","count":10}
{"_id":"doc-6","_type":"counter","count":11}
{"nextCursor":"taZ9fp"}
Returned when an error occurs after the first document is sent. The export is incomplete.
{"_id":"doc-5","_type":"counter","count":10}
{"error":{"description":"Internal server error","type":"internalError"}}
The request is invalid. Causes include:
- An invalid
nextCursorvalue. - The
types,nextCursor, ortagparameter appears more than once. - An unknown query parameter. For example,
drafts=falseis rejected, not ignored.
- errorobject
Show child attributes
- descriptionstring
A description of the error.
- typestring
The error type.
- namesarray
For unknown query parameters, the names of the rejected parameters.
Show child attributes
items
- string
application/json{
"error": {
"description": "invalid cursor value \"not-a-cursor\".",
"type": "httpBadRequest"
}
}{
"error": {
"description": "Unknown query parameter \"drafts\"",
"names": [
"drafts"
],
"type": "httpUnknownQueryStringParameters"
}
}The request includes a token that isn't valid.
- errorobject
Show child attributes
- descriptionstring
A description of the error.
- typestring
The error type.
- namesarray
For unknown query parameters, the names of the rejected parameters.
Show child attributes
items
- string
In cursor mode, the 30-second time window ended before the export read any documents. Retry the request with the same nextCursor value.
- errorobject
Show child attributes
- descriptionstring
A description of the error.
- typestring
The error type.
- namesarray
For unknown query parameters, the names of the rejected parameters.
Show child attributes
items
- string