etsy API 3 upload image in python

167 views
Skip to first unread message

Jan Masar

unread,
Sep 20, 2021, 8:51:25 AM9/20/21
to Etsy API
Hello
I'm working with etsy API 3 on my website and I'm stuck on how to upload image to my draft listing in python.

I was tryng all this solutions:

headers = {
    "Content-Type": "multipart/form-data",
    "x-api-key": settings.ETSY_API_KEY,
    "Authorization": f"Bearer {access_token}"  # listings_w set in scope
}
image_file = open('static/images/CACHE/images/product/000063_1-dsc05556/test_file.jpg', 'rb')
read_image_file = image_file.read()
read_image_file_bytes = base64.b64encode(read_image_file)
read_image_file_bytes_str = "".join([format(n, 'b') for n in read_image_file_bytes])

try1 = requests.post(url=url, headers=headers, data={'image': img})
try2 = requests.post(url=url, headers=headers, data={'image': read_image_file})
try3 = requests.post(url=url, headers=headers, data={'image': read_image_file_bytes})
try4 = requests.post(url=url, headers=headers, data={'image': read_image_file_bytes_str})

# trying to set existing image from my other listing
try_5 = requests.post(url=url, headers=headers, data={'listing_image_id': 2853097528})

but I always get the same response:
{'error': 'Either a valid image file or a listing_image_id must be provided.'}

Could you please let me know what I'm doing wrong?

Thank you
Jan

Adam Grant

unread,
Sep 22, 2021, 3:59:43 PM9/22/21
to Etsy API
I'm having the exact same problem when uploading images through the API, the URLs I'm using for my images are valid, but after it uploads 10 images or so it throws out errors saying URL invalid, after an hour or so it will let me do around another 10 images then does the same thing again.

Jan Masar

unread,
Sep 30, 2021, 2:56:08 PM9/30/21
to Etsy API

Could you please post here your PYTHON solution? Then at least I will know which one is working or which one should be working. Because none of mine (try1 to try5) is working. Im not able to add any image. 

Thank you.

Gareth Doherty

unread,
Oct 14, 2021, 8:29:24 AM10/14/21
to Etsy API

Julio Camejo Corona

unread,
Nov 18, 2021, 10:05:53 AM11/18/21
to Etsy API
Hello, I found the solution. The main key to the problem is sending "Content-Type" and that it's causing the error. My final code is:
files = {
"image": open(file_path, 'rb')
}
headers = {
"Authorization": "Bearer " + user_token,
"x-api-key": X_API_KEY
Reply all
Reply to author
Forward
0 new messages