We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more

Shopify webhooks registered but not triggered when uninstall app

Shopify webhooks registered but not triggered when uninstall app

zahid3d29
Shopify Partner
79 5 28

Hello, shopify app developer. I am developing an app while I have been facing a problem at almost last steps of developments. 

I have succesfully registered an webhooks, we can see status after installed app.  check below...

webhooks-reg.png

But after uninstalled app it should triggred and removing data  from database which I request on delete.php file and also should create .log file to store response data. But nothing is happen. I think there might be a problem with delete.php file. I uploaded full delete.php file for your kind information. please help me if you can. 

 

<?php
require_once("inc/db_connect.php");
require_once("inc/functions.php");


define('SHOPIFY_APP_SECRET', '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'); // Replace with your SECRET KEY

function verify_webhook ($data, $hmac_header){
  $calculated_hmac = base64_encode(hash_hmac('sha256', $data, SHOPIFY_APP_SECRET, true));
  return hash_equals($hmac_header, $calculated_hmac);
}

$res = '';
$hmac_header = $_SERVER['HTTP_X_SHOPIFY_HMAC_SHA256'];
$topic_header = $_SERVER['HTTP_X_SHOPIFY_TOPIC'];
$shop_header = $_SERVER['HTTP_X_SHOPIFY_SHOP_DOMAIN'];
$data = file_get_contents('php://input');
$decoded_data = json_decode($data, true);

$verified = verify_webhook($data, $hmac_header);

if( $verified == true ) {
  if( $topic_header == 'app/uninstalled' || $topic_header == 'shop/update') {
    if( $topic_header == 'app/uninstalled' ) {

      $sql = "DELETE FROM `AccessToken` WHERE store_url='" . $shop_header . "' LIMIT 1";
      $result = mysqli_query($conn, $sql);

      $response->shop_domain = $decoded_data['shop_domain'];

      $res = $decoded_data['shop_domain'] . ' is successfully deleted from the database';
    

    } else {
      $res = $data;
    }
  }
} else {
  $res = 'The request is not from Shopify';
}

error_log('Response: '. $res); //check error.log to see the result

 

Let me know if you need to know something more. 

I have followed this tutorial to create webhooks. 
https://weeklyhow.com/shopify-uninstall-webhook-api-tutorial/

 

Best Regards

Zahid

 

Need a Shopify developer? Chat on WhatsApp
- For Shopify Design Changes | Shopify Custom Coding | Custom Modifications
- Your Coffee Tip , my code a perfect blend!   ❤️
Replies 3 (3)

shop_dev1
Shopify Partner
36 0 3

Hello @zahid3d29 

I hope you are well!

I am facing same issue. I got the registered webhook but when I check in mysql table it is not working. I hope you got the solution and please help me to fix this issue asap.

zahid3d29
Shopify Partner
79 5 28

Hi, I am actually busy right now. Yes, I solved that problem long ago. Please check the attached link and download that app and you can explore. 
https://drive.google.com/file/d/16PCbDdMNrdWGpMdNpZ0cF9NlQ-rY70x-/view?usp=sharing

Need a Shopify developer? Chat on WhatsApp
- For Shopify Design Changes | Shopify Custom Coding | Custom Modifications
- Your Coffee Tip , my code a perfect blend!   ❤️
shop_dev1
Shopify Partner
36 0 3

Hello @zahid3d29 

Thanks for your quick response. I have fixed this issue.