Unlock seamless workflows and faster delivery with our latest releases ā€“ get the details

Creating draft edits programmatically with the Sanity client for JavaScript

5 replies
Last updated: Aug 3, 2022
Hi All!
Is there a way to create a draft edit programatically with the sanity client for javascript. Create or replace works in creating a draft update but this then triggers the create event for a webhook.

I want to use patch to trigger the edit event for my webhook but I don't seem to be able to make patch create a draft update.
May 18, 2022, 2:39 PM
A draft is just a document with an ID starting with
drafts.
, so you could make your patch set your ID as a draft?
May 18, 2022, 2:42 PM
Good call Kitty šŸ™Œ
May 18, 2022, 6:24 PM
Ah it looks like I can't use this as a workaround as I get this error using patch:

immutable attribute \"_id\" may not be modified
May 19, 2022, 10:17 AM
user C
user Y
I have the same problem, did you solve it?
Jul 29, 2022, 9:38 AM
user U
I didn't find anything for a work around so I just used post to create a new doc with the same draft ID which overwrites the original.
Aug 3, 2022, 8:56 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?