Skip to main content

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.

Scenario

Your Mailchimp account has months of campaign data — open rates, click rates, bounce rates, and the actual content that drove those numbers. You pull performance reports for your top-performing campaigns, extract the subject lines, preview text, and content patterns, then feed them into Mavera’s Brand Voice to capture what works. The result is a brand voice trained on your actual winning email content.

Architecture

Code

import os, requests, time

MC_KEY = os.environ["MAILCHIMP_API_KEY"]
MC_DC = os.environ["MAILCHIMP_DC"]
MV = os.environ["MAVERA_API_KEY"]
MB = "https://app.mavera.io/api/v1"
MH = {"Authorization": f"Bearer {MV}", "Content-Type": "application/json"}
MC_BASE = f"https://{MC_DC}.api.mailchimp.com/3.0"
mc_auth = ("anystring", MC_KEY)

r = requests.get(
    f"{MC_BASE}/campaigns",
    auth=mc_auth,
    params={
        "count": 50,
        "sort_field": "send_time",
        "sort_dir": "DESC",
        "status": "sent",
        "fields": "campaigns.id,campaigns.settings,campaigns.report_summary,campaigns.send_time",
    },
)
r.raise_for_status()
campaigns = r.json().get("campaigns", [])

scored = []
for c in campaigns:
    report = c.get("report_summary", {})
    opens = report.get("open_rate", 0)
    clicks = report.get("click_rate", 0)
    settings = c.get("settings", {})

    if opens > 0:
        scored.append({
            "id": c["id"],
            "subject": settings.get("subject_line", ""),
            "preview": settings.get("preview_text", ""),
            "from_name": settings.get("from_name", ""),
            "open_rate": opens,
            "click_rate": clicks,
            "send_time": c.get("send_time", ""),
        })

scored.sort(key=lambda x: x["open_rate"] * 0.6 + x["click_rate"] * 0.4, reverse=True)
top = scored[:15]
bottom = scored[-5:]

winning_content = []
for camp in top[:10]:
    report_r = requests.get(f"{MC_BASE}/reports/{camp['id']}", auth=mc_auth)
    if report_r.status_code == 200:
        detail = report_r.json()
        camp["unique_opens"] = detail.get("opens", {}).get("unique_opens", 0)
        camp["unique_clicks"] = detail.get("clicks", {}).get("unique_clicks", 0)
        camp["bounces"] = detail.get("bounces", {}).get("hard_bounces", 0)

    winning_content.append(
        f"Subject: {camp['subject']}\n"
        f"Preview: {camp['preview']}\n"
        f"From: {camp['from_name']}\n"
        f"Open: {camp['open_rate']:.0%} | Click: {camp['click_rate']:.0%}"
    )
    time.sleep(0.3)

samples_text = "\n\n---\n\n".join(winning_content)

voice = requests.post(f"{MB}/brand-voices", headers=MH, json={
    "name": "Mailchimp: Winning Email Voice",
    "description": (
        "Brand voice extracted from top-performing Mailchimp campaigns. "
        f"Based on {len(top)} campaigns with avg open rate "
        f"{sum(c['open_rate'] for c in top)/len(top):.0%} and avg click rate "
        f"{sum(c['click_rate'] for c in top)/len(top):.0%}."
    ),
    "samples": [c["subject"] + " — " + c["preview"] for c in top],
    "guidelines": (
        f"Top-performing subject lines average {sum(len(c['subject']) for c in top)//len(top)} characters. "
        f"Common patterns: "
        + ("personalization, " if any("{" in c["subject"] or "you" in c["subject"].lower() for c in top) else "")
        + ("urgency, " if any(w in " ".join(c["subject"].lower() for c in top) for w in ["today", "now", "last", "ending"]) else "")
        + ("questions, " if any("?" in c["subject"] for c in top) else "")
        + ("numbers/lists." if any(c["subject"][0].isdigit() for c in top) else "clarity.")
    ),
}).json()

print(f"Brand Voice created: {voice.get('id')}")
print(f"Based on {len(top)} top campaigns")
print(f"Avg open: {sum(c['open_rate'] for c in top)/len(top):.0%}")
print(f"Avg click: {sum(c['click_rate'] for c in top)/len(top):.0%}")
print(f"\nTop 3 subjects:")
for c in top[:3]:
    print(f"  {c['open_rate']:.0%} open | {c['subject']}")

Example Output

Brand Voice created: bv_mc_email_1
Based on 15 top campaigns
Avg open: 34%
Avg click: 5.2%

Top 3 subjects:
  48% open | Your competitor just launched this — here's your move
  44% open | 3 things your dashboard isn't telling you
  41% open | We rebuilt the feature you asked for

Error Handling

The report_summary field is included in campaign list responses only for sent campaigns. Draft and scheduled campaigns won’t have it. Filter by status=sent.
Each API call occupies a connection slot. The detailed report fetch for 10 campaigns uses 10 sequential calls with 300ms delays. Avoid parallel fetches exceeding 10.
Mavera’s Brand Voice endpoint may have limits on the number of samples. If 15 samples exceeds the limit, reduce to 10 — quality of top performers matters more than quantity.

What’s Next

Mailchimp Integration

Back to Mailchimp integration overview

Subscriber Persona Creation

Build personas from audience segments

A/B Focus Group

Understand why A/B variants win

Brand Voice API

Full reference for POST /api/v1/brand-voices