Development discussions around Shopify APIs
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 } });
User | RANK |
---|---|
8 | |
7 | |
3 | |
3 | |
3 |
Connect your PayPal account to allow your customers to checkout using the PayPal gateway a...
ByYour online store speed can enhance your store’s discoverability, boost conversion rates a...
ByShopping is at our fingertips with mobile devices. Is your theme optimized to be user-frie...
By