skip to Main Content

I’ve created a shopify app with PHP. and registered a webhook for ‘app/uninstalled’. Which will remove data from my database.

But when I delete this app the webhook isn’t triggering. Because the store isn’t removing from my database.

Here is my code:

`POST /admin/webhooks.json
'webhook'  => array(
    "topic" => "app/uninstalled",
    "address" => "https://my-domain/apps/app-name/uninstall.php",
    "format" => 'json',
 ),`

Can anyone tell me what is the problem and what things should I need to edit?

I’ve tried for a long time but now I’m stuck with this….

2

Answers


  1. Try to use with exception handling:-

    <?php 
    try
    {
    	$webhook_delete = array(
    	'webhook' =>
    	     array(
    		'topic' => 'app/uninstalled',
    		'address' => 'https://your-domain/app/delhook.php?shop=shop-name',
    		'format' => 'json'
    	     )
            );
            $result = $shopify('POST /admin/webhooks.json',$webhook_delete);
    }
    catch (shopifyApiException $e)
    {
          # HTTP status code was >= 400 or response contained the key 'errors'
    	echo $e;
    	print_r($e->getRequest());
    	print_r($e->getResponse());
    }
    catch (shopifyCurlException $e)
    {
          # cURL error
    	echo $e;
    	print_r($e->getRequest());
    	print_r($e->getResponse());
    }

    You can pass store-name with address in link and can fetch on delhook.php or your file.

    Delhook.php

    if(isset($_REQUEST['shop'])) { 
      //here you can remove store from your database.
    }
    

    If you get any error then it will print the error.

    Login or Signup to reply.
  2. If you believe that the webhook had been created. In https://my-domain/apps/app-name/uninstall.php put these line of code

    $webhook = file_get_contents('php://input');
    $webhook = json_decode($webhook, TRUE);
    $newFileName = "something.txt";
    file_put_contents($newFileName, $webhook);
    

    It will catch the json shopify send when you uninstall your apps and put into file something.txt after that get the info your use to store. Json usually look like

    {
      "id": 690933842,
      "name": "Super Toys",
      "email": "[email protected]",
      "domain": "super.myshopify.com",
      "province": "Tennessee",
      "country": "US",
      "address1": "190 MacLaren Street",
      "zip": "37178",
      "city": "Houston",
      "source": null,
      "phone": "3213213210",
      "latitude": null,
      "longitude": null,
      "primary_locale": "en",
      "address2": null,
      "created_at": null,
      "updated_at": null,
      "country_code": "US",
      "country_name": "United States",
      "currency": "USD",
      "customer_email": "[email protected]",
      "timezone": "(GMT-05:00) Eastern Time (US & Canada)",
      "iana_timezone": null,
      "shop_owner": "Steve Jobs",
      "money_format": "$",
      "money_with_currency_format": "$ USD",
      "weight_unit": "kg",
      "province_code": "TN",
      "taxes_included": null,
      "tax_shipping": null,
      "county_taxes": null,
      "plan_display_name": "Shopify Plus",
      "plan_name": "enterprise",
      "has_discounts": true,
      "has_gift_cards": true,
      "myshopify_domain": null,
      "google_apps_domain": null,
      "google_apps_login_enabled": null,
      "money_in_emails_format": "$",
      "money_with_currency_in_emails_format": "$ USD",
      "eligible_for_payments": true,
      "requires_extra_payments_agreement": false,
      "password_enabled": null,
      "has_storefront": true,
      "eligible_for_card_reader_giveaway": false,
      "finances": true,
      "primary_location_id": 905684977,
      "checkout_api_supported": true,
      "multi_location_enabled": false,
      "setup_required": false,
      "force_ssl": false,
      "pre_launch_enabled": false,
      "enabled_presentment_currencies": [
        "USD"
      ]
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search