Restoring accidentally deleted documents in Sanity dataset without exporting.
I'm really sorry to hear about your products getting wiped! The good news is that yes, you can likely restore them using Sanity's document history system, as long as the deletion happened within your plan's retention period.
Quick Recovery Steps
The fastest way to restore your deleted products is through the History API. Here's what you need to know:
First, check your retention window:
- Free plan: 3 days
- Growth plan: 90 days
- Enterprise plan: 365 days
If your deletion happened within this window, your data is still recoverable!
How to Restore Deleted Documents
Even though documents are deleted, you can still access them if you know their _id. You have two main options:
Option 1: Via Studio URL (Manual)
- Navigate directly to the document using its ID in your Studio URL:
https://your-studio.sanity.studio/desk/yourDocumentType;documentId - Once there, you can view the document history and restore it
Option 2: Programmatically (Recommended for bulk restoration)
Use the History API to retrieve previous versions of your deleted products, then restore them using the JavaScript client's createOrReplace() method with the entire document from the history API as the payload.
Here's a basic approach:
- Query the History API to get the previous state of your products
- Use the
_revproperty to identify the revision you want to restore - Use
client.createOrReplace()with the retrieved document data
You can find detailed guidance on this process in the restoring deleted documents guide and these community answers about restoring accidentally deleted documents.
Important Notes
- The latest version of both published and draft documents always remains available, even after the retention period
- History beyond your retention period is permanently deleted, so act quickly
- Sanity stores all document patches as transactions in the Content Lake, creating a complete revision history that tracks who made changes and when
If you're on a Free plan and it's been more than 3 days, or if you need help with the restoration process, I'd recommend reaching out to Sanity support directlyāthey may be able to help depending on your situation.
Show original thread34 replies
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.