File size: 10,103 Bytes
a51a15b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
from typing import Dict, Optional
from agent.tools.data_providers.RapidDataProviderBase import RapidDataProviderBase, EndpointSchema
class AmazonProvider(RapidDataProviderBase):
def __init__(self):
endpoints: Dict[str, EndpointSchema] = {
"search": {
"route": "/search",
"method": "GET",
"name": "Amazon Product Search",
"description": "Search for products on Amazon with various filters and parameters.",
"payload": {
"query": "Search query (supports both free-form text queries or a product asin)",
"page": "Results page to return (default: 1)",
"country": "Sets the Amazon domain, marketplace country, language and currency (default: US)",
"sort_by": "Return the results in a specific sort order (RELEVANCE, LOWEST_PRICE, HIGHEST_PRICE, REVIEWS, NEWEST, BEST_SELLERS)",
"product_condition": "Return products in a specific condition (ALL, NEW, USED, RENEWED, COLLECTIBLE)",
"is_prime": "Only return prime products (boolean)",
"deals_and_discounts": "Return deals and discounts in a specific condition (NONE, ALL_DISCOUNTS, TODAYS_DEALS)",
"category_id": "Find products in a specific category / department (optional)",
"category": "Filter by specific numeric Amazon category (optional)",
"min_price": "Only return product offers with price greater than a certain value (optional)",
"max_price": "Only return product offers with price lower than a certain value (optional)",
"brand": "Find products with a specific brand (optional)",
"seller_id": "Find products sold by specific seller (optional)",
"four_stars_and_up": "Return product listings with ratings of 4 stars & up (optional)",
"additional_filters": "Any filters available on the Amazon page but not part of this endpoint's parameters (optional)"
}
},
"product-details": {
"route": "/product-details",
"method": "GET",
"name": "Amazon Product Details",
"description": "Get detailed information about specific Amazon products by ASIN.",
"payload": {
"asin": "Product ASIN for which to get details. Supports batching of up to 10 ASINs in a single request, separated by comma.",
"country": "Sets the Amazon domain, marketplace country, language and currency (default: US)",
"more_info_query": "A query to search and get more info about the product as part of Product Information, Customer Q&As, and Customer Reviews (optional)",
"fields": "A comma separated list of product fields to include in the response (field projection). By default all fields are returned. (optional)"
}
},
"products-by-category": {
"route": "/products-by-category",
"method": "GET",
"name": "Amazon Products by Category",
"description": "Get products from a specific Amazon category.",
"payload": {
"category_id": "The Amazon category for which to return results. Multiple category values can be separated by comma.",
"page": "Page to return (default: 1)",
"country": "Sets the Amazon domain, marketplace country, language and currency (default: US)",
"sort_by": "Return the results in a specific sort order (RELEVANCE, LOWEST_PRICE, HIGHEST_PRICE, REVIEWS, NEWEST, BEST_SELLERS)",
"min_price": "Only return product offers with price greater than a certain value (optional)",
"max_price": "Only return product offers with price lower than a certain value (optional)",
"product_condition": "Return products in a specific condition (ALL, NEW, USED, RENEWED, COLLECTIBLE)",
"brand": "Only return products of a specific brand. Multiple brands can be specified as a comma separated list (optional)",
"is_prime": "Only return prime products (boolean)",
"deals_and_discounts": "Return deals and discounts in a specific condition (NONE, ALL_DISCOUNTS, TODAYS_DEALS)",
"four_stars_and_up": "Return product listings with ratings of 4 stars & up (optional)",
"additional_filters": "Any filters available on the Amazon page but not part of this endpoint's parameters (optional)"
}
},
"product-reviews": {
"route": "/product-reviews",
"method": "GET",
"name": "Amazon Product Reviews",
"description": "Get customer reviews for a specific Amazon product by ASIN.",
"payload": {
"asin": "Product asin for which to get reviews.",
"country": "Sets the Amazon domain, marketplace country, language and currency (default: US)",
"page": "Results page to return (default: 1)",
"sort_by": "Return reviews in a specific sort order (TOP_REVIEWS, MOST_RECENT)",
"star_rating": "Only return reviews with a specific star rating (ALL, 5_STARS, 4_STARS, 3_STARS, 2_STARS, 1_STARS, POSITIVE, CRITICAL)",
"verified_purchases_only": "Only return reviews by reviewers who made a verified purchase (boolean)",
"images_or_videos_only": "Only return reviews containing images and / or videos (boolean)",
"current_format_only": "Only return reviews of the current format (product variant - e.g. Color) (boolean)"
}
},
"seller-profile": {
"route": "/seller-profile",
"method": "GET",
"name": "Amazon Seller Profile",
"description": "Get detailed information about a specific Amazon seller by Seller ID.",
"payload": {
"seller_id": "The Amazon Seller ID for which to get seller profile details",
"country": "Sets the Amazon domain, marketplace country, language and currency (default: US)",
"fields": "A comma separated list of seller profile fields to include in the response (field projection). By default all fields are returned. (optional)"
}
},
"seller-reviews": {
"route": "/seller-reviews",
"method": "GET",
"name": "Amazon Seller Reviews",
"description": "Get customer reviews for a specific Amazon seller by Seller ID.",
"payload": {
"seller_id": "The Amazon Seller ID for which to get seller reviews",
"country": "Sets the Amazon domain, marketplace country, language and currency (default: US)",
"star_rating": "Only return reviews with a specific star rating or positive / negative sentiment (ALL, 5_STARS, 4_STARS, 3_STARS, 2_STARS, 1_STARS, POSITIVE, CRITICAL)",
"page": "The page of seller feedback results to retrieve (default: 1)",
"fields": "A comma separated list of seller review fields to include in the response (field projection). By default all fields are returned. (optional)"
}
}
}
base_url = "https://real-time-amazon-data.p.rapidapi.com"
super().__init__(base_url, endpoints)
if __name__ == "__main__":
from dotenv import load_dotenv
load_dotenv()
tool = AmazonProvider()
# Example for product search
search_result = tool.call_endpoint(
route="search",
payload={
"query": "Phone",
"page": 1,
"country": "US",
"sort_by": "RELEVANCE",
"product_condition": "ALL",
"is_prime": False,
"deals_and_discounts": "NONE"
}
)
print("Search Result:", search_result)
# Example for product details
details_result = tool.call_endpoint(
route="product-details",
payload={
"asin": "B07ZPKBL9V",
"country": "US"
}
)
print("Product Details:", details_result)
# Example for products by category
category_result = tool.call_endpoint(
route="products-by-category",
payload={
"category_id": "2478868012",
"page": 1,
"country": "US",
"sort_by": "RELEVANCE",
"product_condition": "ALL",
"is_prime": False,
"deals_and_discounts": "NONE"
}
)
print("Category Products:", category_result)
# Example for product reviews
reviews_result = tool.call_endpoint(
route="product-reviews",
payload={
"asin": "B07ZPKN6YR",
"country": "US",
"page": 1,
"sort_by": "TOP_REVIEWS",
"star_rating": "ALL",
"verified_purchases_only": False,
"images_or_videos_only": False,
"current_format_only": False
}
)
print("Product Reviews:", reviews_result)
# Example for seller profile
seller_result = tool.call_endpoint(
route="seller-profile",
payload={
"seller_id": "A02211013Q5HP3OMSZC7W",
"country": "US"
}
)
print("Seller Profile:", seller_result)
# Example for seller reviews
seller_reviews_result = tool.call_endpoint(
route="seller-reviews",
payload={
"seller_id": "A02211013Q5HP3OMSZC7W",
"country": "US",
"star_rating": "ALL",
"page": 1
}
)
print("Seller Reviews:", seller_reviews_result)
|