Topics covering webhook creation & management, event handling, Pub/Sub, and Eventbridge, in Shopify apps.
I am trying to create a webhook with topic INVENTORY_LEVELS/UPDATE but I am getting the error "Cannot read properties of undefined (reading 'webhookSubscriptions')" at the creation. I've already checked my app scopes and I have the read_inventory scope.
This is my current code:
async function registerRestockHook( session ) {
const hook = await Shopify.Webhooks.Registry.register({
shop: session.shop,
accessToken: session.accessToken,
topic: 'INVENTORY_LEVELS/UPDATE',
path: '/webhooks',
webhookHandler: async (topic, shop, body) => {
console.log(body);
}
});
if (!hook["INVENTORY_LEVELS/UPDATE"].success) {
console.log(
`Failed to register INVENTORY_LEVELS/UPDATE webhook: ${response.result}`
);
}
}
Hey @igortavtib,
I took a closer look at your question and the details shared. I found a few other examples of similar errors that mention this was resolved after updating app permissions.
If so, and this issue has persisted, I wanted to ask a few more questions.
Though I am not personally full-time node.js developer, I have successfully implemented webhooks into several of my test applications that are built with the shopify-node-api library - using this documentation.
Beyond that, if you are able to replicate this behaviour and can log an x-request-id response header value returned with the error, I can absolutely investigate logs on our end, pass back insights, suggestions, or next steps!
- Cheers
awwdam | API Support @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
Hi @awwdam,
After making some tests and rewriting the code I could successfully create the webhook. I actually don't know what exactly was wrong with my first code but now it works.
Thank you for your answer and I am sorry I've not updated this post before.