Attaching file in pipedrive

542 views Asked by At

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})
2

There are 2 answers

0
Kuizame On

Well, I was dumb.

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)

Update

Recently used this endpoint (Feb 2021). Turns out the endpoint doesn't accept the 'file_type' parameter anymore.

2
Ilhicas On

Try to decouple the operation.

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