user7365049
user7365049

Reputation:

cUrL in php : Nothing come in response [NULL]

I am fetching data from thirdparty API using CURL in php. I have read the documentation and passing the same valid parameters to the request but nothing works. I am showing the code removing "API KEY" due to confidentiality.

$service_url = 'https://api.birdeye.com/resources/v1/business/147197756121167?api_key=ApiKeyGoesHere';
    $curl = curl_init($service_url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    $curl_response = curl_exec($curl);
    if ($curl_response === false) 
    {
        $info = curl_getinfo($curl);
        curl_close($curl);
        echo '<pre>';
        die('error occured during curl exec. Additioanl info: ' . var_export($info));
    }

    curl_close($curl);
    $decoded1 = json_decode($curl_response,true);
    if (isset($decoded1->response->status) && $decoded1->response->status == 'ERROR') 
    {
        die('error occured: ' . $decoded1->response->errormessage);
    }
    echo 'response ok!';
    var_export($decoded1->response);
    ?>

The Output it gives me is : response ok!NULL

Link to the documenataion of birdeye API.

http://docs.birdeye.apiary.io/#reference/business/get/get-business

I have tried testing with Terminal it gives me response. Can Any One give me the way, where I am going wrong?

Upvotes: 3

Views: 8005

Answers (2)

Indresh Tayal
Indresh Tayal

Reputation: 306

Try this with your api key

 $urltopost = 'https://api.birdeye.com/resources/v1/business/147197756121167?api_key=ApiKeyGoesHere';
 $header=array("content-type"=>"application/json");
 $ch = curl_init ($urltopost);
 curl_setopt ($ch, CURLOPT_POST, true);
 curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
 curl_setopt ($ch, CURLOPT_HTTPHEADER, $header);
 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
 $returndata = curl_exec ($ch);
 $status_code = @curl_getinfo($ch, CURLINFO_HTTP_CODE); 
 print_r($status_code);
 print_r($returndata);

Upvotes: 3

Suresh
Suresh

Reputation: 5997

Check with this piece of code once. This works for me.

<?php
// Get cURL resource
$curl = curl_init();

// Set some options - we are passing in a useragent too here
curl_setopt_array($curl, array(
    CURLOPT_RETURNTRANSFER => 1,
        CURLOPT_URL => "YOUR API END POINT"

));

// Send the request & save response to $resp
$result = json_decode(curl_exec($curl),true);

// Close request to clear up some resources
curl_close($curl);

return $result;

Upvotes: 0

Related Questions