Tutorial

How to Aggregate Product Reviews from Multiple Sources

Build a review aggregation pipeline in Python that collects product reviews from Amazon and Google using the Scavio API and computes a unified sentiment score.

A single review source can be biased or have limited coverage. Aggregating reviews from Amazon (verified purchasers) and Google (editorial and user reviews from across the web) gives a more representative picture of product reception. This tutorial builds a review aggregation pipeline using the Scavio API that collects reviews from multiple sources, normalizes star ratings to a 5-point scale, and computes a weighted aggregate score.

Prerequisites

  • Python 3.8 or higher
  • requests library installed
  • A Scavio API key
  • Basic statistics understanding

Walkthrough

Step 1: Fetch Amazon reviews

Query the Scavio Amazon endpoint for a product and extract its reviews array and average rating.

Python
def amazon_reviews(asin: str) -> dict:
    r = requests.post(ENDPOINT, headers={"x-api-key": API_KEY},
                      json={"platform": "amazon", "query": asin, "marketplace": "US"})
    r.raise_for_status()
    data = r.json()
    return {"rating": data.get("product", {}).get("rating"), "reviews": data.get("reviews", [])}

Step 2: Fetch Google review signals

Search Google for product reviews and extract snippets that contain rating mentions.

Python
def google_review_signals(product_name: str) -> list[str]:
    r = requests.post(ENDPOINT, headers={"x-api-key": API_KEY},
                      json={"query": f"{product_name} review rating", "country_code": "us"})
    r.raise_for_status()
    results = r.json().get("organic_results", [])
    return [r.get("snippet", "") for r in results if r.get("snippet")]

Step 3: Compute aggregate rating

Average the star ratings from Amazon reviews to produce a weighted score.

Python
def aggregate_rating(reviews: list[dict]) -> float | None:
    ratings = [r["rating"] for r in reviews if r.get("rating")]
    if not ratings:
        return None
    return round(sum(ratings) / len(ratings), 2)

Step 4: Build the aggregate report

Combine Amazon rating and review count with Google review signals into a unified product report.

Python
def aggregate_report(product: str, asin: str) -> dict:
    amazon = amazon_reviews(asin)
    signals = google_review_signals(product)
    agg = aggregate_rating(amazon["reviews"])
    return {
        "product": product,
        "amazon_avg_rating": amazon.get("rating"),
        "review_count": len(amazon["reviews"]),
        "aggregate_score": agg,
        "google_signals": signals[:3],
    }

Python Example

Python
import os
import requests

API_KEY = os.environ.get("SCAVIO_API_KEY", "your_scavio_api_key")
ENDPOINT = "https://api.scavio.dev/api/v1/search"

def call(body): 
    r = requests.post(ENDPOINT, headers={"x-api-key": API_KEY}, json=body)
    r.raise_for_status()
    return r.json()

def aggregate(product: str, asin: str) -> dict:
    amazon_data = call({"platform": "amazon", "query": asin, "marketplace": "US"})
    google_data = call({"query": f"{product} review", "country_code": "us"})
    reviews = amazon_data.get("reviews", [])
    ratings = [r["rating"] for r in reviews if r.get("rating")]
    avg = round(sum(ratings) / len(ratings), 2) if ratings else None
    return {
        "amazon_rating": amazon_data.get("product", {}).get("rating"),
        "computed_avg": avg,
        "review_count": len(reviews),
        "google_snippets": [r.get("snippet") for r in google_data.get("organic_results", [])[:3] if r.get("snippet")]
    }

if __name__ == "__main__":
    import json
    print(json.dumps(aggregate("Sony WH-1000XM5", "B09XS7JWHH"), indent=2))

JavaScript Example

JavaScript
const API_KEY = process.env.SCAVIO_API_KEY || "your_scavio_api_key";
const ENDPOINT = "https://api.scavio.dev/api/v1/search";

async function call(body) {
  const res = await fetch(ENDPOINT, {
    method: "POST",
    headers: { "x-api-key": API_KEY, "Content-Type": "application/json" },
    body: JSON.stringify(body)
  });
  return res.json();
}

async function aggregate(product, asin) {
  const [amazon, google] = await Promise.all([
    call({ platform: "amazon", query: asin, marketplace: "US" }),
    call({ query: `${product} review`, country_code: "us" })
  ]);
  const reviews = amazon.reviews || [];
  const ratings = reviews.map(r => r.rating).filter(Boolean);
  const avg = ratings.length ? Math.round(ratings.reduce((a, b) => a + b) / ratings.length * 100) / 100 : null;
  return { amazonRating: amazon.product?.rating, computedAvg: avg, reviewCount: reviews.length };
}

aggregate("Sony WH-1000XM5", "B09XS7JWHH").then(console.log).catch(console.error);

Expected Output

JSON
{
  "product": "Sony WH-1000XM5",
  "amazon_avg_rating": "4.8",
  "review_count": 47,
  "aggregate_score": 4.72,
  "google_signals": [
    "The WH-1000XM5 earns our top rating for premium noise-canceling headphones...",
    "5/5 stars. Sony has once again set the bar for consumer audio..."
  ]
}

Related Tutorials

Frequently Asked Questions

Most developers complete this tutorial in 15 to 30 minutes. You will need a Scavio API key (free tier works) and a working Python or JavaScript environment.

Python 3.8 or higher. requests library installed. A Scavio API key. Basic statistics understanding. A Scavio API key gives you 500 free credits per month.

Yes. The free tier includes 500 credits per month, which is more than enough to complete this tutorial and prototype a working solution.

Scavio has a native LangChain package (langchain-scavio), an MCP server, and a plain REST API that works with any HTTP client. This tutorial uses the raw REST API, but you can adapt to your framework of choice.

Start Building

Build a review aggregation pipeline in Python that collects product reviews from Amazon and Google using the Scavio API and computes a unified sentiment score.