Topics covering webhook creation & management, event handling, Pub/Sub, and Eventbridge, in Shopify apps.
Hi All,
This is driving me bonkers! I've literally rewrote my func four times to try and understand why I'm not receiving an uninstalled event.
Ok, So, I'm testing locally via ngrok. I've spent the best part of the day wiring up the auth, all is working fine except, uninstalling.
topic: app/uninstalled
address: https://******.ngrok.io/shopify/uninstall
format: json.
I log the response from the api (looks good), I can see the hook via postman (GET request)
I've stripped out all the code on the uninstalled endpoint on my mvc app and I'm left with:
[HttpPost]
public IActionResult Index()
{
return new OkResult();
}
It's just not being hit.
Please can someone point me in the right direction?
Stay Safe,
Solved! Go to the solution
This is an accepted solution.
The logs confirm a webhook is indeed firing, but your endpoint is responding with a 503 error. They're being sent to https://[removed].ngrok.io/Shopify/Uninstall . Hopefully that helps with troubleshooting.
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
Bump...
Anyone else seeing these problems? I really could do with a tech rep from shopify to help identify the issues.
I've tested again this morning, leaving the dev/ngrok server running incase of delay... but 30mins in, and still no data received.
Are there any reported issues using ngrok in a test env? How can I tell if the shopify system even attempted to make this call? Happy to share further details in a private message.
Regards,
Bump Bump...
Anyone? I take it the Shopify team don't work on the weekends. No rotating team I guess.
If your App is not getting hit with a webhook, 99% of the time the problem is, you have not configured your App correctly. So you say Postman registers the hit. Great. Now when you examine the webhook you setup in the App you're about to uninstall, you are 100% certain you did that step correctly, and you see your topic and endpoint perfect right?
Only in that case would I even pretend there is a problem with Shopify... 99% of the time, the problem was me. And what I did. And the DUH moments are there.
Evening Bill,
Thank you very much for the reply. It's truly appreciated.
I completely agree that mistakes and bugs can happen. My day job is a software engineer, so I'm well versed in the art of developing systems.
So, My auth is working. During the callback process, I call the POST webhook endpoint, which certainly creates the hook. The resp from the call:
{"webhook":{"id":****,"address":"https:\/\/****ngrok.io\/shopify\/uninstall\/index\/","topic":"app\/uninstalled","created_at":"2021-04-18T20:33:08+01:00","updated_at":"2021-04-18T20:33:08+01:00","format":"json","fields":[],"metafield_namespaces":[],"api_version":"2021-04","private_metafield_namespaces":[]}}
I also store the config to a table:
topic: app/uninstalled
address: https://****.ngrok.io/shopify/uninstall/index/
format: json
And finally when I get all webhooks using postman, I can certainly see the one I created:
I've now included a logging method and left my dev server running:
[HttpPost]
public async Task<IActionResult> Index()
{
_loggerHelper.Log(LogType.Database, "UninstallController.cs", "Uninstall", "Uninstall Endpoint Hit!");
return new OkResult();
}
You say not configured app? Are you referring to the app in shopify (Create App section). Do I need to whitelist some where?
And finally if I take my url "uninstall" change the verb to post in postman, I can hit my own app... I really wish there was a "DUH" moment but I'm not seeing it.
Regards,
What I meant is, your App is probably not configured properly at the endpoint. Shopify is almost certainly sending you the webhook if you are uninstalling the App. If your endpoint remains unhit, it is likely you are either not listening to the right endpoint with the right verb... or something else is misconfigured. As I said before, there will likely be a duh moment for you.
There is nothing to whitelist. If you set a webhook in an App, and you checked it exists, and you trigger it, you should receive it. In your case, not receiving it is probably due to a config.
Hi Bill,
Still not found the issue, it makes it tremendously difficult if I cannot see what's being returned when shopify attempts to make the call. Surly there's an event stream somewhere?
Taking a screen shot of my dashboard, If the fail rate is at 0.0 (and assuming I have a problem) that should be greater than zero.
Their needs to be more tools to understand the problem. If you say 99% of the time it's user error and shopify is sending the request, can I not see a log of this somewhere?
Regards,
My best advice to you is to reach out to your community then. Not sure what scripting language you are using, but it has users that have handled webhooks before, and probably have written blog posts and Stackoverflow stories about your issue. Try them for advice!
As you well know, Webhooks are nothing new or exotic in Internet computing, and Shopify is nothing but standard issue Webhooks. So like all things scripting, I am sure there something in your setup you are missing, and once you find it, you'll have glory!
Hi Bill,
Thanks for the reply.
Yes, I've built a few systems on webhooks, they truly are magnificent.
I'm using .net/c#.
Do we not have access to logs? I could scout around, but if the logs just tells me the exact problem, I can resolve it. I have a tracer running this end, and nothing is coming in.
My last attempt is to remove the method from the app and add it to a serverless pipeline (Azure HTTP func), if that fails, well I'm truly lost. I recently wrote an app for a WMS system using hooks, with the same process/method and that works fine.
I guess I'll report back.
Regards,
The puzzle from your Dashboard report is fact none are even reported as being tried. So lets type this out. You install your App, which is all fine and dandy. You mastered oAuth. Your database has a token from a shop (likely your test shop) which you setup in the partner Dashboard with ngrok.io settings directly to your App. I myself use a service allowing me to call me Apps stuff like fizzbuzz.test which map nicely to fizzbuzz.ngrok.io which I setup in my Shopify App dashboard.
Once I am setup, and I navigate to the App and see it come up, usually embedded, and usually Polaris... my Hello World if you will, I then uninstall the App. Shopify fires off the uninstall, I watch my terminal logs where I am running my localhost webserver version of the App, and BOOM. I see the Webhook get processed in real-time.
So simple. But the fact that you are doing ALL that, and seeing nothing, is indeed weird. I cannot speak for C# users, but perhaps someone in that community can get you over the hump.
Hi Bill,
It's always great to "rubber duck" the flow.
Yes, so I create an app in shopify - fill in the necessary fields.
1. Click the app
2, Select a store
3, Click and Install
At this point it goes through all typical OAuth process, On the call back using the redirect uri I begin to create the app/uninstalled webhook.
I also log the resp
And I can also see the resp when getting all webhooks for that account
The app is most certainly "installed"
Looking at the same screenshot, I click the Delete button being the uninstalled process, even tried when clicking into the app.
I've tested my own endpoint to simulate what shopify is attempting to do and it works:
End result my local server is still running and not being hit:
I've used the same hook endpoint stored in hook resp, my config tbl, postman etc... The url works.
Other process, ngrok running locally with a developers account - nothing out of the ordinary.
Regards,
Hey @TezWingfield83,
If you provide the id for your app I'll check our logs to confirm the webhook is being sent, and confirm the response we're seeing from your endpoint. Bill's advice is great and there's isn't anything else I'd add, but I can at least confirm the behaviour in our logs to give a bit more confidence while you troubleshoot. The app id is the last set of digits in the URL when you're viewing the app in the partner dashboard.
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
Hi JB, Bill,
Thank you.
Here's the Id: 5175689
Regards,
This is an accepted solution.
The logs confirm a webhook is indeed firing, but your endpoint is responding with a 503 error. They're being sent to https://[removed].ngrok.io/Shopify/Uninstall . Hopefully that helps with troubleshooting.
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
Hi JB, Bill.
Awesome that's something to go on.
503 Service unavailable implies, I guess more of a network issue. I'm able to hit that endpoint locally using ngrok with no issues.
To confirm a network related issue, I'll aim to deploy a serverless http func to see if that resolves it - just makes it impossible to debug locally.
Thank you for your time all.
I'll report back later.
Regards,
Hi @HunkyBill @_JB
Thank you again, I know it's been a challenge. I'm pleased it's not a developer mistake, I.E bug / config.
JB, would it be possible just to confirm whether you're now receiving a 200. I've quickly deployed a serverless func, and can see an execution on my tracer but don't have any logs yet due to a quick temp release to test the theory.
Having said that, I'm still not quite sure why shopify cannot reach my ngrok instance. baffling.
Regards,
I would still bundle any issues you have with your service as a config problem. Whether it be with ngrok, or other aspects, those all get lumped in... Shopify is sending the webhook. That action generates a non-200 OK response... therefore that is a config issue. But yes, it is also that you have not made a typo of otherwise introduced some kind of bug yourself. Good luck, and hopefully your can sort out your ngrok issues soon!
Hi @HunkyBill
Thanks for the info, does come off a little iffy/sarcastic haha but appreciate the honesty.
I use the same configuration through various WMS systems, I'm confident in the approach but non the less shall investigate the configuration.
Again, thank you for the time taken.
Regards,
Hey @TezWingfield83,
Confirmed, I'm seeing 4 200 - OK
responses in the past hour. Note that Shopify automatically retries failed webhook deliveries, so some of those may be from previous failed delivery attempts.
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
Hi @_JB - we are building an app also and having some issues with uninstall. Can you please help to check if it is firing and the response on your server for this app id:
bump
To anyone still struggling with this, in the most recent API versions Shopify made it really UNINTUITIVE to handle webhooks, this is what you should do:
1. Add webhook handler for ALL shops:
Shopify.Webhooks.Registry.addHandler("APP_UNINSTALLED", {
path: "/webhooks",
webhookHandler: async (topic, shop, body) => {
delete ACTIVE_SHOPIFY_SHOPS[shop];
console.log("deleted shop hehe, body:",body)
},
});
Then during or after the individual shop is installing the app
2. register webhook for the INDIVIDUAL shop:
// Put this inside the createShopifyAuth or after the customer has installed the app
const response = await Shopify.Webhooks.Registry.register({
path: '/webhooks',
topic: 'APP_UNINSTALLED',
accessToken: accessToken,
shop: shop,
});
if (!response['APP_UNINSTALLED'].success) {
console.log(
`Failed to register APP_UNINSTALLED webhook: ${response.result}`
);
}
That has always been the pattern. Nothing new there. Can you explain when you say that Shopify recently made that UNINTUITIVE? It's been more than a decade since Webhooks are created the same way. How has it changed?
The old version of my app that has been approved, doesn't need to use the addHandler method, I just do it like this and it works:
let response = await Shopify.Webhooks.Registry.register({
shop,
accessToken,
path: "/webhooks",
topic: "APP_UNINSTALLED",
webhookHandler: async (topic, shop, body) => (
delete ACTIVE_SHOPIFY_SHOPS[shop]
),
});
if (!response.success) {
console.log(
`Failed to register APP_UNINSTALLED webhook: ${response.result}`
);
}
If you used Shopify CLI to create an app, you used to get something like this as well. It's unintuitive compared to the old way which was much more concise and would send you an error message, if the handler wasn't added.
@_JB Thanks for the your Answer. this was happens due the app in development stage. we can see the App URL was change by using the ngrok or cloud flare tunnel. Shopify System retried again those. please help on those issue.
I have develpment app that was app and runing last few day I am not getting the ```app_unnstalled ``` webhook callback,
@_JB my app id is 595853313. I have created app backend in Laravel. The app/uninstall webhook is getting created every time but not getting fired. I have tried many times. Can you guide me?