Building a Python Tool for Amazon Sales Rank Monitoring
For Amazon businesses and market analysts, understanding sales rank is crucial for competitive analysis, inventory management, and market research. Tracking these ranks manually can be time-consuming and inefficient. This blog post guides you through building a Python tool that automates Amazon sales rank monitoring using the SellerMagnet API, an enterprise-grade Amazon data API.
Why Monitor Amazon Sales Rank?
- Competitive Analysis: Identify top-performing products in your niche.
- Inventory Management: Predict demand and optimize stock levels.
- Market Research: Spot emerging trends and market opportunities.
Prerequisites
Before you start, make sure you have:
- Python 3.6+ installed.
- A SellerMagnet API key. You can try it for free.
- The
requests
library installed:pip install requests
Step-by-Step Guide
1. Setting up the Environment
Create a new Python file (e.g., amazon_rank_monitor.py
) and import the necessary libraries:
import requests
import json
API_KEY = "YOUR_API_KEY" # Replace with your actual API key
2. Fetching Product Statistics with SellerMagnet API
Use the Amazon Product Statistics endpoint to retrieve the sales rank for a specific product.
Endpoint: /amazon-product-statistics
Method: GET
Parameters:
asin
(required): Product ASIN (e.g., "B08N5WRWNW")marketplaceId
(required): Marketplace ID (e.g., "A1PA6795UKMFR9" for Amazon.de)api_key
(required): Your API key
Here’s a Python function to fetch product statistics:
def get_product_stats(asin, marketplace_id, api_key):
url = f"https://sellermagnet-api.com/amazon-product-statistics?asin={asin}&marketplaceId={marketplace_id}&api_key={api_key}"
response = requests.get(url)
response.raise_for_status() # Raise HTTPError for bad responses (4xx or 5xx)
return response.json()
Example Usage:
asin = "B08N5WRWNW"
marketplace_id = "A1PA6795UKMFR9" # Amazon.de
product_data = get_product_stats(asin, marketplace_id, API_KEY)
if product_data["success"]:
sales_rank = product_data["data"]["bestSellerRank"]
print(f"Sales Rank for {asin}: {sales_rank}")
else:
print(f"Error: {product_data}")
Example Response:
{
"success": true,
"data": {
"asin": "B08N5WRWNW",
"amazonPrice": 2999,
"bestSellerRank": 15,
"buyBoxPrice": 2999,
"buyBoxFulfillment": "FBA",
"buyBoxSellerIdHistory": [
[
"2024-07-24T12:00:00Z",
"A1234567890123"
]
],
"salesRankHistory": [
[
"2024-07-24T12:00:00Z",
15
]
],
"trackingSince": "2023-01-01"
}
}
3. Building the Monitoring Tool
To create a basic monitoring tool, schedule the function to run at regular intervals. For simplicity, we'll use a loop with a delay. For more robust scheduling consider using DataPipeline tools.
import time
def monitor_sales_rank(asin, marketplace_id, api_key, interval_seconds=3600):
while True:
product_data = get_product_stats(asin, marketplace_id, api_key)
if product_data["success"]:
sales_rank = product_data["data"]["bestSellerRank"]
print(f"{time.ctime()}: Sales Rank for {asin}: {sales_rank}")
else:
print(f"{time.ctime()}: Error: {product_data}")
time.sleep(interval_seconds)
# Example Usage:
monitor_sales_rank(asin, marketplace_id, API_KEY)
4. Storing the Data
For trend analysis, store the sales rank data in a database (e.g., SQLite, PostgreSQL) or a CSV file. Here’s how to append data to a CSV file:
import csv
import time
def monitor_sales_rank(asin, marketplace_id, api_key):
filename = f"{asin}_sales_rank.csv"
file_exists = os.path.isfile(filename)
with open(filename, mode='a', newline='') as csvfile:
csv_writer = csv.writer(csvfile)
if not file_exists:
csv_writer.writerow(['Timestamp', 'Sales Rank'])
while True:
product_data = get_product_stats(asin, marketplace_id, api_key)
if product_data["success"]:
sales_rank = product_data["data"]["bestSellerRank"]
timestamp = time.ctime()
csv_writer.writerow([timestamp, sales_rank])
print(f"{timestamp}: Sales Rank for {asin}: {sales_rank}")
else:
print(f"{time.ctime()}: Error: {product_data}")
time.sleep(3600)
import os
monitor_sales_rank(asin, marketplace_id, API_KEY)
5. Visualizing the Data
Use libraries like matplotlib
or seaborn
to visualize sales rank trends. You can also request graphs directly from the Amazon Product Statistics endpoint by using graphs=true
.
Example API Call with Graphs:
curl "https://sellermagnet-api.com/amazon-product-statistics?asin=B08N5WRWNW&marketplaceId=A1PA6795UKMFR9&api_key=YOUR_API_KEY&graphs=true"
This will return URLs to pre-generated graphs, like:
{
"success": true,
"data": {
"asin": "B0CLTBHXWQ",
"productTitle": "Playstation 5 Console Edizione Digital Slim",
"buyBoxPrice": 41800,
"buyBoxFulfillment": "FBM",
"buyBoxSellerIdHistory": [
[
"2025-06-14 17:08:00",
"A2I59UVTUWUFH0"
]
],
"categoryTree": [
{
"catId": 412603031,
"name": "Videogiochi"
},
{
"catId": 20904349031,
"name": "PlayStation 5"
},
{
"catId": 20904364031,
"name": "Console"
}
],
"graphs": {
"amazonAsSellerPriceHistory": "https://sellermagnet-api-webspace.s3.eu-central-1.amazonaws.com/amazon/api/charts/B0CLTBHXWQ/1749913774/B0CLTBHXWQ_amazon_price_1749913773.png",
"lowestFBAPriceHistory": "https://sellermagnet-api-webspace.s3.eu-central-1.amazonaws.com/amazon/api/charts/B0CLTBHXWQ/1749913776/B0CLTBHXWQ_fba_price_1749913773.png",
"lowestFBMPriceHistory": "https://sellermagnet-api-webspace.s3.eu-central-1.amazonaws.com/amazon/api/charts/B0CLTBHXWQ/1749913775/B0CLTBHXWQ_fbm_price_1749913773.png",
"monthlySoldHistory": "https://sellermagnet-api-webspace.s3.eu-central-1.amazonaws.com/amazon/api/charts/B0CLTBHXWQ/1749913778/B0CLTBHXWQ_monthly_sold_1749913773.png",
"productRatingHistory": "https://sellermagnet-api-webspace.s3.eu-central-1.amazonaws.com/amazon/api/charts/B0CLTBHXWQ/1749913777/B0CLTBHXWQ_rating_1749913773.png"
},
"listedSince": "2023-12-30 01:00:00",
"lowestFBAPrice": 44999,
"lowestFBMPrice": 41700,
"marketplaceId": "APJ6JRA9NG5V4",
"marketplaceNewPriceHistory": [
[
"2025-06-14",
41700
]
],
"offers": {
"A11IL2PNWYJU7H": {
"isFBA": true,
"lastUpdated": "2025-06-14 17:08:00",
"priceHistory": [
[
"2025-06-14 06:22:00",
44999,
0
]
],
"stockHistory": [
[
"2025-05-29 11:32:00",
1
]
]
},
"A12FLY25DT7QO0": {
"isFBA": false,
"lastUpdated": "2025-06-14 17:08:00",
"priceHistory": [
[
"2025-06-09 15:32:00",
41800,
0
]
],
"stockHistory": [
[
"2025-06-14 13:34:00",
49
]
]
},
"A18KSDUE00UP6J": {
"isFBA": false,
"lastUpdated": "2025-06-14 17:08:00",
"priceHistory": [
[
"2025-05-29 11:32:00",
42890,
0
]
],
"stockHistory": [
[
"2025-05-30 18:30:00",
3
]
]
}
},
"productReviewAverage": 4.7,
"productTotalReviews": 3129,
"rootCategory": {
"id": 412603031,
"name": "Videogiochi"
},
"stats": {
"amazonAsSellerPriceHistory": [
[
"2025-06-14",
44999
]
],
"buyBoxPriceHistory": [
[
"2025-06-13",
41700
]
],
"monthlySoldHistory": [
[
"2025-06",
1000
]
],
"productRatingCountHistory": [
[
"2025-06-14 15:28:00",
3129
]
],
"productRatingHistory": [
[
"2025-02-02 01:30:00",
4.7
]
],
"salesRankHistory": [
[
"2025-06-14 01:58:00",
15
]
]
}
}
}
Practical Use Cases
- Dynamic Pricing: Adjust prices based on sales rank changes.
- Restock Alerts: Trigger alerts when sales rank indicates increased demand.
- Promotional Campaigns: Evaluate campaign effectiveness by monitoring sales rank.
Advanced Tips
- Multi-ASIN Monitoring: Scale the tool to monitor multiple products simultaneously.
- Marketplace Expansion: Adapt the tool to different Amazon marketplaces using the appropriate
marketplaceId
. You can use the Get Amazon Marketplaces endpoint to list available marketplaces. - Integrate with Other APIs: Combine sales rank data with other SellerMagnet API endpoints like Amazon Product Offers or Amazon Product Lookup for deeper insights.
Legalities and Ethical Considerations
Always adhere to Amazon's terms of service and avoid overloading their servers with excessive requests. Implement reasonable delays between API calls to ensure compliance.
Conclusion
Building a Python tool for Amazon sales rank monitoring provides valuable insights for businesses and analysts. Using the SellerMagnet API simplifies data retrieval, allowing you to focus on analysis and decision-making. Start building your tool today and gain a competitive edge in the Amazon marketplace!