# Campaigns API

Source: https://aicallstudio.com/docs/api/campaigns. Authentication, scopes, limits, errors and webhooks: https://aicallstudio.com/docs/api

### List campaigns

`GET /api/v1/campaigns` (scope `campaigns:read`)

Your campaigns, newest first. Deleted campaigns are left out.

**Parameters**

| Parameter | Type | What it is |
| --- | --- | --- |
| `status` | string, or null, in the query | Only campaigns with this status, such as running. |
| `limit` | integer, 1 to 100, in the query | Default: 50. |
| `cursor` | string, or null, in the query | `next_cursor` from the previous page. |

**Answer (200): these fields**

| Field | Type | What it is |
| --- | --- | --- |
| `data` (required) | list of objects | — |
| `data[].id` (required) | string (uuid) | — |
| `data[].name` | string, or null | — |
| `data[].status` (required) | string | draft, scheduled, running, paused, completed or cancelled. |
| `data[].mode` (required) | string | ai (an AI agent calls), power (your people call), whatsapp, sms or email. |
| `data[].agent_id` | string (uuid), or null | — |
| `data[].team_id` | string (uuid), or null | — |
| `data[].paused_reason` | string, or null | Why the campaign paused itself, such as wallet_empty; null when a person paused it or it is not paused. |
| `data[].created_at` | string (date-time), or null | — |
| `data[].started_at` | string (date-time), or null | — |
| `data[].finished_at` | string (date-time), or null | — |
| `next_cursor` | string, or null | — |

**Errors**

| Code | When |
| --- | --- |
| `401` | The token is missing, unknown or revoked, or its workspace was deleted. |
| `402` | The workspace's plan does not include API access. The token is paused, not revoked: it works again as soon as the plan includes API access. |
| `403` | The token does not have this endpoint's scope, it is a sandbox token, the workspace is suspended, or the request came from a network the workspace, or the token's IP allowlist, does not allow. |
| `422` | A field is missing or not in the form this endpoint takes. `detail` says which, and why. |
| `429` | This token has made more requests this minute than your plan allows. The Retry-After header says how many seconds to wait. |

```bash
curl "https://aicallstudio.com/api/v1/campaigns?limit=50" \
  -H "Authorization: Bearer mtc_YOUR_TOKEN"
```

### Add contacts to a campaign

`POST /api/v1/campaigns/{campaign_id}/contacts` (scope `campaigns:write`)

Add people to a calling campaign. While it runs they are rung like everyone else in it: within its schedule, your calling window and the plan's limits. Each call is billed.

Send `contacts` (found or saved by number, as Add or update a contact does) or `contact_ids`. A contact on Do-Not-Call is never added; one already in the campaign is not added twice.

This rings real customers. Each call is billed from your wallet like any other call, at your plan's rates.

**Parameters**

| Parameter | Type | What it is |
| --- | --- | --- |
| `campaign_id` (required) | string (uuid), in the path | — |
| `Idempotency-Key` | string, up to 255 characters, in the headers | Any unique text up to 255 characters, such as a UUID, chosen by you for this request. Sent again with the same body within 24 hours, the first answer comes back (with Idempotent-Replayed: true) and nothing is done twice. The same key with another body is refused with 422. |

**Request body (application/json)**

| Field | Type | What it is |
| --- | --- | --- |
| `contacts` | list of objects, or null | Contacts to add, found or saved by number (1 to 100). Send this or contact_ids. |
| `contacts[].phone` (required) | string, up to 20 characters | 8 to 15 digits, optionally starting with +. The same number in any format is the same contact. |
| `contacts[].name` | string, up to 255 characters, or null | Required for a new number; for a known one it renames it. |
| `contacts[].email` | string, up to 255 characters, or null | — |
| `contacts[].custom_fields` | object, or null | Your own fields, by field name. Merged into the contact's: a field you leave out is kept. |
| `contacts[].lead_type` | string, or null | The contact type's key, which decides the fields it needs. |
| `contacts[].source` | string, up to 50 characters, or null | Where the contact came from, in your words. |
| `contacts[].language` | string, or null | The language the person prefers, as a code or a name, such as hi-IN. |
| `contact_ids` | list of string (uuid), or null | Existing contacts to add, by id. |

**Answer (200): these fields**

| Field | Type | What it is |
| --- | --- | --- |
| `added` (required) | integer | — |
| `already` (required) | integer | — |
| `skipped_do_not_call` (required) | integer | — |
| `not_found` (required) | integer | — |
| `failed` | list of objects | Contacts in `contacts` that could not be saved. |
| `failed[].index` (required) | integer | The position of this contact in the list you sent, from 0. |
| `failed[].created` | boolean | Default: false. |
| `failed[].contact_id` | string (uuid), or null | — |
| `failed[].error` | string, or null | Why this one was not saved; null when it was. |

**Errors**

| Code | When |
| --- | --- |
| `401` | The token is missing, unknown or revoked, or its workspace was deleted. |
| `402` | The workspace's plan does not include API access. The token is paused, not revoked: it works again as soon as the plan includes API access. |
| `403` | The token does not have this endpoint's scope, it is a sandbox token, the workspace is suspended, or the request came from a network the workspace, or the token's IP allowlist, does not allow. |
| `404` | No calling campaign of yours has this id. |
| `409` | The campaign has finished. |
| `422` | A field is missing or not in the form this endpoint takes. `detail` says which, and why. |
| `429` | This token has made more requests this minute than your plan allows. The Retry-After header says how many seconds to wait. |

```bash
curl -X POST "https://aicallstudio.com/api/v1/campaigns/YOUR_CAMPAIGN_ID/contacts" \
  -H "Authorization: Bearer mtc_YOUR_TOKEN" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{"contacts":[{"phone":"+919876543210","name":"Asha Verma"}]}'
```

### Pause a campaign

`POST /api/v1/campaigns/{campaign_id}/pause` (scope `campaigns:write`)

Stop a running campaign from placing new calls. Calls already ringing finish.

This rings real customers. Each call is billed from your wallet like any other call, at your plan's rates.

**Parameters**

| Parameter | Type | What it is |
| --- | --- | --- |
| `campaign_id` (required) | string (uuid), in the path | — |
| `Idempotency-Key` | string, up to 255 characters, in the headers | Any unique text up to 255 characters, such as a UUID, chosen by you for this request. Sent again with the same body within 24 hours, the first answer comes back (with Idempotent-Replayed: true) and nothing is done twice. The same key with another body is refused with 422. |

**Answer (200): these fields**

| Field | Type | What it is |
| --- | --- | --- |
| `id` (required) | string (uuid) | — |
| `name` | string, or null | — |
| `status` (required) | string | draft, scheduled, running, paused, completed or cancelled. |
| `mode` (required) | string | ai (an AI agent calls), power (your people call), whatsapp, sms or email. |
| `agent_id` | string (uuid), or null | — |
| `team_id` | string (uuid), or null | — |
| `paused_reason` | string, or null | Why the campaign paused itself, such as wallet_empty; null when a person paused it or it is not paused. |
| `created_at` | string (date-time), or null | — |
| `started_at` | string (date-time), or null | — |
| `finished_at` | string (date-time), or null | — |

**Errors**

| Code | When |
| --- | --- |
| `401` | The token is missing, unknown or revoked, or its workspace was deleted. |
| `402` | The workspace's plan does not include API access. The token is paused, not revoked: it works again as soon as the plan includes API access. |
| `403` | The token does not have this endpoint's scope, it is a sandbox token, the workspace is suspended, or the request came from a network the workspace, or the token's IP allowlist, does not allow. |
| `404` | No campaign of yours has this id. |
| `409` | The campaign is not running. |
| `422` | A field is missing or not in the form this endpoint takes. `detail` says which, and why. |
| `429` | This token has made more requests this minute than your plan allows. The Retry-After header says how many seconds to wait. |

```bash
curl -X POST "https://aicallstudio.com/api/v1/campaigns/YOUR_CAMPAIGN_ID/pause" \
  -H "Authorization: Bearer mtc_YOUR_TOKEN" \
  -H "Idempotency-Key: $(uuidgen)"
```

### Resume a campaign

`POST /api/v1/campaigns/{campaign_id}/resume` (scope `campaigns:write`)

Start a paused campaign calling again. It rings real customers and each call is billed.

The same checks as pressing Resume on the Campaigns page apply: the plan, a phone line, the schedule and your calling window. If the campaign paused itself (an empty wallet, say) and the reason still holds, it pauses again and says why in `paused_reason`.

This rings real customers. Each call is billed from your wallet like any other call, at your plan's rates.

**Parameters**

| Parameter | Type | What it is |
| --- | --- | --- |
| `campaign_id` (required) | string (uuid), in the path | — |
| `Idempotency-Key` | string, up to 255 characters, in the headers | Any unique text up to 255 characters, such as a UUID, chosen by you for this request. Sent again with the same body within 24 hours, the first answer comes back (with Idempotent-Replayed: true) and nothing is done twice. The same key with another body is refused with 422. |

**Answer (200): these fields**

| Field | Type | What it is |
| --- | --- | --- |
| `id` (required) | string (uuid) | — |
| `name` | string, or null | — |
| `status` (required) | string | draft, scheduled, running, paused, completed or cancelled. |
| `mode` (required) | string | ai (an AI agent calls), power (your people call), whatsapp, sms or email. |
| `agent_id` | string (uuid), or null | — |
| `team_id` | string (uuid), or null | — |
| `paused_reason` | string, or null | Why the campaign paused itself, such as wallet_empty; null when a person paused it or it is not paused. |
| `created_at` | string (date-time), or null | — |
| `started_at` | string (date-time), or null | — |
| `finished_at` | string (date-time), or null | — |

**Errors**

| Code | When |
| --- | --- |
| `401` | The token is missing, unknown or revoked, or its workspace was deleted. |
| `402` | The workspace's plan does not include API access. The token is paused, not revoked: it works again as soon as the plan includes API access. The plan's campaign limit is reached. |
| `403` | The token does not have this endpoint's scope, it is a sandbox token, the workspace is suspended, or the request came from a network the workspace, or the token's IP allowlist, does not allow. |
| `404` | No campaign of yours has this id. |
| `409` | The campaign is not paused, or has no phone line to call from. |
| `422` | A field is missing or not in the form this endpoint takes. `detail` says which, and why. |
| `429` | This token has made more requests this minute than your plan allows. The Retry-After header says how many seconds to wait. |

```bash
curl -X POST "https://aicallstudio.com/api/v1/campaigns/YOUR_CAMPAIGN_ID/resume" \
  -H "Authorization: Bearer mtc_YOUR_TOKEN" \
  -H "Idempotency-Key: $(uuidgen)"
```

### Campaign progress

`GET /api/v1/campaigns/{campaign_id}/stats` (scope `campaigns:read`)

How far a calling campaign has got: people it may ring, rung and reached, and today's calls. Counted the way the Campaigns page counts them.

**Parameters**

| Parameter | Type | What it is |
| --- | --- | --- |
| `campaign_id` (required) | string (uuid), in the path | — |

**Answer (200): these fields**

| Field | Type | What it is |
| --- | --- | --- |
| `campaign_id` (required) | string (uuid) | — |
| `status` (required) | string | — |
| `contacts_total` (required) | integer | People the campaign may ring in all. |
| `contacts_dialled` (required) | integer | Of those, people it has rung. |
| `contacts_reached` (required) | integer | People who picked up (an answering machine does not count). |
| `calls_today` (required) | integer | Calls the campaign placed today, India time. |
| `connected_today` (required) | integer | Of those, calls someone picked up. |

**Errors**

| Code | When |
| --- | --- |
| `401` | The token is missing, unknown or revoked, or its workspace was deleted. |
| `402` | The workspace's plan does not include API access. The token is paused, not revoked: it works again as soon as the plan includes API access. |
| `403` | The token does not have this endpoint's scope, it is a sandbox token, the workspace is suspended, or the request came from a network the workspace, or the token's IP allowlist, does not allow. |
| `404` | No campaign of yours has this id. |
| `422` | A field is missing or not in the form this endpoint takes. `detail` says which, and why. |
| `429` | This token has made more requests this minute than your plan allows. The Retry-After header says how many seconds to wait. |

```bash
curl "https://aicallstudio.com/api/v1/campaigns/YOUR_CAMPAIGN_ID/stats" \
  -H "Authorization: Bearer mtc_YOUR_TOKEN"
```
