😎 Discover cool tips and tricks for customization in our next Developer Deep Dive virtual event - sign up now!

Where to Find the User-Token for deleteUnusedAssets.js

12 replies
Last updated: May 11, 2020
I’m trying to delete an image in the studio running this script https://github.com/sanity-io/sanity-recipes/blob/master/snippets/deleteUnusedAssets.js and I need to pass a
user-token
. I’m not sure where to find this?
May 10, 2020, 12:32 PM
Hi, you can create tokens at manage.sanity.io
May 10, 2020, 12:37 PM
Go to your project, then settings -> api
May 10, 2020, 12:37 PM
Ok I was confused and thought I needed to generate another token. I just added the flag
--with-user-token
and it worked.
May 10, 2020, 1:30 PM
I’m still unable to delete an asset after I run the script, it says 3 documents are using it (which correspond to older schemas I have deleted)
May 10, 2020, 1:40 PM
Yeah, you will have to delete any references to that asset to deleted it, or set those references as weak.
May 10, 2020, 2:40 PM
The problem is that I don’t have those references anymore.
May 10, 2020, 4:09 PM
I have a Stack trace:
_useDocumentOperation
is
null
when I try to resolve them
May 10, 2020, 4:17 PM
You can try to find the references by running something like:
sanity documents query "*[references('your-asset-id')]._id"
May 10, 2020, 8:02 PM
That would return the ids of all the documents using that asset
May 10, 2020, 8:02 PM
perfect it worked, thanks!
May 11, 2020, 10:18 AM
Great!
May 11, 2020, 11:33 AM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?