def get_my_fees_estimate_for_orders(seller_id, auth_token, access_key, secret_key, orders): if len(orders) > 4: return items = [] for order in orders: asin = order.asin is_amazon_fulfilled = order.fulfillment_channel == "Amazon" identifier = "test1" item_price = order.item_price or "0.00" item_currency_code = order.currency or "USD" shipping_price = order.shipping_price or "0.00" shipping_currency_code=order.currency or "USD" item = convert_data_to_item(asin, is_amazon_fulfilled, identifier, item_price, item_currency_code,\ shipping_price, shipping_currency_code) items.append(item) try: products_api = mws.Products(access_key=access_key, secret_key=secret_key, account_id=seller_id, auth_token=auth_token) xml = products_api.get_my_fees_estimate(feesEstimateRequestList=items).response.content parsed_fees_list = parse_fees_estimate(xml) #print(parsed_fees_list) return parsed_fees_list except Exception as e: print("Shit! There was an error.", e) return None
def get_my_fees_estimate_for_asin(seller_id, auth_token, access_key, secret_key, asin, is_amazon_fulfilled, identifier, listing_price, listing_currency_code, shipping_price="0.00", shipping_currency_code="USD", marketplace_id="ATVPDKIKX0DER", curr_try=1, max_try=3): try: item = convert_data_to_item(asin, is_amazon_fulfilled, identifier, listing_price, listing_currency_code, shipping_price, \ shipping_currency_code, marketplace_id) products_api = mws.Products(access_key=access_key, secret_key=secret_key, account_id=seller_id, auth_token=auth_token) xml = products_api.get_my_fees_estimate(feesEstimateRequestList=[item]).response.content parsed_fees_list = parse_fees_estimate(xml) return parsed_fees_list[0] except KeyError as e: print("its a key error", e) print(xml) return {} except Exception as e: print(e, item) if curr_try == max_try: return {} time.sleep(1) return get_my_fees_estimate_for_asin(seller_id, auth_token, asin, is_amazon_fulfilled, identifier, listing_price, listing_currency_code, shipping_price=shipping_price, shipping_currency_code=shipping_currency_code, marketplace_id=marketplace_id, curr_try=curr_try+1, max_try=max_try)
def list_matching_products(seller_id, auth_token, access_key, secret_key, marketplaceid, query, curr_try=1, max_try=2): products_api = mws.Products(access_key=access_key, secret_key=secret_key, account_id=seller_id, auth_token=auth_token) try: matching_products_obj = products_api.list_matching_products( marketplaceid=marketplaceid, query=query) products = parse_products_from_api(matching_products_obj) # TMP - Reconcile later #map headers to our version for the frontend hmapped_products = [] #print(products[0]) for product in products: hmapped_product = hmap_product(product) hmapped_products.append(hmapped_product) return hmapped_products except Exception as e: try: print(e) root = ET.fromstring(str(e)) error = root[0] error_type = error[0].text code = error[1].text error_message = error[2].text if code == "AccessDenied": return { "errorType": error_type, "errorCode": code, "errorMessage": error_message } else: if curr_try >= max_try: return hmapped_products else: return list_matching_products(seller_id, auth_token, access_key, secret_key, marketplaceid, query, curr_try + 1, max_try) except Exception as e: if curr_try >= max_try: return [] else: return list_matching_products(seller_id, auth_token, access_key, secret_key, marketplaceid, query, curr_try + 1, max_try)
def grab_lowest_priced_offers_for_asin(self, asin): products_api = mws.Products(access_key=self.access_key, secret_key=self.secret_key, account_id=self.seller_id, auth_token=self.auth_token) xml = products_api.get_competitive_pricing_for_asin( marketplaceid=self.marketplace_id, asins=[asin]).response.content return xml #print(xml) """
def is_valid_auth_data(seller_id, auth_token, access_key, secret_key): print("at the validation stage!!!!") products_api = mws.Products(access_key=access_key, secret_key=secret_key, account_id=seller_id, auth_token=auth_token) try: matching_products_obj = products_api.get_matching_product_for_id( marketplaceid="ATVPDKIKX0DER", type="ISBN", ids=["0470500972"]) products = parse_products_from_api(matching_products_obj) first = products[0] x = ("ASIN: " + first["ASIN"]) x = ("Publisher: " + first["Publisher"]) x = ("Rank: " + first["Rank"]) x = ("ProductCategoryId: " + first["ProductCategoryId"]) x = ("Title: " + first["Title"]) x = ("Image: " + first["SmallImage"]["URL"]) x = ("ProductTypeName: " + first["ProductTypeName"]) return True except Exception as e: print(e) return False
def get_matching_product_for_id(seller_id, auth_token, access_key, secret_key, marketplaceid, idType, id): try: products_api = mws.Products(access_key=access_key, secret_key=secret_key, account_id=seller_id, auth_token=auth_token) matching_products_obj = products_api.get_matching_product_for_id( marketplaceid=marketplaceid, type=idType, ids=id) products = parse_products_from_api(matching_products_obj) # TMP - Reconcile later #map headers to our version for the frontend hmapped_products = [] for product in products: #hmapped_product = hmap_product(product) hmapped_products.append(product) return hmapped_products, None except Exception as e: #print(e) try: root = ET.fromstring(str(e)) error = root[0] error_type = error[0].text code = error[1].text error_message = error[2].text return None, { "errorType": error_type, "code": code, "errorMessage": error_message } except Exception as e: return None, { "errorType": "unknown", "code": "unknown", "errorMessage": "unknown" }