Search code examples
phppipedrive-api

Pipedrive delete a deal with API


I am trying to delete a deal using through the API. The code I have written is below , but its not working. I am not able to figure out where to add the Method "DELETE" while making the call.I am not getting any error message in output. Please suggest.

<?php
$api_token = "myapitoken";

 $url = "https://api.pipedrive.com/v1/deal?api_token=" . $api_token;

 $deal = array(
  'id' => 375,
  'method' => 'DELETE'
  );

 $ch = curl_init();
 curl_setopt($ch, CURLOPT_URL, $url);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 curl_setopt($ch, CURLOPT_POST, true);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $deal);
 $output = curl_exec($ch);
 $info = curl_getinfo($ch);
 curl_close($ch);
 $result = json_decode($output);


?>

Solution

  • Deleting deal on pivedrive can be done using following code

    $id= "deal_id";
    $url = "https://api.pipedrive.com/v1/deals/". $id ."?api_token=" . $api_token;
    
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
     $result = curl_exec($ch);
     $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
     curl_close($ch);