Adding files to deal duplicates deal

I have a fairly straightforward piece of code for adding files to a deal. However, a deal is added TWICE when I use this code. I have no idea why this happens.

function addPipedriveFile($file,$api_token,$company_domain,$dealId){

$data = array(
	'file' => curl_file_create($file),
	'deal_id' => $dealId
// URL for adding a file
$url = 'https://' . $company_domain . '' . $api_token;
$fileCurl = curl_init();
curl_setopt($fileCurl, CURLOPT_URL, $url);
curl_setopt($fileCurl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($fileCurl, CURLOPT_POST, true);
curl_setopt($fileCurl, CURLOPT_POSTFIELDS, $data);
$output = curl_exec($fileCurl);

Code used to call this function:

$signed = $solarLead->quote->quote_signed_file_location;
$signedBase = basename($signed);
file_put_contents($signedBase, fopen($signed, 'r'));
addPipedriveFile($signedBase,$api_token,$company_domain,$dealId); // Add signed document for quote

foreach ($solarLead->documents as $document) { // Loop through various other documents
	$signedBase = basename($document);
	file_put_contents($signedBase, fopen($document, 'r'));


@KevinB welcome to the community :wave:
From the looks of it, the 1st snippet seems to be attaching a file and looks good. I see a couple of possibilities here

  • Do you perform deal creation at any point in time? as a sub-logic in the 2nd snippet ?
  • Is there an automation setup in place that is reacting to these events?

Hope you were able to fix the issue. Feel free to create a new topic if the issue persists :slight_smile: