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

nimirium
New Member
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

0 Likes
AnEpicName
Tourist
8 1 0

Hi!

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

0 Likes
sophief
New Member
2 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.

0 Likes