> ## Documentation Index
> Fetch the complete documentation index at: https://docs.newlead.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Quickstart

> Create a lead and send it your first WhatsApp template.

By the end of this guide you have a lead in NewLead and an open WhatsApp conversation that your agent continues when the lead replies.

## Before you start

You need:

* A NewLead subaccount.
* An active text agent with WhatsApp connected.
* A WhatsApp template approved for that agent.

**1. Create an API key**

In the dashboard, open the subaccount and go to **Settings › API**. Create a key and copy it: it is shown only once.

```bash theme={null}
export NEWLEAD_API_KEY="NL-..."
```

**2. Find your text agent**

```bash theme={null}
curl https://rest.newlead.ai/v1/text_agents \
  -H "Authorization: Bearer $NEWLEAD_API_KEY"
```

```json theme={null}
{
  "object": "list",
  "data": [
    {
      "object": "text_agent",
      "id": "00000000-0000-4000-8000-000000000004",
      "name": "Maria",
      "status": "active",
      "channels": ["whatsapp"],
      "timezone": "Europe/Madrid",
      "created_at": "2026-11-13T09:00:00.000Z"
    }
  ],
  "has_more": false,
  "next_cursor": null
}
```

Copy the `id` of an agent whose `status` is `active`. Use it as `<TEXT_AGENT_ID>` in the next steps.

**3. Choose a template**

```bash theme={null}
curl https://rest.newlead.ai/v1/text_agents/<TEXT_AGENT_ID>/templates \
  -H "Authorization: Bearer $NEWLEAD_API_KEY"
```

```json theme={null}
{
  "object": "list",
  "data": [
    {
      "object": "template",
      "id": "00000000-0000-4000-8000-00000000000b",
      "name": "welcome",
      "language": "en",
      "category": "utility",
      "status": "approved",
      "body_text": "Hi, thanks for your interest. How can we help?",
      "components": [
        {
          "type": "body",
          "format": null,
          "text": "Hi, thanks for your interest. How can we help?",
          "buttons": null
        }
      ],
      "variables": null,
      "rejection_reason": null,
      "created_at": "2026-11-13T09:00:00.000Z"
    }
  ],
  "has_more": false,
  "next_cursor": null
}
```

Note the `name` and `language` of a template whose `status` is `approved`. A WhatsApp conversation can only start with an approved template.

**4. Create a lead**

The `Idempotency-Key` header makes the request safe to repeat: a retry with the same key does not create anything twice.

```bash curl theme={null}
curl -X POST https://rest.newlead.ai/v1/leads \
  -H "Authorization: Bearer $NEWLEAD_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: create-lead-ana-ferrer-001" \
  -d '{
    "text_agent_id": "<TEXT_AGENT_ID>",
    "phone": "+34600111222",
    "name": "Ana Ferrer"
  }'
```

```javascript Node.js theme={null}
const response = await fetch("https://rest.newlead.ai/v1/leads", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.NEWLEAD_API_KEY}`,
    "Content-Type": "application/json",
    "Idempotency-Key": "create-lead-ana-ferrer-001",
  },
  body: JSON.stringify({
    text_agent_id: "<TEXT_AGENT_ID>",
    phone: "+34600111222",
    name: "Ana Ferrer",
  }),
});

console.log(response.status, await response.json());
```

```python Python theme={null}
import os

import requests

response = requests.post(
    "https://rest.newlead.ai/v1/leads",
    headers={
        "Authorization": f"Bearer {os.environ['NEWLEAD_API_KEY']}",
        "Idempotency-Key": "create-lead-ana-ferrer-001",
    },
    json={
        "text_agent_id": "<TEXT_AGENT_ID>",
        "phone": "+34600111222",
        "name": "Ana Ferrer",
    },
    timeout=30,
)

print(response.status_code, response.json())
```

> [!WARNING]
>
> Include the country code in `phone`. A number without it returns `400 parameter_invalid`.

The API returns `201` with the new lead. If the agent already has a WhatsApp or Lead Ads lead with that phone, it updates that lead and returns `200`.

```json theme={null}
{
  "object": "lead",
  "id": "00000000-0000-4000-8000-000000000003",
  "text_agent_id": "00000000-0000-4000-8000-000000000004",
  "voice_agent_id": null,
  "contact_id": "00000000-0000-4000-8000-000000000006",
  "name": "Ana Ferrer",
  "phone": "+34600111222",
  "email": null,
  "username": null,
  "channel": "whatsapp",
  "status": "active",
  "source": { "type": null, "lead_ad": null },
  "summary": null,
  "variables": {},
  "qualification": { "status": "not_started", "completed_at": null, "answers": [] },
  "do_not_contact": false,
  "has_replied": false,
  "ai_paused": false,
  "ai_paused_until": null,
  "messaging_window_expires_at": null,
  "created_at": "2026-11-13T09:00:00.000Z",
  "last_activity_at": "2026-11-13T09:00:00.000Z"
}
```

**5. Send the template**

```bash curl theme={null}
curl -X POST https://rest.newlead.ai/v1/messages \
  -H "Authorization: Bearer $NEWLEAD_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: welcome-ana-ferrer-001" \
  -d '{
    "type": "template",
    "text_agent_id": "<TEXT_AGENT_ID>",
    "to": "+34600111222",
    "template": { "name": "welcome", "language": "en" }
  }'
```

```javascript Node.js theme={null}
const response = await fetch("https://rest.newlead.ai/v1/messages", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.NEWLEAD_API_KEY}`,
    "Content-Type": "application/json",
    "Idempotency-Key": "welcome-ana-ferrer-001",
  },
  body: JSON.stringify({
    type: "template",
    text_agent_id: "<TEXT_AGENT_ID>",
    to: "+34600111222",
    template: { name: "welcome", language: "en" },
  }),
});

console.log(response.status, await response.json());
```

```python Python theme={null}
import os

import requests

response = requests.post(
    "https://rest.newlead.ai/v1/messages",
    headers={
        "Authorization": f"Bearer {os.environ['NEWLEAD_API_KEY']}",
        "Idempotency-Key": "welcome-ana-ferrer-001",
    },
    json={
        "type": "template",
        "text_agent_id": "<TEXT_AGENT_ID>",
        "to": "+34600111222",
        "template": {"name": "welcome", "language": "en"},
    },
    timeout=30,
)

print(response.status_code, response.json())
```

The API returns `201` with the message. When the lead replies, your agent continues the conversation.

```json theme={null}
{
  "object": "message",
  "id": "00000000-0000-4000-8000-00000000000a",
  "lead_id": "00000000-0000-4000-8000-000000000003",
  "direction": "outbound",
  "sender": "agent",
  "origin": "api",
  "type": "template",
  "text": "Hi, thanks for your interest. How can we help?",
  "template": { "name": "welcome", "language": "en" },
  "attachments": [],
  "reply_to_message_id": null,
  "status": "accepted",
  "error": null,
  "created_at": "2026-11-13T09:00:05.000Z",
  "sent_at": null,
  "delivered_at": null,
  "read_at": null,
  "failed_at": null,
  "lead_created": false,
  "warnings": []
}
```

> [accordion] Send values for template variables
>
> If the template has variables, send their values in `template.components`. This example fills `{{1}}` in the body:
>
> ```json theme={null}
> {
>   "type": "template",
>   "text_agent_id": "<TEXT_AGENT_ID>",
>   "to": "+34600111222",
>   "template": {
>     "name": "welcome",
>     "language": "en",
>     "components": [
>       { "type": "body", "parameters": [{ "type": "text", "text": "Ana" }] }
>     ]
>   }
> }
> ```

## Next steps

> [card] [Receive events](https://docs.newlead.ai/webhooks.md)
>
> Get lead, message and call events at your URL.

> [card] [Handle errors](https://docs.newlead.ai/errors.md)
>
> Learn what each error means and when to retry.

> [card] [Retry safely](https://docs.newlead.ai/idempotency.md)
>
> Repeat a request without sending anything twice.

> [card] [Use n8n](https://docs.newlead.ai/n8n.md)
>
> Build the same flow with the official node.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.