This post talks through how to resolve the GatsbyJS Kentico Cloud source plugin Error: Missing or invalid access token. Please include the valid access token value in the Authorization header field as an HTTP bearer authorization scheme.
Getting started with Kentico Cloud
Kentico Cloud is an Content as as Service (CaaS), API First CMS, which allows you to build your content to deliver to different omnichannel devices developed all from the API that is provided by Kentico Cloud.
If you're new to Kentico Cloud, then I would recommend you have a read through my post on Getting Started with Kentico Cloud.
Gatsby Source Plugin for Kentico Cloud
If you're using Kentico Cloud to build your website and you're doing this by using the static site generator GatsbyJS, then you will be most likely using the Gatsby Source Plugin for Kentico Cloud to help you get started.
Using the source plugin is a great way to start using Kentico Cloud, GatsbyJS and GraphQL (a query language for your API). There are step by step instructions that help you achieve this, by starting with installing Gatsby, then by setting the configuration for Kentico Cloud in the gatsby-config file and then with GraphQL.
The instructions mention to scaffold your project using Gatsby Kentico Cloud starter site, however I decided to use my instance of a Kentico Cloud project that I had already configured for my own website.
Gatsby Source Plugin error - missing or invalid access token
My general setup of the Kentico Cloud project was fine, however when I was running the command 'gatsby-develop' to retrieve the data from Kentico Cloud and convert it to Gatsby GraphQL model, I received an error in the terminal/command prompt.
The error I received was 'Error - Plugin gatsby-source-kentico-cloud returned an error.'
A detailed version of the error was 'Error: Missing or invalid access token. Please include the valid access token value in the Authorization header field as an HTTP bearer authorization scheme.'
There was also a warning message of 'The gatsby-source-kentico-cloud plugin has generated no Gatsby nodes. Do you need it?'
Resolved - Missing or invalid access token error
I was looking around for why I received this error and couldn't see anything in the Gatsby Source Plugin for Kentico Cloud instructions on where I might have missed a step.
After looking around various setups and then at my configuration I figured out why this was happening. Earlier, I mentioned I didn't use the Gatsby Kentico Cloud starter site and created my own, I subsequently checked my Kentico Cloud project settings under the API keys section and then noticed I had my 'Delivery API secured access' enabled when I previously had done some API testing.
Disabling this resolved this issue for me and allowed me to carry on working with GastbyJS and Kentico Cloud.