I made an API request:
# set up the request parameters
params = {
'api_key': 'XXXXXXXXXXXXXXXXXXXXXXXXX',
'type': 'product',
'item_id': 'XXXXXXXXX',
'url': 'https://www.somestore.com',
'output': 'json'
}
# make the http GET request to the API
api_result = requests.get('https://api.shopperapi.com/request', params)
product_data = json.loads(api_result.text)
if ((product_data["product.buybox_winner.seller.name"]=="MyStore.com") and (product_data["product.buybox_winner.availability.in_stock"]=="False")):
my_Mailer("Its out of stock")
THE JSON FORMAT IS:
{
"request_info": {},
"request_metadata": {},
"request_parameters": {},
"product": {
"brand": "XXX",
"title": "MyProductName",
"upc": "XXXXXXXX",
"item_id": "XXXXXXXXXX",
"product_id": "XXXXXXXXXX",
"item_number": "XXXXXXXXX",
"model": "85888",
"ratings_total": 45,
"rating": 4.6,
"type": "Housewares",
"buybox_winner": {
"price": 100.0,
"was_price": 199.95,
"currency_symbol": "$",
"id": "XXXXXXXXXXXXXXXXXXXXXXXX",
"": {
"name": "MyStore.com",
"id_secondary": "XXXXXXXXXXXXXXXXXXXXXXXXXX",
"id": "XXXXXXXXXXXXXXXXXXXXXXXXXX"
},
"availability": {
"raw": "OUT_OF_STOCK",
"in_stock": false,
"preorder": false
}
}
My error is KeyError: 'product.buybox_winner.seller.name'
I can't seem to parse this JSON file because I don't know how to reference the key correctly in order to check it.