Access a community of over 900,000 Shopify Merchants and Partners and engage in meaningful conversations with your peers.
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🎉'; });
Solved! Go to the solution
This is an accepted solution.
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 } });
This is an accepted solution.
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 } });