Access a community of over 900,000 Shopify Merchants and Partners and engage in meaningful conversations with your peers.
Hi,
I have generated a nodejs app using the cli for the first time.
The app need to send a request to my nodejs server to save something in the database.
So, from the react, I want to fire a request to the server.
await fetch('/product',{method: 'get' });
In the server I added this:
router.get("/product", async (ctx) => {
console.log(ctx);
return {}
});
┃ TypeError: Cannot read property 'map' of undefined
┃ at new AuthScopes (/usr/local/src/products-importer/node_modules/@shopify/shopify-api/dist/auth/scopes/index.js:14:35)
┃ at AuthScopes.equals (/usr/local/src/products-importer/node_modules/@shopify/shopify-api/dist/auth/scopes/index.js:38:21)
┃ at /usr/local/src/products-importer/node_modules/@shopify/koa-shopify-auth/dist/src/verify-request/verify-token.js:23:79
┃ at step (/usr/local/src/products-importer/node_modules/tslib/tslib.js:133:27)
┃ at Object.next (/usr/local/src/products-importer/node_modules/tslib/tslib.js:114:57)
┃ at fulfilled (/usr/local/src/products-importer/node_modules/tslib/tslib.js:104:62)
┃ at runMicrotasks (<anonymous>)
┃ at processTicksAndRejections (internal/process/task_queues.js:93:5)
What is the correct and secured way to make a request from the client to my server?
Thanks
Hey @Avi4
Just checking that your Node JS app had followed the Oauth process detailed here? Public apps and custom apps must authenticate using the Oauth 2.0 specification in order to use Shopify's API Resources.
The error you have - Cannot read property 'map' of undefined at new AuthScopes (/node_modules/@shopify/shopify-api/dist/auth/scopes/index.js:14:35 - looks very similar to an AuthScope error that I've seen, that has been thrown in the Node CLI in the past, so just wanted to check with you to see at what particular point this error was thrown - is it after you have followed the Oauth process? Please let me know when you get a second - thanks!
I have generated a new app and now this error has disappeared.
Thanks
i am having this error when i call a function from server.js
Response {type: 'basic', url: 'https://21a7-182-176-104-93.ngrok.io/auth?shop=undefined', redirected: true, status: 200, ok: true, …}
my server.js function
//=====================script tags====================//
router.get("/scripttag", verifyRequest(), async(ctx,resp) => {
const { shop, accessToken } = ctx.session;
const url = `https://${shop}/admin/api/2022-01/script_tags.json`;
const src='https://example.com/example.js';
const shopifyHeader = (token)=>({
"Content-Type": "application/json",
"X-Shopify-Access-Token":token,
});
const scriptTagBody = JSON.stringify({
script_tag: {
event: 'onload',
src,
}
});
await axios.post(url,scriptTagBody,{headers:shopifyHeader(accessToken)});
});
//=====================end script tags====================//
User | RANK |
---|---|
6 | |
4 | |
3 | |
3 | |
3 |