> ## 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.

# Org-Level Account Research

> Use Mave Agent to research Pipedrive organizations and write cited intelligence briefs back as pinned notes

## Scenario

Before a meeting, AEs need account intelligence — what the company does, recent news, competitive landscape. Pipedrive stores the org record but lacks depth. **Mave Agent researches each organization** and returns a cited intelligence brief.

## Architecture

```mermaid theme={"dark"}
flowchart LR
    A[Pipedrive Organizations] --> B["POST /api/v1/mave/chat (per org)"] --> C[Intelligence brief] --> D[Write Pipedrive note]
```

## Code

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

  DOMAIN = os.environ["PIPEDRIVE_DOMAIN"]
  PD_TOKEN = os.environ["PIPEDRIVE_API_TOKEN"]
  PD_BASE = f"https://{DOMAIN}.pipedrive.com"
  MAVERA_KEY = os.environ["MAVERA_API_KEY"]

  def pd_get(path, params=None):
      params = params or {}
      params["api_token"] = PD_TOKEN
      r = requests.get(f"{PD_BASE}{path}", params=params)
      r.raise_for_status()
      return r.json()

  # 1. Pull organizations
  orgs = pd_get("/api/v2/organizations", {"limit": 20, "sort_by": "update_time", "sort_direction": "desc"}).get("data", []) or []

  # 2. Research each with Mave Agent
  for org in orgs[:10]:
      name = org.get("name", "Unknown")
      addr = org.get("address", "")
      query = (
          f"Research '{name}'{f' based in {addr}' if addr else ''}. "
          f"Analyze: (1) business model, (2) recent news, (3) competitive landscape, "
          f"(4) strategic initiatives, (5) pain points for B2B SaaS. Cite sources."
      )
      mave = requests.post(
          "https://app.mavera.io/api/v1/mave/chat",
          headers={"Authorization": f"Bearer {MAVERA_KEY}"},
          json={"message": query},
      )
      mave.raise_for_status()
      result = mave.json()
      print(f"\n{'='*50}\nAccount: {name} | Sources: {len(result.get('sources', []))}")
      print(result.get("content", "")[:500])

      # 3. Write brief back as Pipedrive note
      requests.post(
          f"{PD_BASE}/api/v1/notes",
          params={"api_token": PD_TOKEN},
          json={
              "content": f"<b>Account Intelligence Brief</b><br><br>{result.get('content', '')[:3000]}",
              "org_id": org["id"],
              "pinned_to_organization_flag": 1,
          },
      )
  ```

  ```javascript JavaScript theme={"dark"}
  const DOMAIN = process.env.PIPEDRIVE_DOMAIN;
  const PD_TOKEN = process.env.PIPEDRIVE_API_TOKEN;
  const PD_BASE = `https://${DOMAIN}.pipedrive.com`;
  const MAVERA_KEY = process.env.MAVERA_API_KEY;

  async function pdGet(path, params = {}) {
    const url = new URL(`${PD_BASE}${path}`);
    url.searchParams.set("api_token", PD_TOKEN);
    for (const [k, v] of Object.entries(params)) url.searchParams.set(k, v);
    const res = await fetch(url);
    if (!res.ok) throw new Error(`Pipedrive ${res.status}`);
    return res.json();
  }

  // 1. Pull organizations
  const orgs = (await pdGet("/api/v2/organizations", {
    limit: 20, sort_by: "update_time", sort_direction: "desc"
  })).data || [];

  // 2. Research each with Mave
  for (const org of orgs.slice(0, 10)) {
    const query = `Research '${org.name}'${org.address ? ` based in ${org.address}` : ""}. ` +
      `Analyze: (1) business model, (2) recent news, (3) competitive landscape, ` +
      `(4) initiatives, (5) pain points for B2B SaaS. Cite sources.`;

    const maveRes = await fetch("https://app.mavera.io/api/v1/mave/chat", {
      method: "POST",
      headers: { Authorization: `Bearer ${MAVERA_KEY}`, "Content-Type": "application/json" },
      body: JSON.stringify({ message: query }),
    });
    const result = await maveRes.json();

    console.log(`\nAccount: ${org.name} | Sources: ${(result.sources || []).length}`);
    console.log((result.content || "").slice(0, 500));

    // 3. Write back as note
    const noteUrl = new URL(`${PD_BASE}/api/v1/notes`);
    noteUrl.searchParams.set("api_token", PD_TOKEN);
    await fetch(noteUrl, {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify({
        content: `<b>Account Intelligence Brief</b><br><br>${(result.content || "").slice(0, 3000)}`,
        org_id: org.id, pinned_to_organization_flag: 1,
      }),
    });
  }
  ```
</CodeGroup>

## Example Output

```text theme={"dark"}
Account: Acme Manufacturing Inc. | Sources: 4

Business Model: Acme produces industrial automation components for
automotive. Revenue ~$450M (2024 10-K).

Recent News: Announced $30M expansion into EV battery assembly tooling
(Reuters, Jan 2026). Hired new CTO from Siemens in Q4 2025.

Competitive Landscape: Fanuc, ABB Robotics, Rockwell Automation.
Acme differentiates on customization speed.

Pain Points: Legacy ERP integration, manual quality reporting,
scaling engineering for EV pivot. Receptive to workflow automation.
```

## Error Handling

| Error                        | Cause                            | Fix                                                |
| ---------------------------- | -------------------------------- | -------------------------------------------------- |
| Mave returns generic content | Org name too common              | Add industry, location, or website to disambiguate |
| `429` from Mave              | Too many concurrent requests     | Process orgs sequentially with 1-2s delay          |
| Note creation fails          | Org deleted or permissions issue | Verify org exists; check token write scope         |
