New Shopify Certification now available: Liquid Storefronts for Theme Developers

Failed to process webhook: Error: No webhook is registered for topic app_subscriptions/update

Solved
malluAppMaker
Shopify Partner
7 1 2

Hi,

 

I have been using the webhook "app_subscriptions/update" without any error for a year I think. But all of a sudden I am getting  errors in the partner dashboard. When I checked the code I can see the following error when a webhook is received. Same happens for uninstall webhook also.

 

Failed to process webhook: Error: No webhook is registered for topic app_subscriptions/update

 

Webhook setup as below.

 

const response = await Shopify.Webhooks.Registry.register({
shop,
accessToken,
path: "/webhooks",
topic: "APP_UNINSTALLED",
webhookHandler: async (topic, shop, body) =>{

console.log('App uninstalled');
// const obj = JSON.parse(body);
// console.log(obj);


delete ACTIVE_SHOPIFY_SHOPS[shop];
}
,
})
router.post("/webhooks", async (ctx) => {
try {
console.log("processing webhook");
await Shopify.Webhooks.Registry.process(ctx.req, ctx.res);
console.log(`Webhook processed, returned status code 200`);
} catch (error) {
console.log(`Failed to process webhook: ${error}`);
}
});

 

Can anybody trace the issue ?

 

The recent update I have done updating koa-shopify-auth library

 

"@shopify/koa-shopify-auth": "^5.0.3",

 

Accepted Solution (1)
technologytest
Shopify Partner
5 1 1

This is an accepted solution.

I can only speak for fixing the uninstall webhook, but I assume it may apply to the /update one as well. Make sure you have the Shopify.Webhooks.Registry.addHandler code above app.prepare. Your router.post code is fine though 

 

Shopify.Webhooks.Registry.addHandler("APP_UNINSTALLED", {
  path: "/webhooks",
  webhookHandler: async (topic, shop, body) =>
    delete ACTIVE_SHOPIFY_SHOPS[shop],
});

app.prepare().then(async () => {
  const server = new Koa();
  const router = new Router();
  server.keys = [Shopify.Context.API_SECRET_KEY];
  server.use(
    createShopifyAuth({
      async afterAuth(ctx) {
        // Access token and shop available in ctx.state.shopify
        const { shop, accessToken, scope } = ctx.state.shopify;
        const host = ctx.query.host;
        ACTIVE_SHOPIFY_SHOPS[shop] = scope;

        const responses = await Shopify.Webhooks.Registry.register({
          shop,
          accessToken,
          path: "/webhooks",
          topic: "APP_UNINSTALLED",
        });

        if (!responses["APP_UNINSTALLED"].success) {
          console.log(
            `Failed to register APP_UNINSTALLED webhook: ${responses.result}`
          );
        }

        // Redirect to app with shop parameter upon auth
        ctx.redirect(`/?shop=${shop}&host=${host}`);
      },
    })
  );

 

 

View solution in original post

Replies 5 (5)
technologytest
Shopify Partner
5 1 1

This is an accepted solution.

I can only speak for fixing the uninstall webhook, but I assume it may apply to the /update one as well. Make sure you have the Shopify.Webhooks.Registry.addHandler code above app.prepare. Your router.post code is fine though 

 

Shopify.Webhooks.Registry.addHandler("APP_UNINSTALLED", {
  path: "/webhooks",
  webhookHandler: async (topic, shop, body) =>
    delete ACTIVE_SHOPIFY_SHOPS[shop],
});

app.prepare().then(async () => {
  const server = new Koa();
  const router = new Router();
  server.keys = [Shopify.Context.API_SECRET_KEY];
  server.use(
    createShopifyAuth({
      async afterAuth(ctx) {
        // Access token and shop available in ctx.state.shopify
        const { shop, accessToken, scope } = ctx.state.shopify;
        const host = ctx.query.host;
        ACTIVE_SHOPIFY_SHOPS[shop] = scope;

        const responses = await Shopify.Webhooks.Registry.register({
          shop,
          accessToken,
          path: "/webhooks",
          topic: "APP_UNINSTALLED",
        });

        if (!responses["APP_UNINSTALLED"].success) {
          console.log(
            `Failed to register APP_UNINSTALLED webhook: ${responses.result}`
          );
        }

        // Redirect to app with shop parameter upon auth
        ctx.redirect(`/?shop=${shop}&host=${host}`);
      },
    })
  );

 

 

malluAppMaker
Shopify Partner
7 1 2

Hi @technologytest .

Thanks a lot for the quick solution. Implemented the changes and my webhook issues are completely resolved now for both uninstall & app_subscriptions/update.

Sharan_oapps
Shopify Partner
35 1 6

Can you please explain in detail what happens in the flow of doing so...

malluAppMaker
Shopify Partner
7 1 2

As mentioned before, All my webhooks were failing. After changing the code only the webhooks started working again.

Sharan_oapps
Shopify Partner
35 1 6

Yes all webhooks are working fine after this fix..Thank you..