Python script for Amazon product variation analysis using SellerMagnetAPI

Building a Python Script for Amazon Product Variation Analysis with SellerMagnetAPI

By Michael Chen | July 19, 2025

Unlock Amazon Product Insights: Build a Python Script for Variation Analysis with SellerMagnetAPI

In the competitive world of e-commerce, Amazon businesses and market analysts require deep insights into product performance. Variation analysis, understanding how different product attributes (like size, color, or model) impact sales and customer reviews, is crucial for optimizing inventory management, competitive analysis, and market research. This blog post guides you through building a Python script to analyze Amazon product variations using the power of SellerMagnet’s Amazon data API.

Why Analyze Amazon Product Variations?

  • Competitive Advantage: Identify top-performing variations to understand what resonates with customers.
  • Inventory Optimization: Predict demand for specific variations, minimizing stockouts and overstocking.
  • Pricing Strategy: Tailor pricing based on variation popularity and competitor pricing.
  • Market Research: Gain insights into emerging trends and customer preferences.

Leveraging SellerMagnetAPI for Amazon Data

SellerMagnetAPI provides enterprise-grade access to real-time Amazon data, enabling businesses to automate data collection and analysis. This post focuses on using the API to extract and analyze product variation data programmatically.

Setting Up Your Python Environment

First, ensure you have Python installed (preferably version 3.6 or higher). You'll also need the `requests` library to make HTTP requests to the SellerMagnetAPI.

pip install requests

Fetching Product Information with the Amazon Product Lookup API

The Amazon Product Lookup endpoint is key to retrieving detailed product information, including variations. Here's how to use it:

Endpoint: `/amazon-product-lookup`

This endpoint requires the ASIN (Amazon Standard Identification Number) and the Marketplace ID.

Parameters:

  • `asin` (required): The product's ASIN (e.g., "B08N5WRWNW").
  • `marketplaceId` (required): The Amazon Marketplace ID (e.g., "A1PA6795UKMFR9" for Germany). See SellerMagnetAPI Get Amazon Marketplaces endpoint for a list of available Marketplace IDs.
  • `api_key` (required): Your SellerMagnetAPI key.

Python Code Example:


import requests

api_key = "YOUR_API_KEY"  # Replace with your actual API key
asin = "B0CL61F39H"  # Example ASIN for Playstation 5
marketplace_id = "ATVPDKIKX0DER"  # Example Marketplace ID for Amazon US

url = f"https://sellermagnet-api.com/amazon-product-lookup?asin={asin}&marketplaceId={marketplace_id}&api_key={api_key}"

try:
    response = requests.get(url)
    response.raise_for_status()  # Raise HTTPError for bad responses (4XX, 5XX)
    data = response.json()

    if data["success"]:
        product_info = data["data"]["productInfo"]
        print(product_info)
    else:
        print(f"Error: {data}")

except requests.exceptions.RequestException as e:
    print(f"Request failed: {e}")
except KeyError as e:
    print(f"KeyError: Missing key in response - {e}")
except Exception as e:
    print(f"An unexpected error occurred: {e}")

Response Example:


{
  "data": {
    "productInfo": {
      "additionalDetails": {
        "ASIN": "B0CL61F39H",
        "Batteries": "1 Lithium Ion batteries required. (included)",
        "Best Sellers Rank": "Nr. 31 in Video Games Nr. 1 in PlayStation 5 Consoles",
        "Customer Rating": "4.7 out of 5 stars",
        "Date First Available": "December 10, 2023",
        "Item Weight": "10.6 pounds",
        "Item model number": "CFI-2015",
        "Manufacturer": "Sony",
        "Number of Reviews": "7,092 ratings",
        "Product Dimensions": "14 x 17 x 7 inches; 10.6 Pounds",
        "Release date": "December 10, 2023",
        "Type of item": "Video Game"
      },
      "asin": "B0CL61F39H",
      "bestsellerRanks": {
        "main_category": {
          "name": "Video Games",
          "rank": 31
        },
        "subcategory": {
          "name": "PlayStation",
          "rank": 1
        }
      },
      "bulletPoints": [
        "Model Number CFI-2000",
        "Includes DualSense Wireless Controller, 1TB SSD, Disc Drive, 2 Horizontal Stand Feet, HDMI Cable, AC power cord, USB cable, printed materials, ASTRO\u2019s PLAYROOM (Pre-installed game)",
        "Vertical Stand sold separately"
      ],
      "buyBoxInfo": {
        "currencyCode": "USD",
        "currencyName": "United States Dollar",
        "currencySymbol": "$",
        "price": 444.99,
        "sellerId": "A3853PJW50SJG8"
      },
      "categories": {
        "bestsellerCategory": [
          {
            "id": "20972781011",
            "index": 1,
            "name": "PlayStation 5",
            "url": "https://www.amazon.com/b/ref=dp_bc_2?ie=UTF8&node=20972781011"
          },
          {
            "id": "20972796011",
            "index": 2,
            "name": "Consoles",
            "url": "https://www.amazon.com/b/ref=dp_bc_3?ie=UTF8&node=20972796011"
          }
        ],
        "rootCategory": {
          "id": "468642",
          "name": "Video Games",
          "url": "https://www.amazon.com/computer-video-games-hardware-accessories/b/ref=dp_bc_1?ie=UTF8&node=468642"
        }
      },
      "description": [
        "Model Number CFI-2000",
        "Includes DualSense Wireless Controller, 1TB SSD, Disc Drive, 2 Horizontal Stand Feet, HDMI Cable, AC power cord, USB cable, printed materials, ASTRO\u2019s PLAYROOM (Pre-installed game)",
        "Vertical Stand sold separately",
        "The PS5 console unleashes new gaming possibilities that you never anticipated. Experience lightning fast loading with an ultra-high speed SSD, deeper immersion with support for haptic feedback, adaptive triggers, and 3D Audio*, and an all-new generation of incredible PlayStation games. Lightning Speed - Harness the power of a custom CPU, GPU, and SSD with Integrated I/O that rewrite the rules of what a PlayStation console can do. Stunning Games - Marvel at incredible graphics and experience new PS5 features. Play a back catalog of supported PS4 games. Breathtaking Immersion - Discover a deeper gaming experience with support for haptic feedback, adaptive triggers, and 3D Audio technology. Vertical stand sold separately. *3D audio via built-in TV speakers or analog/USB stereo headphones. Set up and latest system software update required."
      ],
      "details": {
        "ASIN": "B0CL61F39H",
        "Batteries": "1 Lithium Ion batteries required. (included)",
        "Date First Available": "December 10, 2023",
        "Item Weight": "10.6 pounds",
        "Item model number": "CFI-2015",
        "Manufacturer": "Sony",
        "Platform": "PlayStation 5",
        "Product Dimensions": "14 x 17 x 7 inches; 10.6 Pounds",
        "Release date": "December 10, 2023",
        "Type of item": "Video Game"
      },
      "hasAPlusContent": true,
      "images": [
        "https://m.media-amazon.com/images/I/41ECK5cY-2L._SL1000_.jpg",
        "https://m.media-amazon.com/images/I/41srF-iY93L._SL1000_.jpg",
        "https://m.media-amazon.com/images/I/41tVr19I3zL._SL1000_.jpg",
        "https://m.media-amazon.com/images/I/41HMaO9jO3L._SL1000_.jpg",
        "https://m.media-amazon.com/images/I/61e8hPmeoYL._SL1000_.jpg",
        "https://m.media-amazon.com/images/I/61Gj1Kc5R5L._SL1000_.jpg",
        "https://m.media-amazon.com/images/I/61r6PutKGwL._SL1000_.jpg",
        "https://m.media-amazon.com/images/I/717Id5h1fhL._SL1000_.jpg"
      ],
      "link": "https://www.amazon.com/dp/B0CL61F39H",
      "listedSinceDate": "2023-12-10",
      "mainImage": "https://m.media-amazon.com/images/I/31kTNmpm6vL.jpg",
      "marketplaceId": "ATVPDKIKX0DER",
      "reviews": {
        "averageRating": 4.7,
        "reviewSummary": "4.7 out of 5 stars",
        "totalReviews": 7092
      },
      "title": "PlayStation\u00ae5 console (slim)",
      "variations": [
        {
          "asin": "B0F6968Y5G",
          "attributes": {
            "Pattern Name": "PS5 w/ Black Ops Bundle",
            "Style": "PlayStation\u00ae5 Digital Edition (slim)"
          }
        },
        {
          "asin": "B0CL5KNB9M",
          "attributes": {
            "Pattern Name": "PS5 Only",
            "Style": "PlayStation\u00ae5 Digital Edition (slim)"
          }
        },
        {
          "asin": "B0CL61F39H",
          "attributes": {
            "Pattern Name": "PS5 Only",
            "Style": "PlayStation\u00ae5 console (slim)"
          }
        },
        {
          "asin": "B0F691TJTP",
          "attributes": {
            "Pattern Name": "PS5 w/ Black Ops Bundle",
            "Style": "PlayStation\u00ae5 console (slim)"
          }
        },
        {
          "asin": "B0FD54CGQ8",
          "attributes": {
            "Pattern Name": "PS5 w/ $100 PlayStation Store GC",
            "Style": "PlayStation\u00ae5 Digital Edition (slim)"
          }
        },
        {
          "asin": "B0FD4WGVH5",
          "attributes": {
            "Pattern Name": "PS5 w/ $100 PlayStation Store GC",
            "Style": "PlayStation\u00ae5 console (slim)"
          }
        }
      ],
      "videos": [
        "https://m.media-amazon.com/S/vse-vms-transcoding-artifact-us-east-1-prod/8af0ddf1-55f5-4e71-9463-39602c3edbae/default.jobtemplate.hls.m3u8",
        "https://m.media-amazon.com/S/vse-vms-transcoding-artifact-us-east-1-prod/50938d5c-2a9b-427a-b766-21b7cd63502e/default.jobtemplate.hls.m3u8"
      ]
    }
  },
  "success": true
}

Analyzing Variation Data

Once you have the product information, extract the `variations` list. Each item in the list represents a variation, containing its ASIN and attributes. You can further analyze this data using other SellerMagnetAPI endpoints.

Fetching Statistics for Each Variation

Use the Amazon Product Statistics endpoint to get sales rank, review counts, and other metrics for each variation's ASIN.


def get_variation_stats(asin, marketplace_id, api_key):
    url = f"https://sellermagnet-api.com/amazon-product-statistics?asin={asin}&marketplaceId={marketplace_id}&api_key={api_key}"
    try:
        response = requests.get(url)
        response.raise_for_status()
        data = response.json()
        if data["success"]:
            return data["data"]
        else:
            print(f"Error fetching statistics for ASIN {asin}: {data}")
            return None
    except requests.exceptions.RequestException as e:
        print(f"Request failed for ASIN {asin}: {e}")
        return None

# After fetching the product information
if data["success"]:
    product_info = data["data"]["productInfo"]
    for variation in product_info["variations"]:
        variation_asin = variation["asin"]
        stats = get_variation_stats(variation_asin, marketplace_id, api_key)
        if stats:
            print(f"Statistics for variation ASIN {variation_asin}: {stats}")

Analyzing Seller Reviews

Retrieve seller reviews associated with each variation using the Amazon Seller Review endpoint. First, extract the seller ID from the Amazon Product Offers API for each variation and then use that ID.


def get_seller_id_and_review(asin, marketplace_id, api_key):
    offers_url = f"https://sellermagnet-api.com/amazon-product-offers?asin={asin}&marketplaceId={marketplace_id}&api_key={api_key}"
    try:
        offers_response = requests.get(offers_url)
        offers_response.raise_for_status()
        offers_data = offers_response.json()

        if offers_data["success"]:
            seller_id = offers_data["data"]["buyBox"]["sellerId"]
            seller_review_url = f"https://sellermagnet-api.com/amazon-seller-review?sellerId={seller_id}&marketplaceId={marketplace_id}&api_key={api_key}"

            review_response = requests.get(seller_review_url)
            review_response.raise_for_status()
            review_data = review_response.json()

            if review_data["success"]:
                return seller_id, review_data["data"]
            else:
                print(f"Error fetching seller review for ASIN {asin}: {review_data}")
                return seller_id, None
        else:
            print(f"Error fetching offers for ASIN {asin}: {offers_data}")
            return None, None
    except requests.exceptions.RequestException as e:
        print(f"Request failed for ASIN {asin}: {e}")
        return None, None

# After fetching the product information
if data["success"]:
    product_info = data["data"]["productInfo"]
    for variation in product_info["variations"]:
        variation_asin = variation["asin"]
        seller_id, seller_review = get_seller_id_and_review(variation_asin, marketplace_id, api_key)
        if seller_review:
            print(f"Seller reviews for variation ASIN {variation_asin} and seller ID {seller_id}: {seller_review}")

Practical Use Cases

  • Identify Underperforming Variations: If a variation has low sales rank and poor reviews, consider discontinuing it or adjusting its pricing.
  • Optimize Product Listings: Use insights from high-performing variations to improve the descriptions, images, and keywords of other variations.
  • Personalized Marketing: Target marketing campaigns towards specific customer segments based on their preferred variation attributes.

Enhancements and Further Exploration

  • Automate Data Collection: Utilize SellerMagnetAPI DataPipeline to schedule regular data updates.
  • Visualize Data: Use libraries like Matplotlib or Seaborn to create charts and graphs for easy interpretation.
  • Combine with Other Data Sources: Integrate data from other sources, such as social media or customer surveys, for a more comprehensive analysis.

Conclusion

By leveraging SellerMagnetAPI and Python, you can build powerful tools for analyzing Amazon product variations, enabling data-driven decisions that improve your business performance. Sign up for a free trial today and start unlocking the potential of Amazon data! Check our Documentation and Code Examples pages to get started.

Back to Blog