Structured Content 2022: Join our conference to explore fresh perspectives on content and digital experiences →

Hi, Can someone tell me the proper way to enter the projectID using ENV’s in the sanity.json. If I hard code, works great, anything else and and it’s not finding the projectId....

8 replies
Last updated: Jan 24, 2021

Hi, Can someone tell me the proper way to enter the projectID using ENV’s in the sanity.json. If I hard code, works great, anything else and and it’s not finding the projectId. ENV’s are in .env.local

"api": {
    "projectId": "PLACEHOLDER_ENV_VARIABLES_WILL_HANDLE_FOR_US",
    "dataset": "PLACEHOLDER_ENV_VARIABLES_WILL_HANDLE_FOR_US"
  }

Jan 6, 2021, 5:17 PM

They need to be in studio folder and be named

.env.development
and
.env.production
I think

Jan 6, 2021, 5:22 PM

and should not be referenced in sanity.json file like that. you can delete the api section

Jan 6, 2021, 5:23 PM

ok thanks, I’ll give that a go

Jan 6, 2021, 5:28 PM

https://www.sanity.io/docs/studio-environment-variables#dot-env-files-env-f5e9e3158896 here you can read a bit more about how they should me named etc

Jan 6, 2021, 5:31 PM

Makes sense, production is working, it’s just localhost that is not finding the project ID. I put in the studio folder

Jan 6, 2021, 5:33 PM

Nice, that’s all it was. Cheers

user T

Jan 6, 2021, 5:36 PM

Hey guys, I am facing the same problem, and I followed the instructions of

user T
(removed the api section from sanity.json), and I placed a .env.development in the root folders with the variables SANITY_STUDIO_API_PROJECT_ID and SANITY_STUDIO_API_DATASET defined.However, when I run sanity start, sanity says "Project configuration required before starting studio" and forces me to select a project or create a new one ...

Any ideas how I could fix that?

Jan 23, 2021, 10:45 AM

(found the answer thanks to

user Q
, commented here: https://sanity-io-land.slack.com/archives/C9Z7RC3V1/p1611482229244200 )

Jan 24, 2021, 12:37 PM

Sanity.io: Get the most out of your content

Sanity.io is a platform to build websites and applications. It comes with great APIs that let you treat content like data. Give your team exactly what they need to edit and publish their content with the customizable Sanity Studio. Get real-time collaboration out of the box. Sanity.io comes with a hosted datastore for JSON documents, query languages like GROQ and GraphQL, CDNs, on-demand asset transformations, presentation agnostic rich text, plugins, and much more.

Don't compromise on developer experience. Join thousands of developers and trusted companies and power your content with Sanity.io. Free to get started, pay-as-you-go on all plans.