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

# Sales Note → Brand Voice Extraction

> Query Notes from Closed Won opportunities, aggregate winning language, and feed it into Mavera's Brand Voice engine to create a 'Sales Winning Language' profile

## Scenario

Your best reps already know the winning language — it's buried in their deal notes. This job queries Notes attached to Closed Won opportunities, aggregates the value-prop phrasing that closes deals, and feeds it into Mavera's Brand Voice engine. The output is a "Sales Winning Language" voice profile that marketing can use to mirror phrases that actually convert.

## Architecture

```mermaid theme={"dark"}
flowchart LR
    A["Salesforce Notes (Closed Won)"] --> B[Aggregate text] --> C["POST /api/v1/brand-voices"] --> D[Voice Profile]
```

## Code

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

  SF   = os.environ["SALESFORCE_INSTANCE"]
  SF_T = os.environ["SALESFORCE_ACCESS_TOKEN"]
  MV_K = os.environ["MAVERA_API_KEY"]
  SF_H = {"Authorization": f"Bearer {SF_T}"}

  opps = requests.get(
      f"https://{SF}/services/data/v66.0/query", headers=SF_H,
      params={"q": "SELECT Id FROM Opportunity WHERE StageName = 'Closed Won' ORDER BY CloseDate DESC LIMIT 50"},
  ).json()["records"]

  opp_ids = "','".join(o["Id"] for o in opps)
  notes = requests.get(
      f"https://{SF}/services/data/v66.0/query", headers=SF_H,
      params={"q": f"SELECT Title, Body FROM Note WHERE ParentId IN ('{opp_ids}') ORDER BY CreatedDate DESC LIMIT 200"},
  ).json()["records"]

  combined = "\n\n---\n\n".join(
      f"[{n.get('Title', 'Untitled')}]\n{n.get('Body', '')}" for n in notes
  )[:50_000]

  bv = requests.post(
      "https://app.mavera.io/api/v1/brand-voices",
      headers={"Authorization": f"Bearer {MV_K}", "Content-Type": "application/json"},
      json={"name": "Sales Winning Language", "extracted_content": combined},
  ).json()

  print(f"Brand Voice ID: {bv['id']} — extracted from {len(notes)} notes across {len(opps)} won deals")
  ```

  ```javascript JavaScript theme={"dark"}
  const SF   = process.env.SALESFORCE_INSTANCE;
  const SF_T = process.env.SALESFORCE_ACCESS_TOKEN;
  const MV_K = process.env.MAVERA_API_KEY;

  async function sfQuery(soql) {
    const res = await fetch(
      `https://${SF}/services/data/v66.0/query?q=${encodeURIComponent(soql)}`,
      { headers: { Authorization: `Bearer ${SF_T}` } }
    );
    return (await res.json()).records;
  }

  const opps = await sfQuery(
    "SELECT Id FROM Opportunity WHERE StageName = 'Closed Won' ORDER BY CloseDate DESC LIMIT 50"
  );
  const oppIds = opps.map((o) => `'${o.Id}'`).join(",");
  const notes = await sfQuery(
    `SELECT Title, Body FROM Note WHERE ParentId IN (${oppIds}) ORDER BY CreatedDate DESC LIMIT 200`
  );

  let combined = notes
    .map((n) => `[${n.Title || "Untitled"}]\n${n.Body || ""}`)
    .join("\n\n---\n\n")
    .slice(0, 50_000);

  const bv = await fetch("https://app.mavera.io/api/v1/brand-voices", {
    method: "POST",
    headers: { Authorization: `Bearer ${MV_K}`, "Content-Type": "application/json" },
    body: JSON.stringify({ name: "Sales Winning Language", extracted_content: combined }),
  }).then((r) => r.json());

  console.log(`Brand Voice ID: ${bv.id} — from ${notes.length} notes across ${opps.length} deals`);
  ```
</CodeGroup>

## Example Output

```json theme={"dark"}
{
  "id": "bv_7mP3q",
  "name": "Sales Winning Language",
  "traits": {
    "tone": "Confident, consultative, outcome-focused",
    "vocabulary": ["speed-to-value", "de-risk", "proof-of-concept", "time-to-revenue", "operationalize"],
    "patterns": [
      "Leads with customer pain before product features",
      "Uses specific ROI numbers from similar customers",
      "Frames pricing as investment with payback period"
    ],
    "avoid": ["Generic 'best-in-class' claims", "Feature lists without business context"]
  }
}
```

<Tip>
  Re-run quarterly as your sales team evolves. Compare voice profiles over time to track how winning language shifts with market conditions.
</Tip>

***

<CardGroup cols={2}>
  <Card title="Salesforce Overview" icon="salesforce" href="/integrations/salesforce">
    Back to all 8 Salesforce jobs
  </Card>

  <Card title="Lead Scoring Validation" icon="chart-bar" href="/integrations/salesforce/lead-scoring-validation">
    Next: Validate lead scoring with synthetic focus groups
  </Card>
</CardGroup>
