3
votes

while running this code with the app instalation,i am getting the Unprocessable Entity status code 422 error. Here is the code

$sc = new ShopifyClient($_SESSION['shop'], $_SESSION['token'], $api_key, $secret);
$charge = array
(
    "webhooks"=> array
    (
        "topic"=>"orders/create",
        "address"=>"http://www.abc123no.com/nomi/s.php?key=123456789",
        "format"=>"json"
    )
);


try 
{
            $webhooks = $sc->call('POST','/admin/webhooks.json',$charge);
}
catch (ShopifyApiException $e)
{
    var_dump($e->getResponseHeaders());
}
2

2 Answers

3
votes

Error code 422 is for validation errors. The body of the response will describe the error to help you debug your application.

e.g. The response might be: {"errors":{"address":["for this topic has already been taken"]}}

Your error appears to be from using the wrong format for the request. The create endpoint doesn't take an array of webhooks, and you should use the singular "webhook" for the top-level key.

The Webhook API documentation has the correct format for the request body.

0
votes

Change webhooks to webhook , it might create bad request error

"**webhooks**"=> array
    (
        "topic"=>"orders/create",
        "address"=>"http://www.abc123no.com/nomi/s.php?key=123456789",
        "format"=>"json"
    )