OAuth and Python and GET

112 views
Skip to first unread message

West Dennis

unread,
Jun 29, 2021, 1:28:51 PM6/29/21
to Etsy API
Hi,
I'm able to get listings and inventory from my shop using python.  Now I want to get the SKU on variations.  For this I need permissions.  I have gone through the process of getting the secret keys by authorizing the app with a scope of listings_r and listings_w.  Now I just need to get the authorization working with a GET.   For testing purposes, i have an inactive listing so I'm trying to use the method of findAllShopListingsInactive.   I get a 403 code back which means i don't have permission.
Can anyone provide a nice example of doing a simple privileged GET using python?
I think I'm probably not building oauth data into the header of the request, but ???

thank you for any insight.

West

Tima M

unread,
Jun 29, 2021, 2:02:01 PM6/29/21
to Etsy API
Here's what I do:

from requests_oauthlib import OAuth1Session

api_key = '***'
shared_secret = '***'
oauth_token = '***'
oauth_token_secret = '***'

etsy = OAuth1Session(client_key=api_key,
                            client_secret=shared_secret,
                            resource_owner_key=oauth_token,
                            resource_owner_secret=oauth_token_secret)


West Dennis

unread,
Jun 30, 2021, 8:29:06 AM6/30/21
to Etsy API
Hi Tima,
Thank you for the response.  I could swear I tried that method.  I removed my apps authorization from my shop and fetched a new set of oauth keys and re-validated the app.   I tried your code with the new keys and i am now pulling the sku from the variations in the inventory for a listing.  Just baby steps at this point but progress is being made.   Thank you again for your reply.
btw, here's my test code...

import json
import requests
from requests_oauthlib import OAuth1Session

api_key = "*****"
shared_secret = "*****"
oauth_token = "*****"
oauth_token_secret = "*****"

etsy = OAuth1Session(client_key=api_key,
                            client_secret=shared_secret,
                            resource_owner_key=oauth_token,
                            resource_owner_secret=oauth_token_secret)

list_text = r.json()
list_id = str(list_text['results'][-1]['listing_id'])
list_title = list_text['results'][-1]['title']
print ("list_id = ", list_id, "-", list_title)
e_url = "https://openapi.etsy.com/v2/listings/"+list_id+"/inventory"
r = etsy.get(e_url)
list_text = r.json()
for inpart in list_text['results']['products']:
    print (inpart['sku'],"-",inpart['property_values'][0]['values'][0]," - ",inpart['offerings'][0]['quantity']," - ",inpart['offerings'][0]['price']['currency_formatted_raw'])
Reply all
Reply to author
Forward
0 new messages