🔮 Sanity Create is here. Writing is reinvented. Try now, no developer setup

Clarification on using the mutate API to draft posts in Sanity.io

6 replies
Last updated: May 28, 2020
hey could someone clarify whether the mutate api allows drafting (but not publishing) posts? https://www.sanity.io/docs/http-mutations#patch-2f480b2baca5
i've been getting 500 errors when testing out this api and im not entirely sure why.
May 27, 2020, 7:25 PM
the only reason i can think of is maybe i am not sending all required fields in the document?
May 27, 2020, 7:25 PM
oh was able to get the post request working, but weird that
create
still goes through when all the required fields are not provided.
May 27, 2020, 7:31 PM
it'd be great if someone could clarify if i could "draft" only with this api! 🙂
May 27, 2020, 7:31 PM
for now i am just going to prefix the
_id
field with
drafts.
which seems to work pretty well! feel free to lmk if this is an anti-pattern or if there is a better way.
May 27, 2020, 8:20 PM
Hi Yihwan, you’re correct! Prefixing with
drafts.
is indeed the way to go and not considered an anti-pattern 🙂
May 28, 2020, 11:18 AM
Regarding the required fields - validation currently happens on the client side only, so any rules you define in your Studio will not be used for server side validation when using the HTTP API. You would have to set up additional validation for these yourself, unfortunately.
May 28, 2020, 11:20 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?