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

Close organizes contacts under Leads (companies/accounts). You want to auto-create Mavera Custom Personas for each ICP segment based on lead data — industry, company size, title patterns — keeping your persona library current with your actual pipeline.

Architecture

Code

import os, requests
from requests.auth import HTTPBasicAuth
from collections import defaultdict

CLOSE_KEY = os.environ["CLOSE_API_KEY"]
CLOSE_AUTH = HTTPBasicAuth(CLOSE_KEY, "")
MAVERA_KEY = os.environ["MAVERA_API_KEY"]

def close_get(path, params=None):
    r = requests.get(f"https://api.close.com/api/v1{path}", auth=CLOSE_AUTH, params=params or {})
    r.raise_for_status()
    return r.json()

# 1. Pull leads with contacts
leads = close_get("/lead/", {"_limit": 200, "_fields": "id,display_name,contacts,custom"}).get("data", [])

# 2. Segment by ICP
segments = defaultdict(list)
for lead in leads:
    custom = lead.get("custom", {})
    industry = custom.get("Industry", custom.get("industry", "General"))
    title = (lead.get("contacts", [{}])[0]).get("title", "Unknown") if lead.get("contacts") else "Unknown"

    role = "IC"
    tl = title.lower()
    if any(t in tl for t in ["cto", "ceo", "cfo", "vp", "chief", "head"]):
        role = "Executive"
    elif any(t in tl for t in ["director", "manager", "lead"]):
        role = "Manager"

    segments[f"{industry} | {role}"].append({
        "company": lead.get("display_name", "Unknown"), "title": title,
        "size": custom.get("Company Size", "Unknown"),
    })

# 3. Create personas in Mavera
created = 0
for seg_key, members in segments.items():
    if len(members) < 2:
        continue
    industry, role = seg_key.split(" | ")
    titles = list({m["title"] for m in members if m["title"] != "Unknown"})[:3]
    companies = [m["company"] for m in members][:3]

    resp = requests.post(
        "https://app.mavera.io/api/v1/personas",
        headers={"Authorization": f"Bearer {MAVERA_KEY}"},
        json={
            "name": f"{industry} {role}",
            "description": (
                f"A {role.lower()}-level buyer in {industry}. "
                f"Based on {len(members)} leads. Titles: {', '.join(titles)}. "
                f"Companies: {', '.join(companies)}. Size: {members[0]['size']}."
            ),
            "metadata": {"source": "close_crm", "segment": seg_key, "lead_count": len(members)},
        },
    )
    if resp.ok:
        print(f"Created: {resp.json().get('name')} ({len(members)} leads)")
        created += 1
    else:
        print(f"Failed for {seg_key}: {resp.status_code}")

print(f"\nTotal personas created: {created}")

Example Output

Created: SaaS Executive (12 leads)
Created: SaaS Manager (8 leads)
Created: Healthcare Executive (5 leads)
Created: FinTech IC (15 leads)
Created: Manufacturing Manager (4 leads)
Created: E-Commerce Executive (7 leads)

Total personas created: 6

Error Handling

ErrorCauseFix
Custom fields missingField keys vary by orgList via GET /custom_field/lead/ and map dynamically
Duplicate personasRunning sync repeatedlyCheck existing personas via GET /personas first; update instead
Empty contactsLead has no contactsSkip or use company-level data only
Sparse segmentsToo-granular custom fieldsSet minimum threshold (3+ leads per segment)