Gatsby: Proxy problems preventing access to Contentful space

Created on 20 Jun 2020  路  27Comments  路  Source: gatsbyjs/gatsby

Description

Hi,
I followed the steps: https://www.gatsbyjs.org/docs/sourcing-from-contentful/ && https://www.gatsbyjs.org/packages/gatsby-source-contentful/ and kept facing issues with fetching data from Contentful

Plugin version: "gatsby-source-contentful": "^2.3.16",

Steps to reproduce

  {
      resolve: `gatsby-source-contentful`,
      options: {
        spaceId: `w1o2zojv27gs`,
        accessToken: `fjXk1QrVG7g7RkrFearmzuww1vzHddcAcJCld_cJtj0`, // OLD-KEY provided in example
      },
    },

Expected result

Succesful build

Actual result

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

Used options:
spaceId: "*********7gs"
accessToken: "***************************************Jtj0"
host (default value): "cdn.contentful.com"
environment (default value): "master"
downloadLocal (default value): false
localeFilter (default value): [Function]
forceFullSync (default value): false
pageLimit (default value): 100
useNameForId (default value): true

not finished source and transform nodes - 0.732s
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] dev: `gatsby develop`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/s121003/.npm/_logs/2020-06-20T10_10_09_565Z-debug.log
s121003@MacBook-Pro TFG-app % 

Environment

Run gatsby info --clipboard in your project directory and paste the output here.

Contentful bug

Most helpful comment

Same problem, but it only fails when using the preview access token and contentful host. CURL to contentful works just fine.

All 27 comments

Hi!

Sorry to hear you're running into an issue. To help us best begin debugging the underlying cause, it is incredibly helpful if you're able to create a minimal reproduction. This is a simplified example of the issue that makes it clear and obvious what the issue is and how we can begin to debug it.

If you're up for it, we'd very much appreciate if you could provide a minimal reproduction and we'll be able to take another look.

Thanks for using Gatsby! 馃挏

Hi @freiksenet,

I've tried to create one, is this what you're after:
https://github.com/LordLalwani/gatsby-contentful-minimal-test-reproduction/tree/master/bug-repro

It still fails

Any Updates? this is really becoming a blocker.

@LordLalwani can you send me an email at [email protected] and maybe send me the correct credentials so I can try it out? We're using contentful ourselves and haven't encountered this issue ourselves unless a wrong API key is present.

Are you sure the correct keys are provided? Is it possible to manually call contentful API with your credentials?

curl --include \
     --request GET \
     --header 'Authorization: Bearer <cma_token>' \
     https://api.contentful.com/spaces/{space_id}

Hi @wardpeet, I'll send you an email shortly.

I wasn't able to get any success with the following:

curl --include \
     --request GET \
     --header 'Authorization: Bearer <cma_token>' \
     https://api.contentful.com/spaces/{space_id}

However this worked for me:

 curl "https://cdn.contentful.com/spaces/{SPACE_ID}/entries/$2?access_token={KEY}"

Jumping in to see if there are any clear fixes for this? Just downloaded my project from GitHub to another computer, and no longer working (still working on the original!)

@Oyyou I had a Zoom call with @wardpeet and we concluded that my work computer might be the one causing this problem for me. We tested the access tokens with Gatsby cloud and they all worked correctly.

Oddly enough, I was able to curl to the Contentful api and retrieve the data however when I start my Gatsby project it still fails for me. The cause is unknown, i'm assuming it's just my local machine.

Hey, I'm unfamiliar with "curl", so what I'm going to do is look at that, and then try this project on a few other computers to see if it's consistent.

I'll report back later

Sounds like a plan ! take a look at the curl examples above :)

@wardpeet I was able to add *.contentful.com to my CNTLM proxy settings and that allowed me to curl the preview tokens and get the correct data however when I attempt to build my gatsby project it still has the same problem.

Is there a specific gatsby url I can add to my proxy? perhaps that will fix the issue?

@LordLalwani A bit embarrassed to say, but I had the wrong access_token..

Sorry about my spam!

P.S Curl did help me realise this

@LordLalwani @wardpeet
i have the same issue but i don't know how it works sometimes and other times doesn't!! it's acting so weird,

@LordLalwani @wardpeet
i have the same issue but i don't know how it works sometimes and other times doesn't!! it's acting so weird,

I updated Gatsby and it works just fine now.

@fayddelight yes me too and it was working fine for today. i wish nothing breaks it again.

@LordLalwani Can you confirm whether this is now working with the latest version of gatsby and the contentful plugin?

@ascorbic

Yep, I'll give it a go after work today and get back to you (I just started so within the next 10-12 hours)

@ascorbic I tried it with [email protected] and [email protected] still the same issue.

Same problem here with:

`success onPreBootstrap - 0.053s
success createSchemaCustomization - 0.018s
Starting to fetch data from Contentful
info Fetching default locale

ERROR

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

Used options:
spaceId: "**49a"
accessToken: "
************2tvY"
host (default value): "cdn.contentful.com"
environment (default value): "master"
downloadLocal (default value): false
localeFilter (default value): [Function]
forceFullSync (default value): false
pageLimit (default value): 100
useNameForId (default value): true

not finished source and transform nodes - 0.631s`

and my profile is:

System:
OS: macOS 10.15.5
CPU: (4) x64 Intel(R) Core(TM) i5-4258U CPU @ 2.40GHz
Shell: 5.7.1 - /bin/zsh
Binaries:
Node: 14.5.0 - ~/.nvm/versions/node/v14.5.0/bin/node
Yarn: 1.22.4 - ~/.nvm/versions/node/v14.5.0/bin/yarn
npm: 6.14.6 - ~/.nvm/versions/node/v14.5.0/bin/npm
Languages:
Python: 2.7.16 - /usr/bin/python
Browsers:
Chrome: 84.0.4147.89
Firefox: 68.0.2
Safari: 13.1.1
npmPackages:
gatsby: ^2.23.12 => 2.24.7
gatsby-cli: ^2.12.63 => 2.12.63
gatsby-image: ^2.4.13 => 2.4.13
gatsby-plugin-chakra-ui: ^0.1.4 => 0.1.4
gatsby-plugin-manifest: ^2.4.14 => 2.4.19
gatsby-plugin-offline: ^3.2.13 => 3.2.19
gatsby-plugin-react-helmet: ^3.3.6 => 3.3.10
gatsby-plugin-sharp: ^2.6.14 => 2.6.20
gatsby-source-contentful: ^2.3.28 => 2.3.28
gatsby-source-filesystem: ^2.3.14 => 2.3.20
gatsby-source-graphql: ^2.6.2 => 2.6.2
gatsby-transformer-remark: ^2.8.25 => 2.8.25
gatsby-transformer-sharp: ^2.5.7 => 2.5.11
gatsby-transformer-yaml: ^2.4.10 => 2.4.10
npmGlobalPackages:
gatsby-cli: 2.12.60

Fixed. The problem was that I was using the first created ApiKey by Contentful.
After creating a new one, it started to work.
Crazy.

I am unsure of what caused this issue on running gatsby develop. But after doing a curl command to my API key I found AccessTokenInvalid response so I changed my Preview API key with the Deliver API key and it works just fine!

I tried a couple times with the Preview API key but it still doesn't work and shows up the same error.

Me to =[

Following the started guide I ran into this issue quickly. Running npm build results in the following:

info Fetching default locale

 ERROR 

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

I set up another API key via the dashboard, updated the .env.development and got it working. The initial example one did not work. Make sure you're using the Deployment and not Preview key.

I had the same issue but fixed it after I updated my host to be preview.contentful.com instead of https://preview.contentful.com.

I am using gatsby-source-contentful plugin.

Running into the same issue after following the guide

Same problem, but it only fails when using the preview access token and contentful host. CURL to contentful works just fine.

  1. Visit https://app.contentful.com/
  2. Switch to the master environment at the sidebar on left
  3. Select Settings (gear icon) menu item in the header
  4. Select API keys in dropdown menu
  5. Select your API_KEY in Content delivery/preview tokens tab
  6. Scroll to down and check your new environment https://prnt.sc/u9qpw5

Hello. Looking through the replies I think the original issue was resolved as being a problem with computer settings. Since I'm worried the generic title will attract a lot of "me toos" I am going to close this issue. If you have problems accessing your Contentful space, it may help to read through replies in this thread and to verify that your settings / tokens / keys are correct. If all else fails, please open a new issue that describes your specific issue and the steps taken so far.

Thank you :purple_heart:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kalinchernev picture kalinchernev  路  3Comments

brandonmp picture brandonmp  路  3Comments

ferMartz picture ferMartz  路  3Comments

signalwerk picture signalwerk  路  3Comments

benstr picture benstr  路  3Comments