🎤 Builder Talk: The Story Behind Lady Gaga’s Digital Experience – Register now

How to perform a "publish" through the API/JavaScript client in Sanity.io

2 replies
Last updated: Jul 21, 2020
Is there a way to perform a “publish” through the API/JavaScript client? (We’d like to add a “publish all drafts” button)
Jul 21, 2020, 8:43 AM
One way to accomplish this would be using the
@sanity/react-hooks
package to run a
publish.execute()
operation using
useDocumentOperation(id, type)
- https://www.sanity.io/docs/studio-react-hooks#usedocumentoperation-c3cb2ad19cf3
Or you could probably just remove the
drafts.
prefix from the
_id
value to achieve the same 🙂
Jul 21, 2020, 9:58 AM
ah thanks peter, I’ll take a look
Jul 21, 2020, 10:29 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?

Related answers

Get more help in the community Slack

TopicCategoriesFeaturedRepliesLast Updated
Filtering out duplicate slugs after a large data importSep 8, 2020
Modifying a string value via a callback in JavaScriptJun 16, 2020
I’m experiencing an error when trying to deploy `sanity graphql deploy` and getting this error point towards a node_module ```import...Jan 16, 2021
Gatsby site crashing with cryptic error, resolved by adjusting resolveReferences depthAug 18, 2020
Browsing raw data and wiping all data in a Sanity instance discussed.Apr 28, 2020
Updating object properties in an array on a document with the Sanity clientMar 17, 2021
Discussing Sanity and Shopify integration, speed optimization, and alternativesSep 9, 2021
Making GROQ params optional in Next.js frontend API endpoint queryJan 19, 2022
Error in React/Sanity tutorial code, resolved with missing comma in querySep 29, 2021
Creating datasets with public and private documents and accessing them in the CMS.Sep 6, 2020

Related contributions

Turbo Start Sanity
- Template

The battle-tested Sanity template that powers Roboto Studio's websites

Go to Turbo Start Sanity

Schema UI - Next.js Sanity Starter
- Template

A Next.js starter template with Next.js 15, Tailwind CSS, shadcn/ui, and Sanity CMS with Live Editing. Get production-ready React components with matching Sanity schemas and queries. Build dynamic pages faster while keeping full control over customization.

Serge Ovcharenko
Go to Schema UI - Next.js Sanity Starter

The Swaddle
- Made with Sanity

A new brand identity to represent a more mature company, to signify The Swaddle’s evolution from publisher to production house, combined with an easier to navigate platform that can surface multiple content types - drawing readers through The Swaddle’s content offering.

Nightjar
Go to The Swaddle