Here is a link to the Etsy V3 API Endpoint that I want to use: https://developers.etsy.com/documentation/reference/#operation/uploadListingFile
I am trying to upload a PDF onto a listing that I have in draft status. I have looked at the etsy documentation and believe this is the correct endpoint to use however can not seem to get it working. https://openapi.etsy.com/v3/application/shops/{shop_id}/listings/{self.listing_id}/files
My function is:
def addFileToDraftListing(self, shop_id):
headers = {
"Authorization": "Bearer " + self.data["etsy_token"]["access_token"],
"x-api-key": self.data["etsy_keystring"]
}
refresh_url = "https://api.etsy.com/v3/public/oauth/token"
etsy_auth = OAuth2Session(self.data["etsy_keystring"], token=self.data["etsy_token"], auto_refresh_url=refresh_url)
file_path = "1.pdf"
with open(file_path, 'rb') as f:
file_data = f.read()
file_name = os.path.basename(file_path)
data = {
'name': file_name,
}
files={
'name': file_name,
'file': (file_path, file_data)}
r = etsy_auth.post(f"https://openapi.etsy.com/v3/application/shops/{shop_id}/listings/{self.listing_id}/files", headers=headers, files=files, data=data)
print(r.text)
The result I am getting is:
{"error":"Either a valid listing_file_id or file must be provided."}
The etsy documentation states that the only path params required is the shop_id and listing_id which I provide. It is asking for a valid listing_file_id however I can not obtain one as no file has already been uploaded. It is then asking for a binary file:
You must either provide the listing_file_id of an existing file, or the name and binary file data for a file to upload
I have tried providing that file in the form open(file_path, 'rb') and as file_data the latter being what you see above. However both thimes it is providing me with the same error.
Can someone help me with this issue I am facing? Where am I going wrong?