Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing your Contentful space failed with gatsby-source-contentful

gatsby: 2.20.8
gatsbh-source-contentful: 2.2.5

I've verified my spaceId and accessToken are correct, and I've verified that these keys have access to my Contentful development environment. I've tried:

  • Enabling GATSBY_CONTENTFUL_OFFLINE
  • Deleting the .cache directory
  • Deleting node_modules
  • Setting environment to "master" and removing it completely
  • Wrapping the env vars in template literals (suggested on an old github issue)

I keep getting this error. Any ideas?

ERROR 

Accessing your Contentful space failed.
Try setting GATSBY_CONTENTFUL_OFFLINE=true to see if we can serve from cache.

Used options:
spaceId: "*********z1u"
accessToken: "*****************************************vMI'"
environment: "development"
host (default value): "cdn.contentful.com"
downloadLocal (default value): false
localeFilter (default value): [Function]
forceFullSync (default value): false
pageLimit (default value): 100
useNameForId (default value): true

And here's my code from gatsby-config.js

{
  resolve: `gatsby-source-contentful`,
  options: {
    spaceId: process.env.CONTENTFUL_SPACE_ID,
    accessToken: process.env.CONTENTFUL_ACCESS_TOKEN,
    environment: process.env.CONTENTFUL_ENVIRONMENT,
  },
},
like image 429
Barryman9000 Avatar asked Mar 27 '20 19:03

Barryman9000


2 Answers

Not sure if you got it working in the meantime but I had this same issue and found this on Github https://github.com/gatsbyjs/gatsby/issues/19392 that is what you and I are having.

Apparently, in newer versions of gatsby-source-plugin it requires the key to have access to the master environment as well (which is ridiculous imo).

After giving the key access to master environment it started working.

like image 154
Hugo Marques Avatar answered Sep 18 '22 15:09

Hugo Marques


Had a similar issue, after importing one space to another. I deleted the demo API key (which i had tried to use) and created a new one. Worked after that

like image 42
Alex Avatar answered Sep 20 '22 15:09

Alex