Sanity CMS Error: Failed to communicate with the Sanity API

Light switch on a wall

I’ve recently started using the Sanity Content Management System and came across a particular error.

Running $sanity init in my studio folder I encountered this –

Graemes-MacBook-Pro:studio graeme$ sanity init
You're setting up a new project!
We'll make sure you have an account with Sanity.io. Then we'll
install an open-source JS content editor that connects to
the real-time hosted API on Sanity.io. Hang on.

Press ctrl + C at any time to quit.

Prefer web interfaces to terminals?
You can also set up best practice Sanity projects with
your favorite frontends on https://sanity.io/create

Looks like you already have a Sanity-account. Sweet!


Error: Failed to communicate with the Sanity API:
Unauthorized - Session not found. For more information, see https://docs.sanity.io/help/cli-errors.
    at /usr/local/lib/node_modules/@sanity/cli/bin/sanity-cli.js:4318:3725
    at async e.default (/usr/local/lib/node_modules/@sanity/cli/bin/sanity-cli.js:4318:3549)

It’s strange because it recognises that you’re logged in but then says it can’t authorize a connection to the Sanity API.

I tried a number of things and I’m still not sure why this was happening.

I fixed it by simply logging out of the Sanity CLI in the terminal and then logging back in again. As always turning something off and then back on again is worth a try.

Graemes-MacBook-Pro:studio graeme$ sanity logout
Logged out
Graemes-MacBook-Pro:studio graeme$ sanity login

Photo by Steve Johnson on Unsplash

Leave a Reply

Your email address will not be published.