I am creating a Shopify app using PHP. I want to delete the store info from the database when someone uninstalls the app. I have found this code but I have no idea where to add this and how to trigger it when an app in uninstalled from the store.
$webhook_delete = [
'webhook' =>
[
'topic' => 'app/uninstalled',
'address' => 'https://icodebreakers.us/shopifyapp/delete_store_info.php?shop=' . $shop_url . '',
'format' => 'json',
],
];
$result = $shopify('POST /admin/webhooks.json', $webhook_delete);
2
Answers
The code you have shared in a Webhook Subscription creation code. You need to create this webhook subscription in Shopify when the app is installed. Now with this done when your App is uninstalled, you will get a notification in the URL you have mentioned in the address of the webhook subscription. You can validate the request and perform whatever task you want to.
Update: Create uninstall webhook for Shopify
If your use ngrok I believe it will appear in the console this when your app is uninstalled:
POST /abc/yourfile 200 OK
If you believe that the webhook had been created. In
delete_store_info.php
put these line of codeIt will catch the json shopify send when you uninstall your apps and put into file something.txt after that get the info you use to store in db. Json usually look like
The ?shop= is no needed because Shopify send info your need already.