Upload PDF to Deals

I am attempting to upload a pdf file (only 20k in size) along with a new deal and I must have the incorrect field for the file or something else. See code below ignore the Set TEXTMERGE etc I am running this through Visual Foxpro, I am able to post new deals via the API but I can’t upload files, any help would be greatly appreciated.

SET TEXTMERGE TO pipedrive.php noshow

\ // Pipedrive API token
$api_token = ‘<>’;

\ // Deal title and Organization ID
$deal = array(
\ ‘title’ => ‘<>’,
\ ‘value’=>’<>’,
\ ‘stage_id’=>‘1’,
\ ‘status’=>‘open’,
\ ‘file’ => curl_file_create(’./K2_Proposal.pdf’)

$url = ‘https://xxxxxxxx.pipedrive.com/v1/deals?api_token=’ . $api_token;
$ch = curl_init();
\Curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
\curl_setopt($ch, CURLOPT_SSLVERSION, 6);
\curl_setopt($ch, CURLOPT_URL, $url);
\curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
\curl_setopt($ch, CURLOPT_POST, true);
\curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query ($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;

For adding a file to a deal you need to use a different endpoint - POST /files. You can also check out this tutorial on adding a file with a full code example.

1 Like

I followed the code example and I am receiving the error below, any ideas?

Hi :slight_smile:
You should first create the deal, following this example.

Once you do, you can get the id of the newly created deal and pass it as deal_id (instead of person_id in the code found in this example.

Let me know if you’re still having issues with it.

maybe it’s not a problem with deal… this is the problem with file upload…