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

# Campaigns API

> Create managed calling campaigns with their leads, add leads to an open campaign, follow progress, calls and attention items, and manage the workspace campaign policy.

Campaigns are the ones on the **Campaigns** page: each lead is called within
the campaign's calling windows, and retried, called back or redirected as its
lead policy allows, until it finishes. See
[Managed calling](https://cntillion.com/docs/campaigns/managed-calling.md) for how a campaign decides.
A campaign calls from a phone number or on WhatsApp, or sends each lead a
WhatsApp message template ([WhatsApp campaigns](#whatsapp-campaigns)).
The API and the dashboard create the same campaigns, run the same checks and
show the same results.

Campaigns use the [Developer API](https://cntillion.com/docs/api-reference/developer-api.md) workspace
keys. The base URL is `https://app.cntillion.com/api/v2`. Reads accept either
key permission. Writes need a **Full access** key. A
key acts as the person who created it, who must have agreed to the outbound
communications terms in the dashboard before their first campaign or test
call; otherwise a campaign is refused with `403 OUTBOUND_TERMS_REQUIRED`.

These endpoints answer only for Campaigns page campaigns. A batch call or a
campaign that enrolls contacts is refused with
`409 CAMPAIGN_KIND_UNSUPPORTED`; use the
[batch call](https://cntillion.com/docs/api-reference/batch-calls.md) or
[enrollment](https://cntillion.com/docs/api-reference/contacts-and-enrollments.md) endpoints for those.

## Endpoints

Paths below are relative to `/api/v2`.

| Method | Path | Behavior |
| - | - | - |
| POST | `/campaigns` | Create a campaign with its leads and start it, or schedule it. |
| GET | `/campaigns` | List the workspace's campaigns, newest first. |
| GET | `/campaigns/{campaignId}` | Read a campaign, its policy and counts. |
| GET | `/campaigns/{campaignId}/progress` | Leads by state, calls waiting by type, and the next call. |
| GET | `/campaigns/{campaignId}/follow-up-requests` | Callbacks and redirects people asked for, and what became of them. |
| POST | `/campaigns/{campaignId}/pause` | Place no new calls until resumed. |
| POST | `/campaigns/{campaignId}/resume` | Call again, or wait for a start still ahead. |
| POST | `/campaigns/{campaignId}/cancel` | Call nobody else; calls under way finish. |
| POST | `/campaigns/pause-all` | Pause every running or scheduled campaign. |
| POST | `/campaigns/cancel-all` | Cancel every campaign that has not finished. |
| GET | `/campaigns/{campaignId}/leads` | List leads, filtered by state, disposition, your id or text. |
| POST | `/campaigns/{campaignId}/leads` | Add leads to a campaign kept open for them. |
| GET | `/campaigns/{campaignId}/leads/{leadId}` | Read a lead with its calls and decision timeline. |
| DELETE | `/campaigns/{campaignId}/leads/{leadId}` | Remove a lead waiting for a call. |
| GET | `/campaigns/{campaignId}/calls` | List the calls placed, newest first. |
| GET | `/campaigns/{campaignId}/calls/export` | Download every call as CSV. |
| GET | `/campaigns/{campaignId}/attention` | List what needs a person. |
| POST | `/campaigns/{campaignId}/attention/{attentionId}/resolve` | Mark an item handled, or open it again. |
| POST | `/campaigns/{campaignId}/attention/{attentionId}/retry` | Call the lead again, or resume the campaign. |
| GET | `/campaigns/attention` | List what needs a person across every campaign, a page at a time. |
| POST | `/campaigns/attention/{attentionId}/resolve` | Resolve an item by its id alone. |
| POST | `/campaigns/attention/{attentionId}/retry` | Retry an item by its id alone. |
| GET | `/campaign-settings` | Read the workspace's campaign policy. |
| PUT | `/campaign-settings` | Replace it, against the version read. |

## Create a campaign

```bash theme={null}
curl 'https://app.cntillion.com/api/v2/campaigns' \
  -H "Authorization: Bearer $CENTILLION_API_KEY" \
  -H 'Content-Type: application/json' \
  -H 'Idempotency-Key: renewals-november' \
  -d '{
    "name": "November renewals",
    "agentId": "YOUR_AGENT_ID",
    "channel": {"type": "phone", "phoneLineId": "YOUR_PHONE_LINE_ID"},
    "timezone": "America/New_York",
    "recipients": [{
      "phoneNumber": "+12025550101",
      "phoneNumbers": ["+12025550111"],
      "recipientId": "crm-4021",
      "name": "Jamie",
      "variables": {"lead_id": "crm-4021", "plan": "gold"}
    }]
  }'
```

The answer is `201` with the campaign in `data`, `created: true`,
`callingStartsAt` (when the first call may go out: the start, or the next
calling window after it) and `withinCallingWindow` (whether that is now).
The campaign, its leads and its launch are written together, or not at all.

| Field | Meaning |
| - | - |
| `name` | 1 to 120 characters. |
| `agentId` | The agent that places the calls. It needs voice on and a calling number that can dial. |
| `channel.phoneLineId` | An active workspace number that can dial out. |
| `channel.ringingTimeoutSeconds` | 5 to 120. Defaults to 60. |
| `channel.answeringMachineDetection` | Whether calls detect voicemail. On by default. |
| `recipients` | Up to 1,000 leads. Leave it out only with `keepOpen`. |
| `startsAt` | When calling may start, ISO 8601. Left out, at once. Calls still wait for a calling window; a time already past is refused. |
| `timezone` | An IANA timezone the calling windows are read in, instead of the policy's. |
| `branchId` | A published branch to call with. Left out, the agent's traffic split decides. |
| `concurrencyLimit` | The most calls at once, within the workspace and agent limits. Left out, Automatic. |
| `callsPerMinute` | 1 to 20. Defaults to 20. |
| `allowedOverrides` | Which of `prompt`, `first_message`, `language` and `voice_id` a lead may override. Defaults to all four. |
| `variant` | `advanced` (the default) follows the policy. `simple` gives every lead one call to its first number, at any time, and takes no `policy`. A WhatsApp text campaign is always `simple`. |
| `policy` | Policy groups to use instead of the workspace's: `timezone`, `callingWindows`, `retries`, `dataCollection` or `followUpContext`, each replacing that whole group. |
| `keepOpen` | Keep the campaign open for leads added later. It then completes only when cancelled. |
| `idempotencyKey` | The same as the `Idempotency-Key` header; send one or the other. |

Each recipient has a `phoneNumber` in E.164 format, up to four more
`phoneNumbers` called in order once calls to the one before keep failing,
an optional `recipientId` of your own (unique in the campaign), a `name`,
`variables` and `overrides`. A lead carries at most 56 variables: every call
adds the four `campaign__` follow-up variables, and a call carries 60. Each
lead must carry every dynamic variable the agent's published versions use,
even empty; a lead without one is refused with `400 MISSING_VARIABLES`. A
number may appear once per campaign, and the campaign's own calling number
not at all.

A repeat within 24 hours with the same idempotency key returns `200`, the
campaign as it is now and `created: false`; the same key with another body is
refused with `409 IDEMPOTENCY_KEY_REUSED`. Without a key, a repeat of exactly
the same body returns the campaign the first request made.

## WhatsApp campaigns

A WhatsApp campaign takes `channel.type: "whatsapp"`, the
`whatsappAccountId` of an active account assigned to the agent, and a
`mode`:

* `voice` calls each lead on WhatsApp, with the same policy, retries and
  callbacks as a phone campaign (the workspace's WhatsApp policy). Its
  optional `template` is an approved template with a call permission
  request, sent once to a lead who has not allowed calls yet.
* `text` sends each lead one approved message `template`, which it needs,
  and the agent answers whoever replies. It has no policy, so it is always
  `simple`.

```json theme={null}
{
  "name": "Order ready",
  "agentId": "YOUR_AGENT_ID",
  "channel": {
    "type": "whatsapp",
    "whatsappAccountId": "YOUR_WHATSAPP_ACCOUNT_ID",
    "mode": "text",
    "template": {
      "name": "order_ready",
      "language": "en_US",
      "variables": {"body": {"1": "first_name"}}
    }
  },
  "recipients": [{"phoneNumber": "+12025550101", "name": "Jamie", "variables": {"first_name": "Jamie"}}]
}
```

`template.variables` says which lead variable fills each of the template's
values, keyed as the [WhatsApp template list](https://cntillion.com/docs/api-reference/developer-api.md)
names them: text placeholders by name or number under `body` and `header`,
buttons by position from 1 under `buttons`, and a media header's public link
as `headerMedia`. A value left out is read from the lead variable of its own
name, so `{{first_name}}` needs no entry; a numbered placeholder such as
`{{1}}` does. Every lead must carry each variable the template reads. The
template is checked with Meta when the campaign is created and again when
it starts; one Meta no longer approves, or a placeholder without a variable,
is refused with `400 INVALID_TEMPLATE`.

A lead's `phoneNumber` is its WhatsApp number, and `phoneNumbers` is
refused: a WhatsApp campaign reaches each lead on one number. The key's
creator must have agreed to the WhatsApp outbound terms in the dashboard.
An open WhatsApp campaign takes leads through the leads endpoint like a
phone campaign.

## The policy

A campaign takes a copy of the policy when it is created: the workspace's
default, the agent's override groups, then the groups the request sends.
Changing the workspace settings later never changes a running campaign.

```json theme={null}
{
  "timezone": "America/New_York",
  "callingWindows": [
    {"weekdays": [0, 1, 2, 3, 4], "intervals": [{"start": "10:00", "end": "12:00"}, {"start": "16:00", "end": "24:00"}]}
  ],
  "retries": {
    "maxTotalCalls": 6,
    "maxShortRetries": 1,
    "maxCallbacks": 2,
    "maxRedirects": 2,
    "maxConsecutiveFailures": null,
    "retryDelaySeconds": 600,
    "intervalPlacement": "start",
    "rotateStepSeconds": 900
  },
  "dataCollection": {"callbacks": true, "redirects": true, "doNotCall": true, "mappings": []},
  "followUpContext": {
    "callType": true,
    "previousConversationId": true,
    "previousSummary": true,
    "previousTranscript": true
  }
}
```

Weekdays run from `0` (Monday) to `6` (Sunday); times are `HH:MM` in the
policy's timezone, and an end of `24:00` runs until midnight. Timeframes on
one day may not overlap. A callback the person asked for dials at its time,
outside the windows. `followUpContext` says which `campaign__` variables
later calls get; one switched off is sent empty, so a prompt that mentions it
still starts. `GET /campaign-settings` returns the workspace's settings with
their `version`; `PUT /campaign-settings` with
`{"expectedVersion": 3, "settings": {...}}` replaces them, and is refused with
`409 CAMPAIGN_SETTINGS_CHANGED` when someone saved since that version.

## Add leads to an open campaign

A system that sends leads one at a time creates the campaign once, with
`keepOpen: true` and as many leads as it has (none is fine), then adds the
rest as they come:

```bash theme={null}
curl 'https://app.cntillion.com/api/v2/campaigns/YOUR_CAMPAIGN_ID/leads' \
  -H "Authorization: Bearer $CENTILLION_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{"leads": [{"phoneNumber": "+12025550102", "recipientId": "crm-4022", "variables": {"lead_id": "crm-4022"}}]}'
```

Up to 200 leads per request, checked as the create request's recipients are.
A lead whose `recipientId`, or number when it has none, is already in the
campaign is returned as it is with `created: false`, so sending a lead again
adds it once; a number already there under another `recipientId` is refused
with `409`. The answer is `201` when any lead was added. New leads are
queued like the others: the first call waits for the start and a calling
window. Only an open campaign that is scheduled, running or paused takes
leads.

## Follow a campaign

`status` is `active` (calling, or waiting for its start), `paused`,
`needs_attention` (it paused itself; `lastError` says why), `cancelling`,
`cancelled`, `completed` or `failed`. Lists take `limit` and `cursor`; pass
the returned `pagination.cursor` with the same filters for the next page.
The campaign list filters by `agentId`, `status` and `search`.

A lead's `state` is `queued`, `in_progress` (on a call or being settled) or
`finished`, with its `disposition`, `nextCall`, counters, variables and, on
the single lead, its calls and decision timeline. `DELETE` removes a lead
that waits for a call; one on a call is refused with `409 LEAD_NOT_REMOVABLE`.

Pause, resume and cancel take no body. A campaign already where the action
leaves it answers as it is; a finished campaign is refused with
`409 CAMPAIGN_STATE_CONFLICT`. Cancelling finishes every waiting lead as
`cancelled`.

## Attention items

Attention items are leads that could not be processed, gave a callback time
or a number that could not be used, or were set aside for review, and the
pause a campaign put itself in, which carries the campaign's own id. A lead
with an item is not called again unless the item is retried.

`GET /campaigns/attention` lists them across every campaign in the
workspace, newest first, open ones only unless `includeResolved=true`.
`campaignId` keeps one campaign's, and `limit` and `cursor` page through
them. `GET /campaigns/{campaignId}/attention` lists one campaign's 200 most
recent at once.

| Field | Meaning |
| - | - |
| `id` | The lead's id, or the campaign's for its own pause. |
| `campaignId` | The campaign it belongs to. |
| `kind` | `lead` or `campaign`. |
| `reasonCode` | `invalid_callback_time`, `invalid_redirect_number`, `could_not_process`, `needs_review` or `campaign_paused`. |
| `reason`, `detail` | The cause in words, and what to fix. |
| `status` | `open` or `resolved`. |
| `retryable` | Whether a retry places another call or resumes the campaign. An item that can't be retried is closed by resolving it. |
| `at` | When the item arose. Resolving it does not move it. |

Resolve a lead's item with `{}` (or `{"resolved": false}` to open it again).
Retry queues the lead for another call, which waits for a calling window and
counts toward the policy's limits, or resumes the campaign for its own pause;
a lead at its call limit is refused with `409 LEAD_AT_CALL_LIMIT`. Both work
under the campaign's path or by the item's id alone under
`/campaigns/attention/{attentionId}`; an id that names no item in the
workspace is `404 ATTENTION_NOT_FOUND`.

The [`campaign.lead_finished` webhook](https://cntillion.com/docs/developer-guides/webhooks) tells
your system when each lead finishes, including leads no call ever reached.


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