App/uninstalled webhook triggered automatically

App/uninstalled webhook triggered automatically

Dev_Shopify_1_A
Shopify Partner
26 0 7

I've created a new app for my shopify store. And seen that the app/uninstalled webhook called automatically, though I ain't uninstalled the app from my store.

Can anyone please tell me what is the problem? Why shopify uninstall webhook called automatically?

Replies 3 (3)

Celso_White
Shopify Partner
23 0 29

I was recently experiencing this too. Very strange but the key thing I learned is to code defensively. Don't solely rely on the webhooks to trigger database actions. See below for my defensive coding practice. Particularly point #3 pertains to your question.

  1. When you receive an uninstall webhook respond to it quickly with a status 200. Shopify requires that you respond within 5s. So quickly verify the webhook, add it's payload to a queue and then respond with status 200. The payload I'm adding is simply the name of the shop that uninstalled. The data sent in the body of the request is only information about the shop. It doesn't include anything unique about the webhook that fired to differentiate it from other uninstall webhooks that may fire for the same shop.
  2. Your queue should be a list that triggers another function to run once a new node is added to it. By using a queue to do the heavy lifting you can spend more time performing db actions without worrying about the 5s respond time. I'm using Firestore for a database and Cloud Firestore Triggers. That backend setup for queue processing is working great. My function only runs onCreate() of a new shop uninstall node so even if multiple uninstall webhooks fire back to back then my function only runs once.
  3. The function I run when a new uninstall is added to my queue first checks to see if I can use the shops access token that I already have saved elsewhere in the users node in my db. If I'm blocked from using the access token then this in fact is a true uninstall and should be processed. If I can still use the access token then the uninstall should be ignored.
  4. When a user reinstalls the app, I remove them from my uninstall queue and send them through the auth process again to get a new access token.

Leonan
Shopify Partner
5 0 5

Hi Celso White,

How can I check if access token is valid?

 

 

Celso_White
Shopify Partner
23 0 29

Hi Leonan, to check if the access token is still valid I do a test api call. You can use pretty much any of the methods. I find the simplest is to do a get request for the users profile info. If the API returns that users info then you still have a valid access token for the shop. If not then the API will return an error (no permission).