So I've been working with the Etsy Api for some days now and it seems to be one problem after another. Their examples and their Authentication are not very clear to me and many others it seems. So i'm having problems with it. And getting any sort of help with support of questions is slow and unresolved.
So I have two issues i'm battling with the Etsy API working with Python.
First i'm able to get my authentication. I then send a refresh_token request back with the refresh_token back but get no expiration on what i get in return which is a new token and a new refresh_token, but it seems like they both expire again after an hour and not 90 days on the refresh. here is the first on the refresh token issue. Here what i'm sending back. And i'm setting my token and an expiration so i can manually just run it without getting 401 and rerequesting.
def refreshing_token(token,keystring,redirect_url,scopes,file_path,token_url):
try:
token_time = time.time()
refresh_token = token['refresh_token']
headers = {"Accept": "application/json",
"Content-Type": "application/x-www-form-urlencoded",
"x-api-key": keystring}
data = {
"grant_type": "refresh_token",
"client_id": keystring,
"refresh_token": refresh_token}
response = requests.post(token_url, data=data, headers=headers)
if response.status_code == 200:
token = response.json()
token['token_time'] = token_time
token['refreshed'] = True
token['expiration'] = token['token_time'] + 7344000#85 Days time in seconds
else: print(response.status_code)
return token
except Exception as e:
clerical.exception_function(e, ' ')
With that it doesn't seem like I'm not at all sure what that token request time is.
On to the second and major issue I have is that i cannot create a draft listing. I'm trying to create a digital download and so I'm being told that it requires a shipping_profile_id for a physical listing, but i'm trying to create a digital. I'm not even sure how the file upload request can be included in this. This is my request but i can't get past a 400 status code. And i can't find something that allows me to upload the ListingFile at the same time.
def create_draft_listing(keystring,products,product,access_token,product_package,store_settings,token):
try:
temp_text_output(products,product)
access_token = token['access_token']
endpoint = f"https://api.etsy.com/v3/application/shops/{store_settings['store_id']}/listings"
headers = {"Authorization": f"Bearer {access_token}",
"Content-Type": "application/x-www-form-urlencoded",
"Accept": "application/json",
"x-api-key": keystring}
data = {"title": product_package['title'],
"description": product_package['description'],
"price": product_package['price'],
"taxonomy_id": product_package['taxonomy_id'],
"tags": product_package['tags'],
"who_made": product_package['who_made'],
"sku": product_package['sku'],
"quantity": int(product_package['quantity']),
"is_digital": True,
"is_supply": False,
"should_auto_renew": True,
"when_made": product_package['when_made']} # Don't know about 'image_ids' yet
response = requests.post(endpoint, headers=headers, data=data)
if response.status_code == 200:
listing = response.json()
else:
print(response.text)
pass
# Get Listing_id from the response
listing_id = listing['listing_id']
product_package['listing_id'] = listing_id
with open(f"{store_settings['store_folder']}/{products}/{product_file}/product_package.json",'w') as json_file:
json.dump(product_package, json_file, indent=4)
pass
return product_package
except Exception as e:
clerical.exception_function(e, ' ')
Everything after the response request is untested as i can't get through to that as i can't get a 200 no matter what i've seemed to do and i've been working a few days and many things on it. It seems there isn't much on this, and less in python. Any assistance I could get would really help me and be greatly appreciated. If i can get this and for it to upload the file would be most helpful. Thank you in advance for any help I can get.