Remove webhook after app uninstall?

Rob_Cameron1
Shopify Partner
8 0 1

I’m working on an app that uses the API to create a webhook so that I can be notified whenever a shop updates a product. 

If someone uninstalls my app, how will I know so that I can use the API to then delete that webhook? Or do I just have to resign myself to receiving those product update calls for all time?

If someone deletes my app is there a specific error that’s returned from the API if I try to make a call in the future? Different enough that I would know I no longer have permission, versus the API call is just invalid? That could be my indication that I’ve been removed?

Justin_Stern1
Excursionist
70 0 14

Hey Rob,

If someone uninstalls my app, how will I know so that I can use the API to then delete that webhook? Or do I just have to resign myself to receiving those product update calls for all time?

Once the app is uninstalled, you can no longer perform API requests on that shop, including the removing of webhooks.  However, you should not receive webhooks from an uninstalled shop, maybe for a second or two as any queued webhooks are fired, but not after that.  At least not for webhooks created over the Shopify API https://docs.shopify.com/api/webhook

If someone deletes my app is there a specific error that’s returned from the API if I try to make a call in the future? Different enough that I would know I no longer have permission, versus the API call is just invalid? That could be my indication that I’ve been removed?

The Shopify API is a little inconsistent in the error response codes for this sort of thing.  Nine times out of 10 calling ShopifyAPI::Shop.current will return a "404 Resource Not Found" if the Shop has uninstalled your app.  Occasionally it will also return "401 Unauthorized Access" for an uninstalled shop.  I don't tend to rely on that as an indicator of uninstallations.

The best real-time indication of an uninstall is to subscribe to the "app/uninstalled" webhook, and mark the Shop as uninstalled unless you're able to get a successful response to ShopifyAPI::Shop.current (do this final Shop.current call because we find that users will often uninstall the app, then quickly re-install it, yet the "app/uninstall" webhook gets fired after the re-install since there's a slight delay, so you don't want to incorrectly mark a Shop as uninstalled that has performed this "quick reinstall")

The other sure fire way to determine if a shop has uninstalled your app is to export the current install CSV from your partner account and compare it to your database.  Doing this would catch any webhooks that you might have somehow missed or incorrectly processed.

Hope this helps!

 

Product Customizer - Creating extremely customizable products within Shopify is no longer a hassle! BlogFeeder - Automatically pull updates from any RSS feed into your Shopify blog Happy Ending - Personalize your thank you page
Rob_Cameron1
Shopify Partner
8 0 1

Awesome, I didn't realize there was an app/uninstall webhook! Someone should add that to the docs! :)

0 Likes
Justin_Stern1
Excursionist
70 0 14

ha ha, it actually is on that docs page, though it's not listed in the table up at the top where you'd expect, which is probably an oversight.  If you search for "app/uinstalled" though in your browser on that page, you'll see it pop up in a couple of places 

Product Customizer - Creating extremely customizable products within Shopify is no longer a hassle! BlogFeeder - Automatically pull updates from any RSS feed into your Shopify blog Happy Ending - Personalize your thank you page
0 Likes
Rob_Cameron1
Shopify Partner
8 0 1

Doh! Yep I just skimmed the list at the top. Thanks!

0 Likes