Export
Base API server URL
Sanity project base URL
https://{projectId}.api.sanity.io/{apiVersion}
Variables
- projectIdstringdefault:
"your-project-id"
Sanity project ID
- apiVersionstringdefault:
"v2021-03-25"
API version
/data/export/{dataset}
The Export API allows you to export all the non-deleted documents in a dataset, including drafts and asset documents.
By default, this endpoint returns all the documents a user can access as an NDJSON stream. The documents will be in the state they were when the request was made and will not be affected by any changes in the dataset that happened after the request was made.
In most cases, you probably want to use the CLI tool's export functionality or the JavaScript npm package. Those have built-in features such as asset downloads and an option for including drafts.
For datasets with many documents (typically tens of thousands), you can experience that network or other instabilities cause the export stream to time out or be interrupted. In these cases, you can send a request a nextCursor query parameter set to an empty string. This will cause the export to run for 30 seconds and end with an object with a nextCursor key and value. 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 nextQuery parameter value to continue the export manually. Note that any changes made between requests in "cursor mode" will be reflected in the export, which can lead to inconsistencies, for example, if references have been changed in the dataset.
Tip: An unauthenticated request will only return publicly available documents. If you include an authentication token, it will consist of documents that this token can access (for example, drafts and system documents).
Returns an NDJSON stream of documents.
A stream of documents in NDJSON format.
{"_id":"doc-5","_type":"counter","count":10} {"_id":"doc-6","_type":"counter","count":11} {"nextCursor":"taZ9fp"}