> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mavera.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Competitor TrustScore Comparison

> Compare TrustScores across competitor domains and generate competitive positioning analysis with Mave Agent

## Scenario

You know your own TrustScore — but how does it compare to competitors? Trustpilot lets you look up any business domain. You pull TrustScores for your competitors, compare distributions, and use Mave to analyze where you win and lose in the court of public opinion.

**Flow:** Trustpilot `GET /business-units/find?name={domain}` (per competitor) → Compare scores → Mavera `POST /mave/chat` → Competitive positioning

## Code

<CodeGroup>
  ```python Python theme={"dark"}
  import os, requests, time

  TP_KEY = os.environ["TRUSTPILOT_API_KEY"]
  MV = os.environ["MAVERA_API_KEY"]
  TP_BASE = "https://api.trustpilot.com/v1"
  MV_H = {"Authorization": f"Bearer {MV}", "Content-Type": "application/json"}

  DOMAINS = ["yourdomain.com", "competitor-a.com", "competitor-b.com", "competitor-c.com"]

  # 1. Pull TrustScores for all domains
  scores = []
  for domain in DOMAINS:
      r = requests.get(f"{TP_BASE}/business-units/find",
          params={"apikey": TP_KEY, "name": domain})
      if r.status_code != 200:
          print(f"Could not find {domain}")
          continue
      bu = r.json()
      score_data = bu.get("score", {})
      scores.append({
          "domain": domain,
          "name": bu.get("displayName", domain),
          "trust_score": score_data.get("trustScore", 0),
          "stars": score_data.get("stars", 0),
          "total_reviews": bu.get("numberOfReviews", {}).get("total", 0),
          "star_distribution": bu.get("score", {}).get("distribution", {}),
      })
      time.sleep(0.2)

  # 2. Pull sample reviews for each competitor
  for s in scores:
      if s["domain"] == DOMAINS[0]:
          continue
      bu_id = requests.get(f"{TP_BASE}/business-units/find",
          params={"apikey": TP_KEY, "name": s["domain"]}).json().get("id", "")
      if not bu_id:
          continue
      revs = requests.get(f"{TP_BASE}/business-units/{bu_id}/reviews",
          params={"apikey": TP_KEY, "perPage": 10, "orderBy": "createdat.desc"}).json()
      s["recent_reviews"] = [
          f"[{r.get('stars',0)}★] {r.get('text','')[:150]}"
          for r in revs.get("reviews", [])[:5]
      ]
      time.sleep(0.2)

  # 3. Mave competitive analysis
  score_block = "\n".join(
      f"- {s['name']} ({s['domain']}): TrustScore={s['trust_score']}, Stars={s['stars']}, Reviews={s['total_reviews']}"
      for s in scores
  )
  review_block = "\n\n".join(
      f"## {s['name']}\n" + "\n".join(s.get("recent_reviews", []))
      for s in scores if s.get("recent_reviews")
  )

  analysis = requests.post("https://app.mavera.io/api/v1/mave/chat",
      headers=MV_H,
      json={"message": f"""Compare TrustScores across these competitors:

  SCORES:
  {score_block}

  SAMPLE COMPETITOR REVIEWS:
  {review_block}

  Produce:
  1. Where do we win on trust? (higher score, better sentiment)
  2. Where do competitors beat us? (and why)
  3. Messaging opportunities based on trust differential
  4. Review volume strategy (if we have fewer reviews)
  5. Specific claims we can make (e.g., "Highest TrustScore in [category]")"""}).json()

  print("=== Competitive TrustScore Analysis ===")
  print(analysis.get("content", "")[:1500])
  ```

  ```javascript JavaScript theme={"dark"}
  const TP_KEY = process.env.TRUSTPILOT_API_KEY;
  const MV = process.env.MAVERA_API_KEY;
  const TP_BASE = "https://api.trustpilot.com/v1";
  const MV_H = { Authorization: `Bearer ${MV}`, "Content-Type": "application/json" };

  const DOMAINS = ["yourdomain.com", "competitor-a.com", "competitor-b.com"];

  // 1. Pull scores
  const scores = [];
  for (const domain of DOMAINS) {
    const res = await fetch(`${TP_BASE}/business-units/find?apikey=${TP_KEY}&name=${domain}`);
    if (!res.ok) { console.log(`Not found: ${domain}`); continue; }
    const bu = await res.json();
    scores.push({
      domain, name: bu.displayName || domain,
      trustScore: bu.score?.trustScore || 0, stars: bu.score?.stars || 0,
      totalReviews: bu.numberOfReviews?.total || 0,
    });
    await new Promise((r) => setTimeout(r, 200));
  }

  // 2. Analysis
  const scoreBlock = scores.map((s) =>
    `- ${s.name}: TrustScore=${s.trustScore}, Stars=${s.stars}, Reviews=${s.totalReviews}`
  ).join("\n");

  const analysis = await fetch("https://app.mavera.io/api/v1/mave/chat", {
    method: "POST", headers: MV_H,
    body: JSON.stringify({
      message: `Compare TrustScores:\n\n${scoreBlock}\n\nProduce: 1) Where we win 2) Where they beat us 3) Messaging opportunities 4) Volume strategy 5) Specific claims`,
    }),
  }).then((r) => r.json());

  console.log("=== Competitive TrustScore ===");
  console.log((analysis.content || "").slice(0, 1500));
  ```
</CodeGroup>

## Example Output

```text theme={"dark"}
=== Competitive TrustScore Analysis ===

| Company | TrustScore | Stars | Reviews |
|---------|-----------|-------|---------|
| You | 4.5 | 5 | 340 |
| CompetitorA | 4.1 | 4 | 1,200 |
| CompetitorB | 3.8 | 4 | 890 |
| CompetitorC | 4.7 | 5 | 45 |

## Where We Win
- Highest TrustScore among established competitors (4.5 vs 4.1/3.8)
- Claim: "Rated 4.5/5 on Trustpilot — highest in our category"

## Where They Beat Us
- CompetitorA has 3.5x our review volume — perceived as more established
- CompetitorC has higher score (4.7) but only 45 reviews — not statistically robust

## Messaging Strategy
1. Use "Highest-rated" badge (vs established competitors)
2. Drive review volume to 500+ to match CompetitorA's perceived scale
3. Highlight trust differential in ads: "4.5 vs industry avg 4.0"
```

## Error Handling

<AccordionGroup>
  <Accordion title="Domain not found">If a competitor isn't on Trustpilot, `GET /business-units/find` returns 404. Skip gracefully and note the gap.</Accordion>
  <Accordion title="Review access for competitors">You can read public reviews for any business via the API. No special permissions needed beyond the API key.</Accordion>
</AccordionGroup>
