Cannot read property 'webhookSubscriptions' of undefined

Solved
johna1203
Tourist
4 1 0

Hi  all,

I posted this question on stackoverflow because I hadn't noticed that this site existed. https://stackoverflow.com/questions/66539378/webhooks-in-shopify-shopify-api-using-nodejs

I am trying to create a Shopify App that observes the FULFILLMENT_UPDATE and I am using node for that.

Recently I created a new project using shopify-cli, and added this code in server.js to observe the FULFILLMENT_UPDATE webhook.

        const response3 = await Shopify.Webhooks.Registry.register({
          shop,
          accessToken,
          path: "/webhooks",
          topic: "FULFILLMENTS_UPDATE",
          webhookHandler: async (topic, shop, body) =>{
            console.log("FULFILLMENT_UPDATE webhooks", body);
//            delete ACTIVE_SHOPIFY_SHOPS[shop]
          },
        });

        if (!response3.success) {
          console.log(
            `Failed to register APP_UNINSTALLED webhook: ${response.result}`
          );
        }

But when the code is executed i get an error that says `Cannot read property 'webhookSubscriptions' of undefined`. 

┃   InternalServerError: Cannot read property 'webhookSubscriptions' of undefined
┃       at Object.throw (/home/user/src/user_test_app/node_modules/koa/lib/context.js:97:11)
┃       at /home/user/src/user_test_app/node_modules/@shopify/koa-shopify-auth/dist/src/auth/index.js:100:42
┃       at step (/home/user/src/user_test_app/node_modules/tslib/tslib.js:133:27)
┃       at Object.throw (/home/user/src/user_test_app/node_modules/tslib/tslib.js:114:57)
┃       at rejected (/home/user/src/user_test_app/node_modules/tslib/tslib.js:105:69)
┃       at processTicksAndRejections (node:internal/process/task_queues:93:5)

 

what should i do to register a webhook using nodejs?

 

Thanks,

Accepted Solution (1)

Accepted Solutions
johna1203
Tourist
4 1 0

This is an accepted solution.

I forgot to add the read_fulfillments scope. I did and it worked.

Thanks.

View solution in original post

Replies 3 (3)
johna1203
Tourist
4 1 0

This is an accepted solution.

I forgot to add the read_fulfillments scope. I did and it worked.

Thanks.

rohit_martires
Shopify Partner
49 3 2

i want to register webhooks for carts/create and carts/update but there are no scopes for carts in the docs.
im getting the same above error tho, any idea what i should do?

Donfetto
Tourist
7 0 2

I have the same problem