Hello, could someone provide me with guidance into uploading a picture to a ‘person’ through API
Support gave me this POST exemple which seems ill-formed:
Pipedrive API v1 Reference
I am using python requests.
headers = {"Accept": "application/json"}
r = requests.post(_api_endpoint + 'persons/' + str(31) +
'/picture' + _api_token, headers=headers, files=files)
dani
August 21, 2018, 8:30am
2
Hi Cristina. The example looks good.
I think there’s probably an issue with how the request is formatted.
Can you post the full request snippet of your code? (Make sure you remove your API token and other private information )
Sure, here is full code, trying to upload google icon as an image.
Works manually through the interface perfectly, but not with API
import requests
from io import BytesIO
_api_token = '?api_token=xxxxxxxxxxxxxxxxx'
_api_endpoint = 'https://api.pipedrive.com/v1/'
def main():
img = requests.get('http://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png')
with BytesIO(img.content) as f:
files = {'file': f}
headers = {"Accept": "application/json"}
r = requests.post(_api_endpoint + 'persons/' + str(31) + '/picture' + _api_token, headers=headers, files=files)
print(r.status_code)
returns with r.status_code == 500
dani
August 22, 2018, 7:56am
5
Ok. I figured it out
The issue is here:
files = {'file': f}
It should be
files = {'file': ('imagename.png', img.content, 'image/png')}
Also, you don’t need to use BytesIO. You can just use img.content
.
Here’s a working snippet (you need to change the id passed in the url):
import requests
_api_token = '?api_token=xxx'
_api_endpoint = 'https://api.pipedrive.com/v1/'
def main():
img = requests.get('http://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png')
files = {'file': ('imagename.png', img.content, 'image/png')}
headers = {"Accept": "application/json"}
r = requests.post(_api_endpoint + 'persons/65/picture' + _api_token, headers=headers, files=files)
main()
1 Like
Thank you Dani, it worked like a charm.
Sadly, we are disappointed that there is no way to display those picture in the application (iOS)
A touch-to-display fullscreen would be great.
dani
August 27, 2018, 11:00am
7
Glad it worked I’m not sure what you mean about the iOS app. The profile picture should be visible both in the contact list and in the contact’s details page.
Indeed, as you can see it is very very small when you picture it.
hence the request for a tap-to-fullscreen / tap-to-close feature
dani
August 28, 2018, 11:38am
9
Got it. Thank you for the feedback.
1 Like
Hem
Split this topic
February 7, 2022, 9:52am
10