1

Below is my CURL request. Im trying to pull data from a CRM called pipedrive. The URL is pulling the data correctly but for some reason its not displaying on my website.

<?php
$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.pipedrive.com/v1/persons/find?term=devonvermaak2%40gmail.com&start=0&search_by_email=1&api_token=e7f91c84dad486160a9744f4972d7f742de3d",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => array(
    "cache-control: no-cache",
    "content-length": "217",
    "content-type": "application/json",
    "x-ratelimit-limit": "20",
    "x-ratelimit-remaining": "19",
    "x-ratelimit-reset": "2"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);
//because of true, it's in an array
$response = json_decode($response, true); 
echo 'Name: '. $response['data']['name']. '<br />';
echo 'Email: '. $response['data']['email']. '<br />';
echo 'Phone: '. $response['data']['phone'];

Its not showing the data at all. Is there something wrong with my code?

Note: I've edited the api token for security purposes..

Devon
  • 49
  • 5

2 Answers2

1

since your $response is

{
  "success": true,
  "data": [
    {
      "id": 91235,
      "name": "Devon Vermaak",
      "email": "devonvermaak2@gmail.com",
      "phone": "0555877857",
      "org_id": null,
      "org_name": "",
      "visible_to": "3"
    }
  ],
  "additional_data": {
    "search_method": "search_by_email",
    "pagination": {
      "start": 0,
      "limit": 100,
      "more_items_in_collection": false
    }
  }
}

you can see that the data is an array

hence, you can access the values via its index. Ex

$response['data'][0]['name'] returns Devon Vermaak

echo 'Name: '. $response['data'][0]['name']. '<br />';
echo 'Email: '. $response['data'][0]['email']. '<br />';
echo 'Phone: '. $response['data'][0]['phone'];
catzilla
  • 1,901
  • 18
  • 31
  • Yes that is exactly how I have it on my side, however its not displaying the data. Also when I print_r the $response it doesnt display anything. – Devon Mar 10 '20 at 07:53
0

Wrong 'CURLOPT_HTTPHEADER' array values.

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.pipedrive.com/v1/persons/find?term=devonvermaak2%40gmail.com&start=0&search_by_email=1&api_token=e7f91c84dad486160a9744f4972d7f742de3d",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => array(
    "cache-control"=> "no-cache",
    "content-length"=> "217",
    "content-type"=> "application/json",
    "x-ratelimit-limit"=> "20",
    "x-ratelimit-remaining"=> "19",
    "x-ratelimit-reset"=> "2"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);
//because of true, it's in an array
$response = json_decode($response, true); 
print_r($response);
halfer
  • 19,824
  • 17
  • 99
  • 186
vadivel a
  • 1,754
  • 1
  • 8
  • 18