Question

I am trying to create a webhook (orders/create) when my shopify app gets installed, but i am unable to make it work. When trying to create the webhook i receive the error "Unprocessable Entity". The below is the code that i am using currently. Can you please help me fix this error.

    if (isset($_GET['code'])) {
    $shopifyClient = new ShopifyClient($_GET['shop'], "", API_KEY, SECRET);
    session_unset();
    $_SESSION['token'] = $shopifyClient->getAccessToken($_GET['code']);
    if ($_SESSION['token'] != '')
        $_SESSION['shop'] = $_GET['shop'];
    $shopifyClient = new ShopifyClient($_GET['shop'], $_SESSION['token'], API_KEY, SECRET);
    $charge = array("webhook"=>array("topic"=>"orders/create","address"=>"http://localhost/xxxxx/test.php","format"=>"json"));
    try
    {
      $webhooks = $shopifyClient->call('POST','/admin/webhooks.json',$charge);
    } catch(Exception $e){
      //do something with the Exception
      echo $e->getMessage();
      exit;
    }
    header("Location: http://localhost/xxxxx/index.php");
    exit;
}
Was it helpful?

Solution

May not be your main problem (it could be though), but Shopify won't add a localhost webhook. Try something like https://forwardhq.com/ to test webhooks in your app, or http://requestb.in/ if you just want to inspect them.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top