Attaching file in pipedrive

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

https://developers.pipedrive.com/docs/api/v1/#!/Files/post_files 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