Reputation: 2597
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:
GATSBY_CONTENTFUL_OFFLINE
.cache
directory environment
to "master" and removing it completelyI 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,
},
},
Upvotes: 12
Views: 6304
Reputation: 834
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
Upvotes: 3
Reputation: 1215
In my case just deleted the 2 spaces in Contentful and then created a new one, changed the values of the env variables and it worked, seems is some problem with the content model and content..
just reporting
Upvotes: 0
Reputation: 551
I encountered the same issue when I tried to access my development environment. I was using gatsby 2.22.17
and gatsby-source-contentful 2.3.14
. Apparently, Contentful has environment alias. It can be found in settings > environments
. I resolved mine by using the environment alias.
Basically, it is like making the master a pointer to an environment. You might be asked to rename your master environment when setting it up. Please think carefully about the name you want to choose for your master environment because you might not be able to rename it again. I don't think the process is reversible.
So any time you want to work on your development environment. You have to go to the environment setting and change the target environment for the alias. And then you change it back to your master environment when you are done. Try not to forget to change the target environment for the alias back to the master environment. Else your production site might fetch its content from the development environment on the next build.
I hope this helps. This solution does not make sense for me but it was the only one I could find. Please I would love to hear about any other better solution.
Upvotes: 0
Reputation: 85
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.
Upvotes: 6
Reputation: 30165
As I stated in my comment to your question, I was suspicious this had something to do with a discrepancy between the Contentful models that my Gatsby build expected, and what models were actually in the Contentful space. Acting on that I decided to delete my Contentful space entirely and re-create it. I then re-ran the automation script, which came with the rg-portfolio repo, that is responsible for creating all my initial content models. This had been part of the instructions for rg-portfolio.
contentful space --space-id xxxxxxxxx0b9 import --content-file contentful-data.json
The script completed successfully, no errors - only warnings about rate limiting.
When I then finally retried gatsby develop
it worked!!!
Part of the reason I suspected this Contentful "model discrepancy" issue was because when I first ran that contentful-data.json
script:
So there was a lot of room for me to believe there was something just "wrong" with the model(s) in that Contentful space.
Upvotes: 0