Update Person's Picture with Python (pipedrive-python)

Hi all,

I would like to update a person’s picture via the Pipedrive API. It looks like /v1/persons/{id}/picture is not supported in pipedrive-python.

I could not figure out how to add this myself and get an Error 404. Maybe someone has solved this before and could provide a code snippet?

import requests
token = {'api_token': apikey}
put_url = 'https://company.pipedrive.com/api/v1/persons/438/picture'
img = requests.get("https://a.slack-edge.com/a533fe3/marketing/img/media-kit/img-logos-alt@2x.png")
put_payload = {'file': ('imagename.png', img.content, 'image/png')}
put_response = requests.put(put_url, params=token, data=put_payload)
print(put_response)

Thank you
Max

I have solved it like this

url = f'https://company.pipedrive.com/api/v1/persons/{person_id}/picture?api_token={pd_api_key}'
    image_url = "https://someimage.jpeg"
    image_content = requests.get(image_url).content

    try:
      pdimg_response = requests.post(url, files={"file": ("someimage.jpeg", image_content, 'image/jpeg')})
      print("Success:", "https://company.pipedrive.com/person/"+str(person_id))
    except Exception as e: 
      print("Error:", "https://company.pipedrive.com/person/"+str(person_id),e)
      
1 Like

Hey @max5000
Thank you very much for sharing the working solution with the community members. :100: !!