I am trying to work with Etsy API, to create a listing, upload images and download files (for digital product).
I have a working functions for listing creation and image upload, but I have some problems with file upload. By documentation (https://developers.etsy.com/documentation/reference/#operation/uploadListingFile) it seems very similar to image upload, however it doesn't work for me.
The function I am using is this:
def upload_file(keystring,token,shop_id,listing_id,file):
headers = {
"Accept": "application/json",
"x-api-key": keystring,
"Authorization" : f"Bearer {token}"
}
url = f"https://openapi.etsy.com/v3/application/shops/{shop_id}/listings/{listing_id}/files"
files = {'file': ('10.png', open(file,'rb'))}
response = requests.post(
url=url,
headers=headers,
files=files
)
if response.status_code == 200:
print(response.json())
else:
print('Upload failed with status code:', response.status_code)
print(response.json())
And as a response, I get 400:
'A valid name must be provided with a new file.'
Maybe someone has any ideas or have a working function for this task.
OK, got everything working.
For others interested, you need to pass data in this format:
replacing 10.png to real file name