I use the shopify api nodejs and all works fine and I can login and auth.
I also get the access token and the session.
Now I want to get all products but I got this error:
TypeError: Cannot read properties of undefined (reading 'all')
at C:\express_inngest\src\server.ts:127:47
at step (C:\express_inngest\src\server.ts:56:23)
at Object.next (C:\express_inngest\src\server.ts:37:53)
at fulfilled (C:\express_inngest\src\server.ts:28:58)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
here is my code:
app.get('/auth/callback', async (req: any, res: any) => {
try {
// The library will automatically redirect the user
console.log('CALLBACK');
const callback = await shopify.auth.callback({
rawRequest: req,
rawResponse: res,
});
const response = await shopify.webhooks.register({
session: callback.session,
});
const products = await shopify.rest.Product.all({
session: callback.session,
});
if (!response['PRODUCTS_CREATE'][0]?.success) {
Sentry.captureException(
`Failed to register PRODUCTS_CREATE webhook: ${response['PRODUCTS_CREATE'][0]?.result}`,
);
}
res.send('AUTH');
} catch(e) {
console.log(e);
Sentry.captureException(e);
}
});
I had the same issue, the problem is the restResources
is missing in shopifyApi declaration. In my case, to fix that, I set my shopifyApi like :
const shopify = shopifyApi({
apiKey: process.env.SHOPIFY_API_KEY,
apiSecretKey: process.env.SHOPIFY_API_SECRET ?? "",
scopes: process.env.SCOPES?.split(","),
hostName: process.env.SHOPIFY_APP_URL?.replace(/https:\/\//, "") ?? "",
apiVersion: ApiVersion.April23,
isEmbeddedApp: true,
restResources: restResources, // I add this line
});
And I import my ressource from :
import { restResources } from "@shopify/shopify-api/rest/admin/2023-10";