
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeI'm really sorry to hear you accidentally wiped your products! The good news is that yes, you can restore deleted documents in Sanity if they were deleted within your plan's history retention period.
If you still have the document IDs, you can restore individual documents directly through the Studio:
https://YOUR-PROJECT.sanity.studio/YOUR-DATASET/YOUR-DOC-TYPE/YOUR-DOC-IDFor restoring multiple products programmatically, you'll need to use the History API. Here's the approach based on a successful community recovery:
Step 1: Get the transaction ID of the deletion event
GET https://YOUR-PROJECT.api.sanity.io/v1/data/history/YOUR-DATASET/transactions
Step 2: Find the documents that were deleted in that transaction
GET https://YOUR-PROJECT.api.sanity.io/v1/data/history/YOUR-DATASET/transactions/TRANSACTION-ID?excludeContent=true&reverse=true
Step 3: For each deleted document, get its last revision before the deletion. The key insight is that you need to query the transaction before the deletion transaction to get the actual document content.
Step 4: Use the JavaScript client's createOrReplace() method to restore each document with the retrieved content.
A community member successfully restored 400 accidentally deleted documents using this exact approach. The tricky part is that querying the deletion transaction itself returns empty documents, so you need to get the previous transaction for each document.
History retention depends on your plan (as detailed in the history documentation):
If your deletion happened outside your retention window, the history is permanently gone.
Before making bulk changes, always export your dataset as a backup using the CLI export command:
sanity dataset export production backup-before-changes.tar.gzYou can then restore if something goes wrong:
sanity dataset import backup-before-changes.tar.gz productionConsider setting up automated backups using GitHub Actions or scheduled scripts, especially for production environments, since Sanity doesn't provide built-in backup storage.
Good luck with the recovery! If you're within your retention period, you should be able to get everything back.
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