Upload a file using PHP/Curl

Hi there,

I’m new to both pipedrive & PHP so any help would be appreciated. I’m currently trying to add a file to a deal but to no avail.

My code is as follows:

if (!empty($result[‘data’][‘id’])) {
$_SESSION[‘deal_id’] = $result[‘data’][‘id’];

        $deal = array(
          'file' => $_SESSION['file'],
          'deal_id' => $_SESSION['deal_id']

        $url = 'https://api.pipedrive.com/v1/files';

        $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);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

        $output = curl_exec($ch);

        $result = json_decode($output, true);


Thank you!

Hi @jakealdred I’m afraid I cannot really help you with specific code, however, I can provide you some resources in relation to how to upload files via API, First of all, as you can see in our API reference page you need to use the multipart/form-data encoding (you can learn more about this here: https://philsturgeon.uk/api/2016/01/04/http-rest-api-file-uploads).

Also, since you want to use PHP maybe you can consider using this php client for our api: https://github.com/IsraelOrtuno/pipedrive

Hope this helps!


Thanks a lot Diego, I’ll check those links out now