See Sanity in action 👀 Join us for a live product demo + Q&A →

How to use mutation API for Sanity Studio without authentication

7 replies
Last updated: Feb 2, 2023
Hey, I want to use mutation api for sanity studio without authentication. In other words, I want to make a specific document unprotected and I want update it with a api call from anywhere.Can anyone please guide me how to achieve this if it is possible?

Thanks ^^
Feb 1, 2023, 9:59 AM
can’t do that but you can add a API route thats unprotected and only mutates that document
Feb 1, 2023, 10:15 AM
Than you
user A
,Can you show a example or elaborate more on how to do so?
Feb 1, 2023, 10:21 AM
Do you use Next.js?
Feb 1, 2023, 10:26 AM
Anyways something like this:


const documentId = ""

export const handler = (req, res) => {
  const mutation = req.body;

  await authClient.patch(documentId, mutation).commit()

  res.status(200)
}
Not sure the use case for this though as anyone can overwrite anything any time.
Feb 1, 2023, 10:28 AM
I want to hit Mutate API from a third party site wich is public and no auth is implemented.
I just want to keep track of clicks on specific links.

Is it possible without authenticating user?
Feb 1, 2023, 10:31 AM
This is not possible. All write requests to your dataset require authentication.
Feb 1, 2023, 5:37 PM
Thank you
user M
for confirming this.
Feb 2, 2023, 5:10 AM

Sanity.io – build remarkable experiences at scale

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