App/unistalled webhook is not created

Highlighted
Shopify Partner
3 0 0

Hi,

I am creating a custom app in PHP. I am storing some store info into my database table.

 

I want the delete the store details from PHP Application after uninstalling the app from Shopify store which are stored in database when Application installed. We have two things to achieve this -

1. Register for app/uninstalled web hook , after this when i check the status it fives me error -

{
    "errors": {
        "address": [
            "for this topic has already been taken"
        ]
    }
}

and there are not any hook in my shopify store under "settings-> notification "

2. the code is not taking me to "uninstall.PHP file".

I have attached the screenshots of the code, Please check and let me know what is the issue here.

 

https://prnt.sc/mjzs6i

https://prnt.sc/mjzsan

 

Thanks.

0 Likes
Highlighted
Shopify Partner
23 1 4

The first error means: you have already created webhook.  For your second question, this is the same problem I am facing. My wehbook is not redirecting me to my uninstall route.

0 Likes
Highlighted
Shopify Partner
3 0 0

But whenever i hit the webhooks.JSON it gives me

{"webhooks":[]}

So it is not creating the web hook not even in the shopify back end.

0 Likes
Highlighted
Shopify Partner
23 1 4

Hi, Please try with this.
$url = 'https://' . your_shop_name . '/admin/webhooks.json';
$site_url="https:\/\/your_site_url_where_your_app_is_present";
$params1 = '{"webhook": {
"topic": "app\/uninstalled",
"address": "https://your_app_url/appuninstall",
"format": "json"
}}';

$session = curl_init();

curl_setopt($session, CURLOPT_URL, $url);
curl_setopt($session, CURLOPT_POST, 1);
// Tell curl that this is the body of the POST
curl_setopt($session, CURLOPT_POSTFIELDS, $params1);
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_HTTPHEADER, array('Accept: application/json', 'Content-Type: application/json', 'X-Shopify-Access-Token: '.your_app_access_token));
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);

if(preg_match("/^(https)/",$url)) curl_setopt($session,CURLOPT_SSL_VERIFYPEER,false);

$response = curl_exec($session);
curl_close($session);

// echo "<br>";print_r($response);   it will show your webhook. 

0 Likes
Highlighted
Shopify Partner
3 0 0

Hi Vikas,

It is  showing me the webhook response on email, but not when i hit the /admin/webhooks.json . But i want to go to file uninstall.php whenever i want to delete the App from admin. I have tried your code as well.

$url = 'https://' . STORE_URL . '/admin/webhooks.json';

$params = '{"webhook": {
"topic": "app\/uninstalled",
"address": "'.$serverurl.'/uninstall.php",
"format": "json"
}}';


$session = curl_init();

curl_setopt($session, CURLOPT_URL, $url);
curl_setopt($session, CURLOPT_POST, 1);
// Tell curl that this is the body of the POST
curl_setopt($session, CURLOPT_POSTFIELDS, $params);
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_HTTPHEADER, array('Accept: application/json', 'Content-Type: application/json', 'X-Shopify-Access-Token: '.TOKEN));
//curl_setopt($session, CURLOPT_CUSTOMREQUEST, 'POST');

curl_setopt($session, CURLOPT_RETURNTRANSFER, true);

if(preg_match("/^(https)/",$url)) curl_setopt($session,CURLOPT_SSL_VERIFYPEER,false);

$response = curl_exec($session);
curl_close($session);

$body =json_decode($response);

0 Likes