Have your say in Community Polls: What was/is your greatest motivation to start your own business?
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.

Re: Can't create webhook for SUBSCRIPTION_CONTRACTS_CREATE topic in custom app node.js code

Can't create webhook for SUBSCRIPTION_CONTRACTS_CREATE topic in custom app node.js code

nimirium
Visitor
3 0 0

I'm building a custom shopify app, where I register a webhook for SUBSCRIPTION_CONTRACTS_CREATE and SUBSCRIPTION_CONTRACTS_UPDATE topic.

I'm using shopify-api npm library, version 1.2.1, and I tried shopify api versions 2021-07, 2021-04 and 2021-01.

 

 

 

            Shopify.Webhooks.Registry.register({
                shop,
                accessToken,
                path: '/webhooks',
                topic: 'SUBSCRIPTION_CONTRACTS_CREATE',
                apiVersion: ApiVersion.April21,  // I also tried '2021-07' and ApiVersion.January21
                webhookHandler: (_topic, shop, _body) => { console.log('Subscription Contract was created!'); }
            });

 

 

 

I expect the webhook to be registered successfully, like when I register PRODUCTS_CREATE topic, but it is not.

 

 

 

(node:53083) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'webhookSubscriptions' of null
    at Object.<anonymous> (/Users/sophie/Projects/shopify-app/node_modules/@shopify/shopify-api/dist/webhooks/registry.js:92:44)
    at step (/Users/sophie/Projects/shopify-app/node_modules/@shopify/shopify-api/node_modules/tslib/tslib.js:143:27)
    at Object.next (/Users/sophie/Projects/shopify-app/node_modules/@shopify/shopify-api/node_modules/tslib/tslib.js:124:57)
    at fulfilled (/Users/sophie/Projects/shopify-app/node_modules/@shopify/shopify-api/node_modules/tslib/tslib.js:114:62)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)

 

 

 

What can I do to fix this? Looks like a problem with the library.

Thanks.

 

**Edit**

I added prints to the library code and got this error:

[{"message":"topics argument cannot contain any topics to which you do not have access.","locations":[{"line":2,"column":5}],"path":["webhookSubscriptions"]}]

 looks like my app is missing permissions

Replies 2 (2)

AnEpicName
Tourist
8 1 2

Hi!

Did you manage to solve this? I'm having a similar issue with my app.

sophief
Shopify Partner
11 0 0

It was a permission issue. I had to request permissions for the app to access subscriptions from the shopify partners settings.

I ended up using graphql instead of webhooks though.