Error getspace with non master enviroment accessToken
See original GitHub issueExpected Behavior
My API key has access to QA environment only. But before initial request I would like to call getSpace
. And received 404
Actual Behavior, Possible Solution
Set space and environment
Environment
QA
- Language Version: 11*
- Operating System: Ubuntu
- Package Version: 2.1.47
- Which API are you using?: Delivery / Preview
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
contentful.js - Documentation
contentful.js. /** * Contentful Delivery API SDK. Allows you to create instances of a client * with access to the Contentful Content Delivery...
Read more >Content Management API | Contentful
A space has a minimum of one environment, which is called master. The master environment cannot be changed, deleted or renamed.
Read more >Accessing your Contentful space failed with gatsby-source ...
After giving the key access to master environment it started working. ... The script completed successfully, no errors - only warnings about ...
Read more >3xn3xw8e2 - JavaScript - OneCompiler
environment : 'master', // defaults to 'master' if not set. accessToken: 'yTlb7gLay9iH8YXj9pVqV-RApok-0RQLqeVYVpmwZBI'. }) client.getSpace().
Read more >contentful-management - npm
Normally you get the token in the Contentful web app accessToken: ... getEnvironment('master').then((environment) => { // Now that we have an environment, ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@Khaledgarbaya Thank you for looking into this. I understand and I can also confirm that everything works when granting the API key access to the master environment.
Here’s some background: In our project, we’re consuming the Contentful API with the gatsby-source-contentful plugin. When fetching the content, the plugin uses
getSpace()
, probably to get some metadata from it. However, if the configured API key does not have access to the master space, an exception is thrown, which essentially breaks the build.As it might not always be desirable to grant certain API keys access to the master environment, even during development, I think I should maybe report this in the gatsby project and see if there’s some solution, even if it’s only a note in the docs.
@Khaledgarbaya
Hi! I was just debugging the same problem before finding this issue.
If I understand the documentation at https://www.contentful.com/developers/docs/concepts/multiple-environments/ correctly, and a sandbox environment acts as kind of an override for specific space information, should
getSpace
then really get the data of the master environment’s space?Here’s my code that failed:
I’d expect
space
to contain the space information for the environment specified increateClient
, but instead theclient.getSpace()
call actually throws an exception with a 404 error, just like mentioned by the OP.This feels like a bug to me. Or do I misunderstand something here?