{"record":{"id":"b5f1e77788934caa","repo":"gatsbyjs/gatsby","slug":"cannot-access-contentful-space-masktext-plugino","errorCode":null,"errorMessage":"Cannot access Contentful space \"${maskText(pluginOptions.spaceId)}\" on environment \"${pluginOptions.environment}\" with access token \"${maskText(pluginOptions.accessToken)}\". Make sure to double check them!","messagePattern":"Cannot access Contentful space \"(.+?)\" on environment \"(.+?)\" with access token \"(.+?)\"\\. Make sure to double check them!","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"packages/gatsby-source-contentful/src/gatsby-node.js","lineNumber":39,"sourceCode":"    {\n      headers: {\n        Authorization: `Bearer ${pluginOptions.accessToken}`,\n        \"Content-Type\": `application/json`,\n      },\n    }\n  )\n    .then(res => res.ok)\n    .then(ok => {\n      if (!ok) {\n        const errorMessage = `Cannot access Contentful space \"${maskText(\n          pluginOptions.spaceId\n        )}\" on environment \"${\n          pluginOptions.environment\n        }\" with access token \"${maskText(\n          pluginOptions.accessToken\n        )}\". Make sure to double check them!`\n\n        throw new Error(errorMessage)\n      }\n    })\n\n  return undefined\n}\n\nexport const onPreInit = async (\n  { store, reporter, actions },\n  pluginOptions\n) => {\n  // if gatsby-plugin-image is not installed\n  try {\n    await import(`gatsby-plugin-image/graphql-utils`)\n  } catch (err) {\n    reporter.panic({\n      id: CODES.GatsbyPluginMissing,\n      context: {\n        sourceMessage: `gatsby-plugin-image is missing from your project.\\nPlease install \"gatsby-plugin-image\".`,","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/gatsbyjs/gatsby/blob/8b06340921ffdf23125a365b9c9923690cb62ce6/packages/gatsby-source-contentful/src/gatsby-node.js#L21-L57","documentation":"Thrown by gatsby-source-contentful's validateContentfulAccess when the HTTP request to the Contentful Content Management API returns a non-OK status (4xx/5xx). This means the spaceId, environment, or accessToken is incorrect, or the token lacks permission. Credentials are masked in the message for safety.","triggerScenarios":"fetch() to contentful.com returns res.ok === false (HTTP 401/403/404); spaceId, environment, or accessToken in pluginOptions is wrong, expired, or from a different environment.","commonSituations":"Wrong spaceId copied from Contentful, access token from a different space or environment, token revoked/expired, environment name typo, or network/proxy returning an error page.","solutions":["Double-check spaceId, environment, and accessToken in gatsby-config.js against the Contentful dashboard.","Ensure the accessToken has read access to the specified environment (not just master).","Verify the environment name exists in the space (Contentful > Settings > Environments).","Regenerate the access token in Contentful if it may be expired or revoked.","Check for trailing spaces or copy-paste errors in the credentials."],"exampleFix":"// before\n{\n  resolve: 'gatsby-source-contentful',\n  options: {\n    spaceId: 'space-id',\n    accessToken: 'wrong-token',\n    environment: 'master'\n  }\n}\n// after\n{\n  resolve: 'gatsby-source-contentful',\n  options: {\n    spaceId: 'correct-space-id',\n    accessToken: 'CFPAT-correct-token',\n    environment: 'main'\n  }\n}","handlingStrategy":"retry","validationCode":"// Validate Contentful credentials format before build\nconst { spaceId, accessToken, environment } = pluginOptions\nif (!spaceId || !accessToken || !environment) {\n  throw new Error('Contentful spaceId, accessToken, and environment are all required')\n}\nif (!accessToken.startsWith('CDA') && !accessToken.startsWith('CFPAT')) {\n  console.warn('Access token format looks unusual — verify it is a Contentful token')\n}","typeGuard":null,"tryCatchPattern":"try {\n  await validateContentfulAccess(pluginOptions)\n} catch (e) {\n  if (e.message.includes('Cannot access Contentful')) {\n    // check credentials, retry with corrected config\n  } else throw e\n}","preventionTips":["Store Contentful credentials in environment variables, not in gatsby-config directly.","Verify spaceId, environment, and accessToken in the Contentful dashboard before building.","Ensure the access token has read access to the target environment.","Use a pre-build script to test Contentful API connectivity."],"tags":["gatsby","contentful","cms","authentication","network","credentials"],"backgroundTag":null,"analyzedSha":"8b06340921ffdf23125a365b9c9923690cb62ce6","analyzedAt":"2026-08-13T02:36:21.405Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}