StoreFrontAccessToken Api: errors: '[API] Invalid API key or access token ' + '(unrecognized log

Solved
Highlighted
Excursionist
38 3 2
errors: '[API] Invalid API key or access token ' +
    '(unrecognized login or wrong password)'

I see this when I try to make a fetch request to the storefront api, passing in the general access token into the required header like so:

 

const returnStoreFrontToken = async (generalAccessToken, shopHost) => {
 const storeFrontAccessTokenUrl = `https://${shopHost}/admin/api/2019-10/storefront_access_tokens.json`;
 
 const getResponse = await fetch(storeFrontAccessTokenUrl);
 const data = await getResponse.json();
 console.log(data, `=====data after get token(s)=====`);
};

And it is called inside a middleware that is behind the verifyRequest() middleware. Can anyone tell why this is happening?

// application code
 app.use(async ctx => {
  const {shop, accessToken} = ctx.session;
  console.log(accessToken, `=====accessToken=====`); // shows a token
  
  // below line returns the error mentioned 
  const returnedToken = await returnStoreFrontToken(accessToken, shop);
  console.log(returnedToken, `=====returnedToken=====`); // undefined
  
  ctx.body = 'assigned body at the end of app.use middleware🎉';
 });
0 Likes

Success.

Excursionist
38 3 2

I forgot to add headers, the problem is now fixed at this particular step:

 

const getResponse = await fetch(storeFrontAccessTokenUrl, {
   method : "get"
   , headers : {
    "X-Shopify-Access-Token" : generalAccessToken
   }
  });
0 Likes