How to fix Shopify sync error after removing store and token from Sanity?

21 replies
Last updated: May 20, 2022
Hi guys,
Yesterday I tryed shopify connect with sanity, and I removed the store and token but now I get this when I try to delete some of the products. How can resolve this?
AI Update

This is a common issue that happens when Shopify Connect creates documents with references between them, and then you disconnect Shopify but the references remain in your Sanity dataset.

The error message is telling you that the product you're trying to delete is referenced by 2 other documents. Sanity prevents you from deleting documents that are referenced elsewhere as a safety measure to maintain data integrity.

Here's how to resolve this:

Find the referencing documents

Use the Vision plugin in your Studio to find all documents that reference the one you're trying to delete. Run this GROQ query:

*[]{_id, title, "references":*[references(^._id)]}[length(references)>0]

This will show you which documents are holding references to the document you want to delete.

Remove the references

You have a few options:

  1. Through the Studio UI: Open each referencing document and manually remove the reference fields. However, based on the thread you linked, it sounds like the Studio might crash when trying to access these documents.

  2. Delete the referencing documents first: If you don't need those documents either, delete them first, then delete the product.

  3. Use a migration script: If the Studio crashes or you have many references to clean up, you can write a migration script to programmatically unset the references or delete the documents.

  4. Nuclear option: As mentioned in the thread, if this is a development project and you don't need any of the data, you can delete the entire dataset and start fresh through your project settings at manage.sanity.io.

The most likely scenario is that Shopify Connect created product variant documents or image asset documents that reference each other, and those references need to be cleaned up before deletion is possible.

Show original thread
21 replies
You are trying to delete a document which is referenced by 2 other documents, which is not possible for security reasons. Open these documents in the studio, and remove the reference to the document you are trying to delete.
This is what the error message is telling you.
It can't be, There is no document with that ref ???
It is not even connected with shopify anymore
This has nothing to do with Shopify I'm afraid. It's about linked documents in your studio, as the dialog and the error indicate.
well how do I remove a reference? in my studio it looks like this:
Errr, do you have other document types? Like pages or something maybe? Or do you only have products?
No only products at this point
I found this
is there a media library somewhere I can acces ?
media library gives me errors
and I still dont know how to fix the ref error
this is what I get when I click on the img Ref
the document with
_id
:
e1887e01-fd78-9a12-67fccbc43372
needs to be deleted in order to delete the product you are trying to delete. 🙂 In order to get all documents that have references you can put the following query into vision:
*[]{_id, title , "references":*[ references(^._id)]}[length(references)>0]

If the studio crashes when you attempt to access them with the GUI, you might have to delete them with a script instead. Is there any particular reason you want to delete these products or are you simply attempting to learn more about Sanity?
You might not have to delete the document with that
_id
, but you would need to unset the reference. In practical terms this means finding the links to other documents and deleting the links in the studio.
I hooked Shopify to it and it added some products to my studio that didnt go as planned and so I disconnected it but the ref is still there for some reason. I just put that query you gave me in vision and its not crashing. but I need to clean it up so I can add my own files.
I cant remove the files and it enoys me
This is a real problem if you cant remove it in the studio
the data is still in the back but you just cant reach it
nvm I deleted the whole dataset

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?