Topics covering webhook creation & management, event handling, Pub/Sub, and Eventbridge, in Shopify apps.
HI ,
I am trying to create webhook using api using following code. (https://github.com/sandeepshetty/shopify_api. 😉
$shopify = shopify_api\client(
$shop_data->store_name, $shop_data->access_token, $app_settings->api_key, $app_settings->shared_secret
);
//print_r($shopify);
$arguments = array(
'webhooks'=>array
(
'topic' => 'cart/updated',
'address' => 'http://test.com/shopify/shopify_testing/sendPrints.php?key='.$shop_data->store_name,
'format'=>'xml'
)
);
try
{
$webhooks = $shopify('POST', '/admin/webhooks.json', $arguments,$response_headers);
echo 'test';
echo '<pre>'; print_r($webhooks);echo '</pre>' ;
}
catch (shopify_api\Exception $e)
{
echo '<pre>'; print_r($e);echo '</pre>' ;
}
catch (shopify_api\CurlException $e)
{
echo "doh";
echo '<pre>'; print_r($e);echo '</pre>' ;
}
I am getting following error:
[info:protected] => Array ( [method] => POST [response_headers] => Array ( [http_status_message] => Bad Request [http_status_code] => 400 [server] => nginx [date] => Mon, 21 Apr 2014 12:17:03 GMT [content-type] => application/json; charset=utf-8 [transfer-encoding] => chunked [status] => 400 Bad Request [x-xss-protection] => 1; mode=block [x-content-type-options] => nosniff [x-ua-compatible] => chrome=1 [x-shopid] => 4352121 [x-shardid] => 0 [x-shopify-asset-version] => bac6763d60bfdd59408fe42fb4e6d2ae9b65b101 [x-shopify-shop-api-call-limit] => 1/40 [http_x_shopify_shop_api_call_limit] => 1/40 [x-stats-userid] => 0 [x-stats-apiclientid] => 201113 [x-stats-apipermissionid] => 5887753 [x-request-id] => 60e479dc-5692-49f0-ab87-75d3127f2ae5 ) [response] => Array ( [errors] => Array ( [webhook] => Required parameter missing or invalid ) ) )
I have tried a lot to solve this error, I have also tried 'webhook'=>array instead of 'webhooks'=>array. but no luck.
can please anyone help me out?
thanks in advance.
I can't see any issue however can you paste the response when you use "webhook" rather than "webhooks" as this isn't correct.
Actually topic is incorrect and should be 'carts/update'
following is the response:
[info:protected] => Array ( [method] => POST [response_headers] => Array ( [http_status_message] => Bad Request [http_status_code] => 400 [server] => nginx [date] => Mon, 21 Apr 2014 12:17:03 GMT [content-type] => application/json; charset=utf-8 [transfer-encoding] => chunked [status] => 400 Bad Request [x-xss-protection] => 1; mode=block [x-content-type-options] => nosniff [x-ua-compatible] => chrome=1 [x-shopid] => 4352121 [x-shardid] => 0 [x-shopify-asset-version] => bac6763d60bfdd59408fe42fb4e6d2ae9b65b101 [x-shopify-shop-api-call-limit] => 1/40 [http_x_shopify_shop_api_call_limit] => 1/40 [x-stats-userid] => 0 [x-stats-apiclientid] => 201113 [x-stats-apipermissionid] => 5887753 [x-request-id] => 60e479dc-5692-49f0-ab87-75d3127f2ae5 ) [response] => Array ( [errors] => Array ( [webhook] => Required parameter missing or invalid ) ) )
Did you change your topic to the correct "carts/update"?
No, I don't want the solution specific to cart/update I actually wants to create webhook for order creation.
do we need to take permission for creating webhooks using API ?
actually I have created one shopify app and creating webhook using API is the part of that app.
I want the orders details when order is created. so I am trying to create webhook.
$arguments = array("webhook" => array( 'topic' => $webhook, 'address' => $app['shopify']['credentials']['return_url']."webhook/".$webhook, 'format' => "json" ));
The above is our arguments code, for order creation $webhook = "orders/create"
what should I placed in
$app['shopify'] --------->store url ?
['credentials'] ---------> access_token?
['return_url'] ---------> 'http://test.com/shopify/shopify_testing/sendPrints.php?key='.$shop_data->store_name ?
$arguments = array("webhook" => array( 'topic' => "orders/create", 'address' => 'http://test.com/shopify/shopify_testing/sendPrints.php?key='.$shop_data->store_name, 'format' => "json" ));
Is all you would need
I'd also stay away from XML with shopify as they have no guarantees this will work as expected and will be deprecated at some point, if it hasn't already.
how to check whether webhook is created or not ?
now I am not getting any error but not getting whether it is created or not?
you just need to go to xxxx.myshopify.com/admin/webhooks.json?access_token=xxxxx make sure you do it in a browser that isn't logged in to the admin panel or you won't be able to see it.
getting following error :
{"errors":"SSL required"}
Just put https://xxxx.myshopify.com/admin/webhooks.json?access_token=xxxxx ;
I did the same but getting same error.
Always works for me, maybe your behind a proxy or something?
thanks it works I have tried by clearing browser's history n cookies.