# Leads

List the people your agents have met, and fetch one lead with their meetings.

A lead is a person who told one of your agents who they are, usually through the visitor form. Leads are unique by email within your workspace, so a person who comes back is the same lead. Both endpoints need a key with the `leads:read` scope.

A visitor who never gave an email (an agent with its visitor form off) still gets a lead, as an anonymous placeholder whose email ends in `@anonymous.invalid`. The list leaves those out unless you ask for them. Their meetings are always in [`GET /api/v1/meetings`](/docs/developers/api/meetings).

## The lead object

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | `string` | No | The lead's id. Meetings and webhooks refer to it as lead_id. |
| `tenant_id` | `string` | No | Your workspace's id. |
| `email` | `string` | No | The email the person gave. Unique within the workspace, compared without regard to case. |
| `name` | `string \| null` | No | Their name, when they gave one. |
| `company` | `string \| null` | No | Their company, when they gave one. |
| `role` | `string \| null` | No | Their role, when they gave one. |
| `first_seen_at` | `number` | No | When the lead was created, in Unix seconds. |
| `last_seen_at` | `number` | No | When the person was last seen, in Unix seconds. |
| `meeting_count` | `number` | No | How many meetings they have had. |
| `lead_score` | `'hot' \| 'warm' \| 'cold' \| null` | No | The score from their latest scored meeting. Only presentation and tour meetings are scored; null until one is. |
| `status` | `'new' \| 'engaged' \| 'qualified' \| 'disqualified'` | No | new until their first meeting, then engaged. Your team sets qualified or disqualified on the lead in the dashboard. |
| `custom_fields` | `object` | No | Answers to your own visitor-form questions, keyed by field. An empty object when there are none. |
| `language` | `string \| null` | No | A language code such as hi-IN when one was set for this person. null means the workspace default. |

## List leads

`GET /api/v1/leads` returns leads, most recently seen first.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `status` | `string` | No | Only leads with this status: new, engaged, qualified or disqualified. |
| `score` | `string` | No | Only leads with this lead_score: hot, warm or cold. |
| `q` | `string` | No | Search text. Matches the lead's name, email, company or any answer on your visitor form. |
| `include_anonymous` | `boolean` | No | true also lists anonymous visitors. Default: `false`. |
| `limit` | `number` | No | Leads per page, 1 to 500. Default: `100`. |
| `offset` | `number` | No | How many leads to skip. Default: `0`. |

**cURL**

```bash title="List engaged leads"
curl 'https://api.insurgeai.com/api/v1/leads?status=engaged&limit=50' \
  -H "Authorization: Bearer $INSURGE_API_KEY"
```

**Node.js**

```js title="List every engaged lead"
const headers = { Authorization: `Bearer ${process.env.INSURGE_API_KEY}` };
const all = [];
for (let offset = 0; ; offset += 50) {
  const url = `https://api.insurgeai.com/api/v1/leads?status=engaged&limit=50&offset=${offset}`;
  const res = await fetch(url, { headers });
  if (!res.ok) throw new Error(`${res.status} ${await res.text()}`);
  const { leads } = await res.json();
  all.push(...leads);
  if (leads.length < 50) break;
}
```

**Python**

```python title="List every engaged lead"
import os
import requests

H = {"Authorization": f"Bearer {os.environ['INSURGE_API_KEY']}"}
leads, offset = [], 0
while True:
    r = requests.get(
        "https://api.insurgeai.com/api/v1/leads",
        params={"status": "engaged", "limit": 50, "offset": offset},
        headers=H,
        timeout=30,
    )
    r.raise_for_status()
    page = r.json()["leads"]
    leads += page
    if len(page) < 50:
        break
    offset += 50
```

```json title="200 OK"
{
  "leads": [
    {
      "id": "c41e7b2a9d3f4e6a8b1c5d7f9e2a4b6c",
      "tenant_id": "acme",
      "email": "arjun@example.org",
      "name": "Arjun Rao",
      "company": "Northwind Traders",
      "role": null,
      "first_seen_at": 1796122800.4,
      "last_seen_at": 1796122800.5,
      "meeting_count": 1,
      "lead_score": null,
      "status": "engaged",
      "custom_fields": {},
      "language": null
    },
    {
      "id": "3f6c1a9e2b7d4e5f8a9b0c1d2e3f4a5b",
      "tenant_id": "acme",
      "email": "priya@example.com",
      "name": "Priya Sharma",
      "company": "Example Labs",
      "role": "Head of Operations",
      "first_seen_at": 1796119198.3,
      "last_seen_at": 1796119200.6,
      "meeting_count": 1,
      "lead_score": "hot",
      "status": "engaged",
      "custom_fields": {
        "team_size": "40"
      },
      "language": null
    }
  ],
  "count": 2
}
```

`count` is the number of leads in this page. Keep asking with a larger `offset` until a page has fewer than `limit` leads.

| Status | When |
|---|---|
| `401` | The key is missing, wrong, expired or revoked. |
| `403` | The key doesn't have `leads:read`. |
| `422` | `limit` or `offset` is out of range. |

## Get a lead

`GET /api/v1/leads/{lead_id}` returns one lead and their meetings, newest first (up to 100). Each meeting has the shape of an item in [List meetings](/docs/developers/api/meetings#list-meetings).

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `lead_id` | `string` | Yes | The lead's id, from a meeting, a webhook or the list. |

**cURL**

```bash title="Get a lead"
curl 'https://api.insurgeai.com/api/v1/leads/your_lead_id' \
  -H "Authorization: Bearer $INSURGE_API_KEY"
```

**Node.js**

```js title="Get a lead"
async function getLead(leadId) {
  const res = await fetch(`https://api.insurgeai.com/api/v1/leads/${leadId}`, {
    headers: { Authorization: `Bearer ${process.env.INSURGE_API_KEY}` },
  });
  if (res.status === 404) return null; // not a lead of this workspace
  if (!res.ok) throw new Error(`${res.status} ${await res.text()}`);
  return res.json(); // { lead, meetings }
}
```

**Python**

```python title="Get a lead"
import os
import requests

def get_lead(lead_id: str):
    r = requests.get(
        f"https://api.insurgeai.com/api/v1/leads/{lead_id}",
        headers={"Authorization": f"Bearer {os.environ['INSURGE_API_KEY']}"},
        timeout=30,
    )
    if r.status_code == 404:
        return None  # not a lead of this workspace
    r.raise_for_status()
    return r.json()  # {"lead": ..., "meetings": [...]}
```

```json title="200 OK"
{
  "lead": {
    "id": "3f6c1a9e2b7d4e5f8a9b0c1d2e3f4a5b",
    "tenant_id": "acme",
    "email": "priya@example.com",
    "name": "Priya Sharma",
    "company": "Example Labs",
    "role": "Head of Operations",
    "first_seen_at": 1796119198.3,
    "last_seen_at": 1796119200.6,
    "meeting_count": 1,
    "lead_score": "hot",
    "status": "engaged",
    "custom_fields": {
      "team_size": "40"
    },
    "language": null
  },
  "meetings": [
    {
      "id": "9b2e7c4d1a3f4b6e8d0c2a4e6f8b1d3c",
      "lead_id": "3f6c1a9e2b7d4e5f8a9b0c1d2e3f4a5b",
      "client_id": "b0c6f1e2-5a7d-4c39-9e8b-2f4d6a1c3e5b",
      "started_at": 1796119200.4,
      "ended_at": 1796119612.4,
      "duration_s": 412.0,
      "plan_slug": "agent:product-tour",
      "final_phase": null,
      "status": "completed",
      "objectives_total": 4,
      "objectives_completed": 4,
      "lang": "en-IN",
      "channel": null,
      "agent_id": "product-tour",
      "platform": "desktop_web",
      "source": null,
      "embed_host": "www.example.com",
      "progress": {
        "sections_done": [
          "Workspace",
          "Pipelines",
          "Alerts",
          "Reports"
        ],
        "sections_total": 4,
        "next_section": null
      },
      "resumed_from_meeting_id": null,
      "lead_name": "Priya Sharma",
      "lead_email": "priya@example.com",
      "lead_company": "Example Labs",
      "lead_role": "Head of Operations",
      "lead_score": "hot",
      "lead_status": "engaged",
      "requested_follow_up": 1
    }
  ]
}
```

| Status | When |
|---|---|
| `403` | The key doesn't have `leads:read`. |
| `404` | `Lead not found: <id>`. There is no lead with this id in the key's workspace. |
