Uploading picture in person

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)

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 :slight_smile: )

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

Ok. I figured it out :slight_smile:
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.

Glad it worked :slight_smile: 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

Got it. Thank you for the feedback.

1 Like

A post was split to a new topic: Updating profile picture of a person (preferably via Zapier)