Replace Document Asset
A 3-step recipe with Sanity. We can help you get access.
Recipe · 3 steps
Replace Document Asset
with Sanity
Swap a document's image to a newly uploaded asset reference.
- Upload the replacement image and capture its asset document id.
- Read the target document by id to confirm it exists before patching.
- Patch the document's image field so its asset reference points at the newly uploaded asset.
What you'll need to have ready
- projectId: The Sanity project id that scopes the API endpoint.
- apiToken: Sanity project API token used as a Bearer credential.
- dataset: Dataset name holding the document and receiving the asset.
- documentId: The _id of the document whose image asset is being replaced.
- imageBinary: Raw binary image content for the replacement asset.
- filename: Optional original filename to record on the asset.
For your developer
Arazzo workflow sanity:replace-document-asset, 3 operations: uploadImageAsset → queryDocumentsPost → mutateDocuments. Specs on APIs.io.