Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Error "Cannot read properties of undefined (reading 'webhookSubscriptions')" at webhook creation

Error "Cannot read properties of undefined (reading 'webhookSubscriptions')" at webhook creation

igortavtib
Visitor
2 0 1

 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}`
    );
  }
}

 

Replies 2 (2)

awwdam
Shopify Staff
249 42 38

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.

 

  • Have you worked through any debugging with an API client? I was able to register a subscription with both a REST post request and GraphQL mutation, neither has issues when the app had the correct scope access (read_inventory).
  • Can you register other subscriptions with the same app?

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

igortavtib
Visitor
2 0 1

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.