Solved

How to get webhook details in CURL request in PHP

team-promojuice
Visitor
2 0 0

I have logged in browser with shopify credentials, when I hit the "admin/webhooks.json" API in browser I am getting the response array with webhook details but If I tried to do CURL Get request using PHP code it is giving me a blank array response.
Here is the code.

$webhooks_url = $shopify_api_url."/admin/webhooks.json";
$webhooks = curlRequest(array(),$webhooks_url,false);

/* Function to make curl request for Shopify */
function curlRequest($auth_header,$request_api,$is_post,$data=null,$is_delete=false){

     $ch = curl_init();

     curl_setopt($ch, CURLOPT_HTTPHEADER, $auth_header);

     curl_setopt($ch, CURLOPT_URL, $request_api);

     if($is_post == true){

          curl_setopt($ch, CURLOPT_POST, true);
          curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
     }
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     $output = curl_exec($ch);
     curl_close($ch);

     $output = json_decode($output, true);
     return $output;
}

This is the Output Logged

development.ERROR: Array
(
       [webhooks] => Array
       (
       )
)

Accepted Solution (1)

Zameer
Shopify Staff
297 31 90

This is an accepted solution.

Hey there,

 

As documented here, webhooks are scoped only to the app that they're registered to. So when you are making the call in the admin, you will see all of the webhook notifications which you set up in the admin.

 

When you make the same call to the "/admin/webhooks.json" endpoint using your API credentials, you will only see the webhooks which you registered with that API client. In your case, you must not have any webhooks which were registered with your app, which is why the response is an empty array.

To learn more visit the Shopify Help Center or the Community Blog.

View solution in original post

Replies 2 (2)

Zameer
Shopify Staff
297 31 90

This is an accepted solution.

Hey there,

 

As documented here, webhooks are scoped only to the app that they're registered to. So when you are making the call in the admin, you will see all of the webhook notifications which you set up in the admin.

 

When you make the same call to the "/admin/webhooks.json" endpoint using your API credentials, you will only see the webhooks which you registered with that API client. In your case, you must not have any webhooks which were registered with your app, which is why the response is an empty array.

To learn more visit the Shopify Help Center or the Community Blog.

team-promojuice
Visitor
2 0 0

Thankyou @Zameer