Receiving 401 'Unauthorized' when working with Storyblok CMS API

1.3k views Asked by At

I am struggling to get started with Storyblok CMS. I have been following some of the tutorials on the Interwebs, e.g., Nuxt JS with Storyblok, etc., but I cannot seem to successfully call the API without receiving a 401 'Unauthorized' exception.

At first, I thought it was my code so I tried:

curl "https://api.storyblok.com/v2/cdn/stories?token=MYTOKEN" -X GET -H "Accept: application/json" -H "Content-Type: application/json"

but that didn't work either. Double checked my token, etc. I must be missing something. I am on the non-paying Community plan right now.

2

There are 2 answers

1
David K. Hess On

It's likely the region you deployed to - if the US, the host is api-us.storyblok.com. When using and initializing the JS API give it the option region: "us".

Some sample code provided by a helpful commenter:

const apiOptions = { accessToken: '<YOUR_ACCESS_TOKEN>', region: 'us' }
const storyblok = new StoryblokClient(apiOptions)
0
Haxwell On

I had a similar problem, but I found that the issue was that the api wasn't designed to respond to the format of my request.

If you're like me then the issue is that you didn't specify a story in the route of the url. So your request should look more like

curl "https://api.storyblok.com/v2/cdn/stories/home?token=MYTOKEN" -X GET -H "Accept: application/json" -H "Content-Type: application/json"

where I've added "/home" to the url as an example of a story.