Topics covering webhook creation & management, event handling, Pub/Sub, and Eventbridge, in Shopify apps.
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?
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 | Solutions Engineer @ Shopify
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
This is the app id for the app I am using to test locally: 4213623
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 | Solutions Engineer @ Shopify
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
@_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
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
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 | Solutions Engineer @ Shopify
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
@_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;
});
@_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?
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 | Solutions Engineer @ Shopify
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
Hey, I am struggling with the same issue. Have you found a solution?
I'm also struggling, please see my thread: https://community.shopify.com/c/Shopify-APIs-SDKs/Uninstalled-Webhook-not-firing/m-p/1140901#M65579
Please can a shopify expert check my logs (that we don't have access to).
Regards
Hey TezWingfield83,
I found a solution. I made a post about it, check https://community.shopify.com/c/Shopify-APIs-SDKs/How-to-set-up-the-app-uninstall-webhook/m-p/114099...
regards
Hi @MarcoDo
Thanks for the heads up, I'm not familiar with NodeJs/React. My stack is .NET/C#.
Before resolving the issue, were you able to see the hook once created? I.E GET request on webhooks.
Regards,
When doing the GraphQL API request to create the webhook subscription, the Api returned as object id and success message. So I could confirm to have it set up correctly.
Is that what you meant?
For anyone else reading along, the conversation is continuing on this post: https://community.shopify.com/c/Shopify-APIs-SDKs/Uninstalled-Webhook-not-firing/m-p/1141072#M65601
JB | Solutions Engineer @ Shopify
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog