---
title: "Load leads into a campaign"
url: "https://coldagentai.com/docs/guides/add-leads-to-a-campaign.md"
canonical_url: "https://coldagentai.com/docs/guides/add-leads-to-a-campaign"
last_updated: "2026-10-22"
type: "how-to"
summary: "Load leads into a ColdAgentAI campaign from JSON or CSV, read why each row was added or skipped, and verify addresses first."
related: ["https://coldagentai.com/docs/api/leads.md", "https://coldagentai.com/docs/api/campaigns.md", "https://coldagentai.com/docs/api/verification.md", "https://coldagentai.com/docs/api/imports.md", "https://coldagentai.com/docs/api/blocklist.md", "https://coldagentai.com/docs/errors.md"]
install: "claude mcp add --transport http coldagentai-free https://coldagentai.com/api/mcp"
---

# Load leads into a campaign

> **For AI agents:** the complete index of ColdAgentAI pages is [llms.txt](https://coldagentai.com/llms.txt). Every page is also served as markdown at its URL plus .md.

Load leads into a ColdAgentAI campaign from JSON or CSV, read why each row was added or skipped, and verify addresses first.

Put leads into a campaign from JSON or a CSV file, see why any row was skipped, and read the list back.

## What you need

- A key with write scope. Adding leads changes state, so a read key gets `403 forbidden`. See [Authentication](https://coldagentai.com/docs/authentication.md).
- A campaign id. `POST /v1/campaigns` creates a campaign and returns its `id`; `GET /v1/campaigns` lists the ones you have.
- Your leads, as objects with an `email` and optional `first_name`, `last_name`, `company_name`, `title` and `custom_fields`, or as one CSV file.

Both routes take at most 1,000 leads per request. Send larger lists in several requests.

## Optionally verify the addresses first

`POST /v1/email-verification` checks up to 1,000 addresses per request and spends credits from your wallet. A recent result is reused without a charge. When a fresh check finishes for an address that already belongs to a lead in your account, the result is stored on that lead and shows in its `verification` field. A lead added afterwards starts as `unverified`, and a reused result is not copied onto it.

Send an `Idempotency-Key` header so a retry after a timeout does not pay twice. The same key with a different list of addresses is refused.

cURL:

```
curl -X POST https://api.coldagentai.com/v1/email-verification \
  -H "Authorization: Bearer $COLDAGENTAI_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: verify-2026-10-18-batch-1" \
  -d '{ "emails": ["ada@example.com", "grace@example.org"] }'
```

Node:

```
const base = 'https://api.coldagentai.com';
const headers = { Authorization: `Bearer ${process.env.COLDAGENTAI_API_KEY}`, 'Content-Type': 'application/json' };

async function call(method, path, body) {
  const res = await fetch(base + path, { method, headers, body: body === undefined ? undefined : JSON.stringify(body) });
  const json = await res.json();
  if (!res.ok) throw new Error(`${json.error.code}: ${json.error.fix}`);
  return json;
}

const batch = await fetch(base + '/v1/email-verification', {
  method: 'POST',
  headers: { ...headers, 'Idempotency-Key': 'verify-2026-10-18-batch-1' },
  body: JSON.stringify({ emails: ['ada@example.com', 'grace@example.org'] }),
}).then((r) => r.json());

const sendable = batch.results.filter((r) => r.outcome === 'verified' && r.sendable).map((r) => r.email);
console.log(sendable, batch.credits_charged, batch.stopped_by);
```

Each result has an `outcome` of `verified`, `failed` or `skipped`. Only a `verified` result carries a `result` and a `sendable` flag. `invalid`, `risky` and `unknown` addresses are never sendable. If the wallet runs dry part way, `stopped_by` is `insufficient_credits` and the rest are `skipped`. `GET /v1/email-verification/{id}` reads a finished batch back without spending anything.

## Add leads as JSON

`POST /v1/campaigns/{id}/leads` takes a `leads` array. Addresses are compared case-insensitively against the rest of the request and against your account. A bad row never fails the others.

cURL:

```
curl -X POST https://api.coldagentai.com/v1/campaigns/$CAMPAIGN_ID/leads \
  -H "Authorization: Bearer $COLDAGENTAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "leads": [
      { "email": "ada@example.com", "first_name": "Ada", "company_name": "Analytical Engines", "custom_fields": { "city": "London" } },
      { "email": "grace@example.org", "first_name": "Grace" }
    ]
  }'
```

Node:

```
const base = 'https://api.coldagentai.com';
const headers = { Authorization: `Bearer ${process.env.COLDAGENTAI_API_KEY}`, 'Content-Type': 'application/json' };

async function call(method, path, body) {
  const res = await fetch(base + path, { method, headers, body: body === undefined ? undefined : JSON.stringify(body) });
  const json = await res.json();
  if (!res.ok) throw new Error(`${json.error.code}: ${json.error.fix}`);
  return json;
}

const result = await call('POST', `/v1/campaigns/${process.env.CAMPAIGN_ID}/leads`, {
  leads: [
    { email: 'ada@example.com', first_name: 'Ada', company_name: 'Analytical Engines', custom_fields: { city: 'London' } },
    { email: 'grace@example.org', first_name: 'Grace' },
  ],
});
console.log(result.created, result.updated, result.duplicates, result.rejected);
```

A `custom_fields` key must start with a letter and use only letters, digits and underscores. Each custom field is usable as a merge field in the sequence.

## Import a CSV file

`POST /v1/campaigns/{id}/leads/import` takes the file text as the request body with `Content-Type: text/plain`. A file can hold at most 1,000 data rows, and the request body is limited to 256 KB; a larger body is refused with `payload_too_large`. The first row is the header, and the email column is found by its name. First name, last name, company and title are mapped from their usual headers, and every other column becomes a custom field.

- Add `?layout=smartlead` to read an export with that layout; its activity columns are skipped.
- A cell that starts with `=`, `+`, `-` or `@` is kept as text and counted in `flagged_cells`, so you know it could act as a formula if you write it back to a spreadsheet.
- Rows the parser itself refused come back in `csv_rejected` with their line number. Nothing from a file that cannot be read at all is stored.

cURL:

```
curl -X POST https://api.coldagentai.com/v1/campaigns/$CAMPAIGN_ID/leads/import \
  -H "Authorization: Bearer $COLDAGENTAI_API_KEY" \
  -H "Content-Type: text/plain" \
  --data-binary @leads.csv
```

Node:

```
import { readFile } from 'node:fs/promises';

const base = 'https://api.coldagentai.com';
const csv = await readFile('leads.csv', 'utf8');
const res = await fetch(`${base}/v1/campaigns/${process.env.CAMPAIGN_ID}/leads/import`, {
  method: 'POST',
  headers: { Authorization: `Bearer ${process.env.COLDAGENTAI_API_KEY}`, 'Content-Type': 'text/plain' },
  body: csv,
});
const result = await res.json();
if (!res.ok) throw new Error(`${result.error.code}: ${result.error.fix}`);
console.log(result.created, result.rejected, result.csv_rejected, result.flagged_cells, result.warnings);
```

## Read the result

Both routes return the counts and an entry in `rows` for each row they processed. On the JSON route, `index` is the position in your `leads` array, starting at 0. On CSV import, `index` counts only the rows the parser accepted, so use `csv_rejected[].line` for refused rows and match the others by `email`.

| Outcome | Meaning | What to do |
| --- | --- | --- |
| `created` | A new lead was stored and enrolled in this campaign. | Nothing. |
| `updated` | The address was already in your account. The fields you sent were applied and the lead was enrolled in this campaign. | Nothing, unless you did not mean to overwrite its fields. |
| `duplicate` | The address repeats an earlier row in the same request. | Remove the repeat from your source list. |
| `rejected` | The row was not added. `reason` says why in plain words. | See the reasons below. |

### Why a row is rejected

- The address is not a valid email address.
- A field value is too long, or the lead would end up with too many custom fields.
- The address is on your do-not-contact list, either by an entry you added or because the person opted out. `GET /v1/blocklist` shows the entries. Entries that record an opt-out cannot be removed.
- The address is new to your account and the plan's active-contact cap is already reached. Addresses that are already in your account are not blocked by the cap. Leads that are unsubscribed, bounced or blocked do not count toward it.

### Read the list back

`GET /v1/campaigns/{id}/leads` returns the enrolled leads oldest first. Filter with `status` (`new`, `contacted`, `replied`, `interested`, `meeting_booked`, `not_interested`, `bounced`, `unsubscribed` or `blocked`). `limit` goes up to 100; pass `next_cursor` as `cursor` for the next page. See [Pagination](https://coldagentai.com/docs/pagination.md).

cURL:

```
curl "https://api.coldagentai.com/v1/campaigns/$CAMPAIGN_ID/leads?status=new&limit=50" \
  -H "Authorization: Bearer $COLDAGENTAI_API_KEY"
```

Node:

```
const base = 'https://api.coldagentai.com';
const headers = { Authorization: `Bearer ${process.env.COLDAGENTAI_API_KEY}`, 'Content-Type': 'application/json' };

async function call(method, path, body) {
  const res = await fetch(base + path, { method, headers, body: body === undefined ? undefined : JSON.stringify(body) });
  const json = await res.json();
  if (!res.ok) throw new Error(`${json.error.code}: ${json.error.fix}`);
  return json;
}

let cursor;
do {
  const query = new URLSearchParams({ status: 'new', limit: '50', ...(cursor ? { cursor } : {}) });
  const page = await call('GET', `/v1/campaigns/${process.env.CAMPAIGN_ID}/leads?${query}`);
  for (const lead of page.data) console.log(lead.email, lead.status, lead.verification);
  cursor = page.next_cursor ?? undefined;
} while (cursor);
```

## What can go wrong

| Code | Cause | Fix |
| --- | --- | --- |
| [`forbidden`](https://coldagentai.com/docs/errors.md#forbidden) | The key has read scope. | Use a write key. |
| [`unknown_product`](https://coldagentai.com/docs/errors.md#unknown_product) | The campaign id is not in your account. | List campaigns with `GET /v1/campaigns` and use one of those ids. |
| [`invalid_input`](https://coldagentai.com/docs/errors.md#invalid_input) | The body is not valid, a batch is larger than 1,000, or the CSV has no email column. | Read `error.message` and `error.fix`, correct the request and send it again. Nothing was stored. |
| [`payload_too_large`](https://coldagentai.com/docs/errors.md#payload_too_large) | The request body is over the size limit. | Split the list into smaller requests. |
| [`rate_limited`](https://coldagentai.com/docs/errors.md#rate_limited) | Too many requests for this key. | Wait `Retry-After` seconds. See [Rate limits](https://coldagentai.com/docs/rate-limits.md). |
| [`insufficient_credits`](https://coldagentai.com/docs/errors.md#insufficient_credits) | Verification needs more credits than the wallet holds. | Add credits, or send a smaller batch. |
| [`provider_unavailable`](https://coldagentai.com/docs/errors.md#provider_unavailable) | Verification has no provider that can run on this server. | Read `GET /v1/capabilities`, slot `verifiers`. |

## Next steps

- Set the sequence with `PUT /v1/campaigns/{id}/sequence`, preview a step against a real lead with `POST /v1/campaigns/{id}/preview`, then start with `POST /v1/campaigns/{id}/start`. See [Campaigns](https://coldagentai.com/docs/api/campaigns.md).
- Move a lead to a new status with `PATCH /v1/leads/{id}`. See [Leads](https://coldagentai.com/docs/api/leads.md).
- Add addresses you never want to mail with `POST /v1/blocklist`. See [Do-not-contact list](https://coldagentai.com/docs/api/blocklist.md).

## Related

- [Leads API reference](https://coldagentai.com/docs/api/leads.md)
- [Campaigns API reference](https://coldagentai.com/docs/api/campaigns.md)
- [Verification API reference](https://coldagentai.com/docs/api/verification.md)
- [Imports API reference](https://coldagentai.com/docs/api/imports.md)
- [Blocklist API reference](https://coldagentai.com/docs/api/blocklist.md)
- [API errors](https://coldagentai.com/docs/errors.md)
