Can deleted documents be restored in Sanity preview datasets?

1 replies
Last updated: Jun 19, 2023
hey! one of my clients deleted a document from a preview dataset and is wondering if this can be restored. My understanding is that deleted documents cannot be restored but I’m wondering if that’s still the case? I know that with the standard plan there is a 3 day retention on changes but is this history wiped out if the document is deleted?
AI Update

Good news! Deleted documents can be restored from a preview dataset (or any dataset), but only if they're still within your plan's history retention period.

Here's what you need to know about the Standard (Growth) plan:

History Retention:

  • Growth Plan: 90 days of history retention
  • Free Plan: 3 days
  • Enterprise Plan: 365 days (customizable)

Important: The history is not wiped out when a document is deleted. The deletion itself is just another event in the document's history. As long as the deletion happened within your retention period (90 days for Growth plan), the document and all its previous versions remain recoverable.

How to restore a deleted document:

  1. Via Studio URL: Navigate directly to the document using its _id:

    https://your-project.sanity.studio/desk/yourDocumentId

    You can access the document history and restore it from there.

  2. Via History API: Use the History API to programmatically fetch the document's last version before deletion, then use the client's createOrReplace() method to restore it.

There's also a helpful community guide for creating a "bin" for restoring deleted documents that makes this process easier.

After the retention period: Once the 90 days pass, older revisions are permanently deleted and cannot be recovered. However, note that if you upgrade your plan, it extends the retention period going forward but doesn't restore previously deleted history.

So yes, your client should be able to restore that deleted document as long as it was deleted within the last 90 days!

Show original thread
1 reply
Update: I was able to restore my document by creating a new document of the same id using the CLI
create
command

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.

Was this answer helpful?