Export

Export all your documents with one request

The export endpoint allows you to export all your project's documents in a dataset.

To get all documents by dataset, request the following URL:

https://<projectId>.api.sanity.io/v2021-03-25/data/export/<dataset>/

For example, if your project id is zp7mbokg and your dataset name is production, the export endpoint URL will be https://zp7mbokg.api.sanity.io/v2021-03-25/data/export/production/.

The export endpoint has an optional parameter to export specified document types, provided as a comma-delimited list of type names.

https://<projected>.api.sanity.work/v2021-03-25/data/export/<dataset>?types=type1,type2

This endpoint returns a node-stream of NDJSON data. You can write this directly to a file by running this in your command-line interface:

curl https://<projectId>.api.sanity.io/v2021-03-25/data/export/<dataset>/ > backup.ndjson

curl https://<projectId>.api.sanity.io/v2021-03-25/data/export/<dataset>?types=author,book > backup.ndjson

An unauthenticated request will only return publicly available documents. If you include an authentication token, it will include documents that this token can access (for example, drafts and system documents).

Protip

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.

Was this article helpful?