0

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})
Kuizame
  • 158
  • 1
  • 6

2 Answers2

0

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)
Ilhicas
  • 1,429
  • 1
  • 19
  • 26
  • Did you work with this API endpoint? Maybe you have some raw request example? – Kuizame Aug 31 '17 at 17:57
  • Sorry, I've never worked with it before, but that's how I usually interact with uploading files to api's with requests lib. – Ilhicas Aug 31 '17 at 18:02
0

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.

Maurice
  • 11,482
  • 2
  • 25
  • 45
Kuizame
  • 158
  • 1
  • 6