PHP and API Integration

I am using the tutorial to “create a new deal” I have correctly entered the API Token,organization ID and company domain. Every time I run the script “create_deal.php” the request is sent but I do not get a response and the deal isn’t posted. Any help would be appreciated!!
I am using PHP 7.3.5, and below is the code:

// Content of create_deal.php
// Pipedrive API token
$api_token = 'xxxxx';
// Deal title and Organization ID
$deal = array(
  'title' => 'New Deal Test',
  'org_id' => '1'
$url = 'https://<company-domain>' . $api_token;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $deal);
echo 'Sending request...' . PHP_EOL;
$output = curl_exec($ch);
// Create an array from the data that is sent back from the API
// As the original content from server is in JSON format, you need to convert it to PHP array
$result = json_decode($output, true);
// Check if an ID came back, if did print it out
if (!empty($result['data']['id'])) {
   echo 'Deal was added successfully!' . PHP_EOL;

Is curl set up correctly on your machine/server?

P.S. (Please change your API token, and avoid posting it in the future for security reasons :wink: )

I have verfied that Curl is working correctly, I curled Google and received a response. Still not able to post new deals? API token changed too.

Try changing this

curl_setopt($ch, CURLOPT_POSTFIELDS, $deal);


curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($deal));



I corrected the line to “curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($deal));” and still no response from the API.

What do you get if you just echo the whole $output? (After calling curl_exec)

echo $output;

No response after the echo.

And, just to make sure, this is after curl_exec?

Have you already tried debugging line by line?

What about the TLS version? Are you using TLS 1.2?

I debugged PHP and even turned on error reporting just to be sure, no issues. I just added “curl_setopt($ch, CURLOPT_SSLVERSION, 6);” to force TLS 1.2. still getting no response.

Just asking has anyone gotten the sample code to work from the tutorial?

Yes, it’s a very simple script… I also just re-tested it just to make sure.

I can’t think of much else in this moment, honestly. You could try to:

  • Make the same (similar) POST request to another API to isolate the problem (I suspect it’s something to do with CURL on your machine)
  • Check if any request is actually firing at all


I got it! I added not to verify the peer “curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);” and the deal added!!! :slight_smile:

Thanks for your help

1 Like