Delete all attached products from a deal

How would you delete all the attached products from a deal based on the deal ID?

First, you can get the list of products attached to a deal with
GET /deals/{id}/products

Then if you want to only remove the attachment, you can use
DELETE /deals/{id}/products/{product_attachment_id}

If instead you actually want to delete the product, you can use
DELETE /products/{id}

Thanks! Solved.
Didn’t figure that the id in the “list all products” is the product_attachment_id

1 Like

How can I remove all the products from an ID, without having to delete one by one?
Thanks in advance

Hi @cyberpolito

Unfortunately we don’t yet support Bulk actions via API so here isn’t a way to remove all from an ID.

Hopefully we can add bulk options in the future.

Thanks David, and in this code:

$url = 'https://api.pipedrive.com/v1/deals/'.$IDPipe.'/products?start=0&api_token=xxxx';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch);
$result = json_decode($output, true);
$result2=$result['data'];
$array_num = count($result2);

for ($i = 0; $i < $array_num; ++$i){
        $url = 'https://api.pipedrive.com/v1/deals/'.$IDPipe.'/products/'.$result2[$i]['id'].'?api_token=xxx';
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
        $output = curl_exec($ch);
        curl_close($ch);              
}

Can I pass a multiple array to the curl call to delete all products of deal?.
I’m looking to speed up time but it takes a long time to delete one by one

No, unfortunately not.

We have some things you could do in bulk this way (like Delete Deals), but we don’t support bulk deleting of Activities at this time (including in array).

Thanks David, I hope they implement it in the future.
Using array would be a very good solution.
Regards

1 Like