Attaching file in pipedrive

Question asked in StackOverflow
(https://stackoverflow.com/questions/45986996/attaching-file-in-pipedrive)

Pipedrive API v1 Reference Doesn’t show request example and I can’t send POST request via python.

My error is: “No files provided”

Maybe someone has an example for this request?

My code:

import requests

with open('qwerty.csv', 'rb') as f:
    r = requests.post('https://api.pipedrive.com/v1/files',
                      params={'api_token': 'MY_TOKEN'}, files={'file': f})
1 Like

Ah, all you need is check request in chrome develop tools and play with it for some time.

import requests

files = {'file': ('FILE_NAME', open('fgsfds.jpg', 'rb'), 'CONTENT_TYPE')}
r = requests.post('https://api.pipedrive.com/v1/files',
                  params={'api_token': 'TOKEN'}, 
                  data={'file_type':'img', 'deal_id':DEAL_ID}, files=files)

Hi!

What is the max file size for uploading?

The max should be 50MB.
I’m about 97% sure.

1 Like

Code that works to upload file:

import requests
api_token = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
headers = {
    'X-Api-Token': str(api_token),
    'User-Agent': "Testing",
    'Cache-Control': "no-cache",
    'Host': "api.pipedrive.com"
}

id = 1
files = {'file': ('file_name_in_pd.jpg', open('existing_file_name.jpg', 'rb'), 'img')}
url='https://api.pipedrive.com/v1/files'
r = requests.post(url, headers=headers, data={'deal_id':id}, files=files)

print(r)
2 Likes

Hi jaan.molder,

Could I please have an example of uploading a file in NodeJS?

Because I am getting an error as Pipedrive API error:Invalid File Create request - data contains invalid keys while adding a file by using the endpoint (pipedrive.Files.add(data, [callback])). I have used the data keys as per the given documentations.

My data to upload the file is shown below.

let dataToAddFile = {
file: pdfToBeUploaded,
deal_id: 1
}

1 Like

Hi Varinder,

You can use PipeDrive Npm in node Js for attaching a files to a deal

Using Files.add method

Thanks David, very helpful ! Do you also have sample code to do the same file upload in VBA ? I would like to attach an Excel offer to a deal…