app/uninstalled webhook not working

Highlighted
Excursionist
13 1 2

I see a lot of threads in these forums about app/uninstalled webhook not working, but I have not seen any with a solution.

In my server.js file, I register the app/uninstalled webhook inside the afterAuth function like this:

 

const registration = await registerWebhook({
            address: `${properties.host}/webhooks/app/uninstalled`,
            topic: 'APP_UNINSTALLED',
            accessToken,
            shop,
            apiVersion: ApiVersion.October19
            });

          if (registration.success) {
             console.log('Successfully registered webhook!');
          } else {
             console.log('Failed to register webhook', registration.result);
          }

 

Then later in the file, I listen for that webhook here:

 

const appUninstallWebhook = receiveWebhook({secret: SHOPIFY_API_SECRET_KEY});

  router.post('/webhooks/app/uninstalled', appUninstallWebhook, (ctx) => {
    console.log('received webhook: ', ctx.state.webhook);
    ctx.status = 200;
  });

 

 

I see the webhook successfully being registered, however when I delete the app running locally on ngrok in my test Shopify store, I do not see that webhook being triggered.

Could this be because the app is being run locally? Or is there a specific permission I need to request when installing an app during the Shopify OAuth process in order to listen to this webhook?

The way I am understanding it is that when the app is deleted off the user's store, this webhook should be called and the code inside the router post should execute. Why is this not working?

0 Likes
Highlighted
Shopify Staff
Shopify Staff
619 76 139

Hey @Indeed,

Based on the flow you provided it definitely looks like the webhook should have fired. Can you provide the app_id you're using to test? It's the last string of numbers in the URL when viewing the app in your partner dash. I'll use this to check our logs and see what's happening with the webhook.

JB | Developer Support @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 

0 Likes
Highlighted
Excursionist
13 1 2

This is the app id for the app I am using to test locally: 4213623

0 Likes
Highlighted
Shopify Staff
Shopify Staff
619 76 139

Hey @Indeed,

I was able to check the logs for that app, and they're showing the webhooks fired as expected but received a 404 response from your endpoint. The endpoint being hit was  https://********93f7.ngrok.io/webhooks/app/uninstalled

The system automatically retries a webhook 19 times after which it will be discarded. Once you get the endpoint fixed up you should be able to receive the webhook as expected.

JB | Developer Support @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 

1 Like
Highlighted
Excursionist
13 1 2

@_JB  Oh ok, what do I need to do to get the endpoint set up on the local ngrok URL? I did not do anything to set up this endpoint

0 Likes
Highlighted
Excursionist
13 1 2

I don't see anything about needing to set up the webhook endpoint in the documentation, I figured we could just listen to that endpoint and it would already be set up by Shopify somehow: https://shopify.dev/docs/admin-api/rest/reference/events/webhook

0 Likes
Highlighted
Shopify Staff
Shopify Staff
619 76 139

Hey @Indeed,

I just meant that your app needs to accept POST requests on the /webhooks/app/uninstalled path, because right now it's returning a 404. 

JB | Developer Support @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 

0 Likes
Highlighted
Excursionist
13 1 2

@_JB  But isn't that what this part of the server code is supposed to be doing? :

 

 

const appUninstallWebhook = receiveWebhook({secret: SHOPIFY_API_SECRET_KEY});

router.post('/webhooks/app/uninstalled', appUninstallWebhook, (ctx) => {
    console.log('received webhook: ', ctx.state.webhook);
    ctx.status = 200;
  });

 

 

 

0 Likes
Highlighted
Excursionist
13 1 2

@_JB sorry, still stuck on this - is there another way I need to be setting up the app to accept POST requests to that path besides the code I pasted there?

0 Likes
Highlighted
Shopify Staff
Shopify Staff
619 76 139

Hey @Indeed,

It's hard to say for sure without seeing the full code, but it definitely seems like the app isn't properly handling POST requests to the /webhooks/app/uninstalled endpoint.

It looks like you're using the express router, so one thing to check is that your app is calling the router module correctly. Another troubleshooting step to consider is to temporarily bypass the router by defining a route for /webhooks/app/uninstalled in the main app with app.post, and then try sending a POST locally with Insomnia/Postman. If that works, you know the app is handling requests properly and should focus troubleshooting on the router module. If it doesn't work, the console will hopefully provide some useful information that can tell you where to start troubleshooting in your code.

 

JB | Developer Support @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 

1 Like