# Campaigns

> Call a list of contacts with an assistant: create a campaign, add or import contacts, set calling windows and retries, then start, pause and follow it.

A **campaign** calls a list of contacts with an assistant. The dialer works through the list at the pace you set, only inside your calling windows, retries the people it didn't reach, and checks every contact against the compliance rules just before dialling. You add contacts, start the campaign, and follow the results.

A campaign moves through these states:

| `state` | Meaning |
| --- | --- |
| `draft` | Being set up. Nothing is dialled. |
| `scheduled` | Started with a later `start_at`; dialling begins then. |
| `running` | Dialling, inside the calling windows. |
| `paused` | Not dialling new calls. Calls in progress finish. |
| `completed` | Every contact reached a final status. |
| `cancelled` | Stopped for good. |

## Create a campaign

`name` and `purpose` are required. Everything else takes the defaults the dashboard uses, and the campaign starts as a `draft`:

**cURL**

```sh
# A draft campaign: it dials nobody until you add contacts and start it.
curl https://api.morevoice.ai/v1/campaigns \
  -H "Authorization: Bearer $MOREVOICE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "November flu-shot reminders",
    "purpose": "service",
    "assistant_id": "'"$ASSISTANT_ID"'"
  }'
```

**Node.js**

```ts title="create-campaign.ts"
import MoreVoice from "@morevoice/sdk";

const mv = new MoreVoice(); // reads MOREVOICE_API_KEY

// A draft campaign: it dials nobody until you add contacts and start it.
const campaign = await mv.campaigns.create({
	name: "November flu-shot reminders",
	purpose: "service",
	assistant_id: process.env.ASSISTANT_ID!,
});
console.log(campaign.id); // cmp_…
```

**Python**

```python title="create_campaign.py"
import os

import requests

API = "https://api.morevoice.ai/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['MOREVOICE_API_KEY']}"}

# A draft campaign: it dials nobody until you add contacts and start it.
response = requests.post(
    f"{API}/campaigns",
    headers=HEADERS,
    json={
        "name": "November flu-shot reminders",
        "purpose": "service",
        "assistant_id": os.environ["ASSISTANT_ID"],
    },
    timeout=30,
)
response.raise_for_status()
print(response.json()["id"])  # cmp_…
```

`purpose` works as on a [single call](https://docs.morevoice.ai/guides/outbound-calls/#purpose-and-compliance): `marketing` campaigns need a recorded consent for every contact (§30A) and pass the national do-not-call registry, and they always play the AI and recording disclosure. Choose `service` or `survey` only when the call really is one.

## Settings

Send any of these when you create the campaign, or change them later with `PATCH /v1/campaigns/{id}` (nested objects are merged with the stored values). A completed or cancelled campaign can't be changed, and a running one must be paused before its `purpose` changes.

| Field | What it does |
| --- | --- |
| `assistant_id` | The assistant that talks. |
| `connection_id`, `caller_id` | The SIP connection to dial through and the number to show (by default, the organisation's default connection and its caller ID). |
| `schedule` | When it may dial: see [calling windows](#calling-windows). |
| `retry` | Whom to call again, and when: see [retries](#retries). |
| `max_concurrent` | Calls this campaign may have in progress at once (1–500). |
| `calls_per_second` | New calls per second (0–100; `0` leaves it to the connection's limit). |
| `priority` | 1–10. When campaigns compete for lines, the higher one goes first. |
| `ring_timeout_seconds` | Give up on an unanswered call after this long (5–120). |
| `amd` | Answering machines: `{ "mode": "off" }`, `"hangup"`, or `"leave_message"` with a `message`. |
| `first_message` | Replaces the assistant's first sentence for this campaign. `{{variables}}` come from each contact. |
| `script` | Extra instructions for the assistant in this campaign, for example the offer. `{{variables}}` allowed. |
| `dispositions` | The outcomes the assistant can record, such as `interested` or `callback-requested`. |
| `disclosure` | The AI and recording disclosure played before the first message. `enabled: null` follows the organisation's default, which is on for marketing; a marketing campaign can't turn it off. |
| `opt_out_dtmf_key` | The key a contact presses to opt out (by default, the organisation's). |

### Calling windows

`schedule.windows` lists when the campaign may dial, in `schedule.timezone` (or each contact's own `timezone`). Up to 14 windows, each with weekdays and a start and end time:

```json title="Part of a campaign"
{
  "schedule": {
    "timezone": "Asia/Jerusalem",
    "windows": [
      { "days": ["sun", "mon", "tue", "wed", "thu"], "start": "09:00", "end": "19:00" },
      { "days": ["fri"], "start": "09:00", "end": "13:00" }
    ],
    "respect_shabbat": true,
    "respect_holidays": true,
    "start_at": null,
    "end_at": "2026-11-30T18:00:00.000Z"
  }
}
```

The organisation's own calling hours, Shabbat and holidays apply on top of the campaign's windows, whatever it says: a campaign can only narrow them, never widen them. `end_at` stops the dialling at that time. [Compliance](https://docs.morevoice.ai/guides/compliance/#calling-hours-shabbat-and-holidays) explains the rules.

### Retries

`retry.max_attempts` is the most times one contact is dialled, the first call included (1–20). For each result you choose whether to try again, and after how many minutes:

```json title="Part of a campaign"
{
  "retry": {
    "max_attempts": 3,
    "busy": { "enabled": true, "delay_minutes": 15 },
    "no_answer": { "enabled": true, "delay_minutes": 60 },
    "voicemail": { "enabled": true, "delay_minutes": 120 },
    "declined": { "enabled": false, "delay_minutes": 240 },
    "failed": { "enabled": true, "delay_minutes": 10 }
  }
}
```

A retry still waits for an open calling window.

## Add contacts

Send up to 1,000 contacts per request. Numbers can be in E.164 (`+972…`) or national format (`050-…`) with a `default_country`. Each contact can carry `variables` for the campaign's `{{variables}}`, and its own `timezone`:

**cURL**

```sh
# Up to 1,000 contacts per request. Numbers may be national (050-…) with a default country.
curl https://api.morevoice.ai/v1/campaigns/$CAMPAIGN_ID/contacts \
  -H "Authorization: Bearer $MOREVOICE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "default_country": "IL",
    "contacts": [
      { "phone": "+972501234567", "name": "דנה לוי", "variables": { "clinic": "רעננה" } },
      { "phone": "052-765-4321", "name": "יוסי כהן", "variables": { "clinic": "כפר סבא" } }
    ]
  }'
```

**Node.js**

```ts title="add-contacts.ts"
import MoreVoice from "@morevoice/sdk";

const mv = new MoreVoice(); // reads MOREVOICE_API_KEY

// Up to 1,000 contacts per request. Numbers may be national (050-…) with a default country.
const batch = await mv.campaigns.contacts.create(process.env.CAMPAIGN_ID!, {
	default_country: "IL",
	contacts: [
		{ phone: "+972501234567", name: "דנה לוי", variables: { clinic: "רעננה" } },
		{ phone: "052-765-4321", name: "יוסי כהן", variables: { clinic: "כפר סבא" } },
	],
});
console.log(`${batch.imported} added, ${batch.rejected} rejected`, batch.rejected_reasons);
```

**Python**

```python title="add_contacts.py"
import os

import requests

API = "https://api.morevoice.ai/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['MOREVOICE_API_KEY']}"}
campaign_id = os.environ["CAMPAIGN_ID"]

# Up to 1,000 contacts per request. Numbers may be national (050-…) with a default country.
response = requests.post(
    f"{API}/campaigns/{campaign_id}/contacts",
    headers=HEADERS,
    json={
        "default_country": "IL",
        "contacts": [
            {"phone": "+972501234567", "name": "דנה לוי", "variables": {"clinic": "רעננה"}},
            {"phone": "052-765-4321", "name": "יוסי כהן", "variables": {"clinic": "כפר סבא"}},
        ],
    },
    timeout=30,
)
response.raise_for_status()
batch = response.json()
print(f"{batch['imported']} added, {batch['rejected']} rejected", batch["rejected_reasons"])
```

Contacts are checked like a dashboard import: numbers are normalised, duplicates (in the request or already in the campaign) are dropped, and numbers on the do-not-call list are kept with the status `dnc` and never dialled. Send `drop_dnc: true` to leave them out entirely. The answer counts what happened and lists the first 100 problems by position:

```json title="Response"
{
  "object": "contact_batch_result",
  "campaign_id": "cmp_2Yb7mCq9aPLk",
  "livemode": true,
  "received": 2,
  "imported": 2,
  "rejected": 0,
  "rejected_reasons": { "invalid": 0, "duplicate": 0, "dnc": 0 },
  "without_consent": 0,
  "consent_recorded": 0,
  "errors": [],
  "warnings": []
}
```

### Consent for marketing campaigns

A marketing call needs evidence that the person agreed to be called: when, where and how. Send it with each contact as `consent`, with `granted_at` (an ISO-8601 time), `source` (for example the form's name) and `channel` (`web`, `phone`, `sms`, `email`, `whatsapp`, `app`, `written`, `in_person` or `other`). MoreVoice records it as a consent for that number. A contact without it is added, counted in `without_consent`, and skipped by the dialer until a consent is recorded.

## Import a file

For larger lists, upload a CSV or XLSX file of up to 10 MB and 50,000 rows. The import runs in the background:

**cURL**

```sh
# Upload a CSV or XLSX file (up to 10 MB). `mapping` says which column holds what;
# any other key (here "clinic") becomes a {{variable}}.
curl https://api.morevoice.ai/v1/campaigns/$CAMPAIGN_ID/contacts/import \
  -H "Authorization: Bearer $MOREVOICE_API_KEY" \
  -F file=@contacts.csv \
  -F 'mapping={"phone": "Mobile", "name": "Name", "clinic": "Clinic"}' \
  -F default_country=IL

# The import runs in the background: poll it until it succeeds or fails.
curl https://api.morevoice.ai/v1/imports/$IMPORT_ID \
  -H "Authorization: Bearer $MOREVOICE_API_KEY"
```

**Node.js**

```ts title="import-contacts.ts"
import MoreVoice from "@morevoice/sdk";

const mv = new MoreVoice(); // reads MOREVOICE_API_KEY

// Upload a CSV or XLSX file (up to 10 MB) and wait for the import to finish. `mapping` says which
// column holds what; any other key (here "clinic") becomes a {{variable}}.
const job = await mv.campaigns.importCsv(process.env.CAMPAIGN_ID!, "contacts.csv", {
	mapping: { phone: "Mobile", name: "Name", clinic: "Clinic" },
	default_country: "IL",
});
console.log(`${job.imported} imported, ${job.rejected} rejected`, job.rejected_reasons);
```

**Python**

```python title="import_contacts.py"
import json
import os
import time

import requests

API = "https://api.morevoice.ai/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['MOREVOICE_API_KEY']}"}
campaign_id = os.environ["CAMPAIGN_ID"]

# Upload a CSV or XLSX file (up to 10 MB). `mapping` says which column holds what;
# any other key (here "clinic") becomes a {{variable}}.
with open("contacts.csv", "rb") as f:
    response = requests.post(
        f"{API}/campaigns/{campaign_id}/contacts/import",
        headers=HEADERS,
        files={"file": ("contacts.csv", f, "text/csv")},
        data={
            "mapping": json.dumps({"phone": "Mobile", "name": "Name", "clinic": "Clinic"}),
            "default_country": "IL",
        },
        timeout=120,
    )
response.raise_for_status()
job = response.json()

# The import runs in the background: poll it until it succeeds or fails.
while job["status"] not in ("succeeded", "failed"):
    time.sleep(2)
    response = requests.get(f"{API}/imports/{job['id']}", headers=HEADERS, timeout=30)
    response.raise_for_status()
    job = response.json()
print(job["status"], f"{job['imported']} imported, {job['rejected']} rejected", job["rejected_reasons"])
```

- **`mapping`** says which column holds what: `phone` (required), `name`, `timezone`, and the consent columns `consent`, `consent_at`, `consent_source` and `consent_channel`. Any other key names a `{{variable}}`. Name columns by header or by 0-based index. Leave `mapping` out and the columns are detected the way the dashboard does it.
- **`default_country`** reads numbers written without a country code (IL by default).
- **`consent_source`** and **`consent_channel`** apply to every consenting row when the file has no such columns.
- **`has_header`** and **`drop_dnc`** work as their names say.

The upload answers `202 Accepted` with an `import` object. Poll `GET /v1/imports/{id}` until its `status` goes from `pending` and `processing` to `succeeded` or `failed`. The Node.js SDK's `campaigns.importCsv()` uploads and waits for you. A finished import counts the rows like a batch (`received`, `imported`, `rejected`, `rejected_reasons`, `without_consent`), lists the first 100 rejected rows with their row number in `errors`, and a failed one says why in `error`.

The same endpoint also takes JSON, with exactly one of `csv` (the file's text), `file` (`filename` and `content_base64`) or `url` (a public `https` address to download it from).

## Start the campaign

`start` runs the same pre-flight checks as the dashboard's Start button, then dials:

**cURL**

```sh
# Runs the pre-flight checks and starts dialling; a failed check answers 409 preflight_failed.
curl -X POST https://api.morevoice.ai/v1/campaigns/$CAMPAIGN_ID/start \
  -H "Authorization: Bearer $MOREVOICE_API_KEY"
```

**Node.js**

```ts title="start-campaign.ts"
import MoreVoice from "@morevoice/sdk";

const mv = new MoreVoice(); // reads MOREVOICE_API_KEY

// Runs the pre-flight checks and starts dialling; a failed check answers 409 preflight_failed.
const campaign = await mv.campaigns.start(process.env.CAMPAIGN_ID!);
console.log(campaign.id, campaign.stats);
```

**Python**

```python title="start_campaign.py"
import os

import requests

API = "https://api.morevoice.ai/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['MOREVOICE_API_KEY']}"}
campaign_id = os.environ["CAMPAIGN_ID"]

# Runs the pre-flight checks and starts dialling; a failed check answers 409 preflight_failed.
response = requests.post(f"{API}/campaigns/{campaign_id}/start", headers=HEADERS, timeout=30)
if response.status_code == 409:
    error = response.json()["error"]
    print(error["code"], error["message"], error.get("details"))
else:
    response.raise_for_status()
    print(response.json()["id"], "started")
```

If a check fails, nothing starts: the request answers `409` with the code `preflight_failed`, and `details.preflight` lists the `errors` to fix (no assistant, no contacts, no recorded consent, no registry for a marketing campaign…), `warnings` (contacts that will be skipped), how many contacts are `dialable`, and whether a calling window is open now. `GET /v1/campaigns/{id}/preflight` runs the same checks without starting. To start later, send `start_at` with the start and the campaign waits in `scheduled`.

Once running, the dialer checks each contact again just before calling it: the do-not-call list, consent, the national registry, calling hours and Shabbat. A marketing campaign that can't reach the national registry pauses itself and says why in `pause_reason`.

## Pause, resume and cancel

**cURL**

```sh
# Stop dialling new calls; calls in progress finish.
curl -X POST https://api.morevoice.ai/v1/campaigns/$CAMPAIGN_ID/pause \
  -H "Authorization: Bearer $MOREVOICE_API_KEY"

# Later: run the pre-flight checks again and carry on.
curl -X POST https://api.morevoice.ai/v1/campaigns/$CAMPAIGN_ID/resume \
  -H "Authorization: Bearer $MOREVOICE_API_KEY"
```

**Node.js**

```ts title="pause-resume.ts"
import MoreVoice from "@morevoice/sdk";

const mv = new MoreVoice(); // reads MOREVOICE_API_KEY
const campaignId = process.env.CAMPAIGN_ID!;

// Stop dialling new calls; calls in progress finish.
await mv.campaigns.pause(campaignId);

// Later: run the pre-flight checks again and carry on.
await mv.campaigns.resume(campaignId);
```

**Python**

```python title="pause_resume.py"
import os

import requests

API = "https://api.morevoice.ai/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['MOREVOICE_API_KEY']}"}
campaign_id = os.environ["CAMPAIGN_ID"]

# Stop dialling new calls; calls in progress finish.
requests.post(f"{API}/campaigns/{campaign_id}/pause", headers=HEADERS, timeout=30).raise_for_status()

# Later: run the pre-flight checks again and carry on.
requests.post(f"{API}/campaigns/{campaign_id}/resume", headers=HEADERS, timeout=30).raise_for_status()
```

`pause` stops new calls and lets calls in progress finish. `resume` runs the pre-flight checks again and carries on. `cancel` stops the campaign for good: calls not yet answered are hung up, and contacts not yet dialled are cancelled.

## Follow the results

The campaign object carries `stats`: contacts per status, how many will not be dialled again (`finished`), and the calls in progress now. List the contacts by status to see where each one stands:

**cURL**

```sh
# Contacts still waiting to be called.
curl "https://api.morevoice.ai/v1/campaigns/$CAMPAIGN_ID/contacts?status=pending&limit=50" \
  -H "Authorization: Bearer $MOREVOICE_API_KEY"
```

**Node.js**

```ts title="list-contacts.ts"
import MoreVoice from "@morevoice/sdk";

const mv = new MoreVoice(); // reads MOREVOICE_API_KEY

// Contacts still waiting to be called.
for await (const contact of mv.campaigns.contacts.list(process.env.CAMPAIGN_ID!, { status: "pending", limit: 50 })) {
	console.log(contact.phone, contact.name, contact.attempts);
}
```

**Python**

```python title="list_contacts.py"
import os

import requests

API = "https://api.morevoice.ai/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['MOREVOICE_API_KEY']}"}
campaign_id = os.environ["CAMPAIGN_ID"]

# Contacts still waiting to be called.
response = requests.get(
    f"{API}/campaigns/{campaign_id}/contacts",
    headers=HEADERS,
    params={"status": "pending", "limit": 50},
    timeout=30,
)
response.raise_for_status()
for contact in response.json()["data"]:
    print(contact["phone"], contact["name"], contact["attempts"])
```

| Contact `status` | Meaning |
| --- | --- |
| `pending` | Waiting for its first call. |
| `scheduled` | Due again later: a retry, or requeued. |
| `callback` | The person asked to be called back. |
| `dialing` | Being called now. |
| `done` | Reached; `outcome` holds the disposition the assistant recorded. |
| `failed` | Not reached after every attempt. |
| `dnc`, `skipped`, `invalid`, `cancelled` | Never dialled; `skip_reason` says why (do-not-call, no consent, outside every window, skipped by hand…). |

`GET /v1/campaigns/{id}/stats` adds attempts by result, recorded outcomes and compliance skips, and `GET /v1/campaigns/{id}/export` downloads the contacts or the attempts as a CSV that opens in Excel with Hebrew intact. Webhooks follow the campaign as it runs: `campaign.started`, `campaign.paused`, `campaign.completed`, `contact.attempted`, `contact.completed` and the call events of each call; see the [event catalogue](https://docs.morevoice.ai/webhooks/events/#campaigns). [`campaign.blocked`](https://docs.morevoice.ai/webhooks/events/#campaign.blocked) tells you when a running campaign can't dial right now: outside its calling window, on Shabbat or a holiday, or stopped by a compliance gate.

### Requeue or skip a contact

Each contact keeps its dial attempts: when, the `result` (`answered`, `no_answer`, `busy`, `voicemail`…) and the call's `end_reason`. To try someone again now, set the contact's `status` to `scheduled`; to take them out of the campaign, `skipped`, as the dashboard's contact actions do:

**cURL**

```sh
# Why wasn't this contact reached? Its dial attempts, then dial it again now.
curl https://api.morevoice.ai/v1/campaigns/$CAMPAIGN_ID/contacts/$CONTACT_ID/attempts \
  -H "Authorization: Bearer $MOREVOICE_API_KEY"

curl -X PATCH https://api.morevoice.ai/v1/campaigns/$CAMPAIGN_ID/contacts/$CONTACT_ID \
  -H "Authorization: Bearer $MOREVOICE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "status": "scheduled" }'
```

**Node.js**

```ts title="requeue-contact.ts"
import MoreVoice from "@morevoice/sdk";

const mv = new MoreVoice(); // reads MOREVOICE_API_KEY
const campaignId = process.env.CAMPAIGN_ID!;
const contactId = process.env.CONTACT_ID!;

// Why wasn't this contact reached? Its dial attempts, then dial it again now.
for await (const attempt of mv.campaigns.contacts.listAttempts(campaignId, contactId)) {
	console.log(attempt.attempt_number, attempt.started_at, attempt.result, attempt.end_reason);
}
const contact = await mv.campaigns.contacts.update(campaignId, contactId, { status: "scheduled" });
console.log(contact.status);
```

**Python**

```python title="requeue_contact.py"
import os

import requests

API = "https://api.morevoice.ai/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['MOREVOICE_API_KEY']}"}
campaign_id = os.environ["CAMPAIGN_ID"]
contact_id = os.environ["CONTACT_ID"]

# Why wasn't this contact reached? Its dial attempts, then dial it again now.
response = requests.get(f"{API}/campaigns/{campaign_id}/contacts/{contact_id}/attempts", headers=HEADERS, timeout=30)
response.raise_for_status()
for attempt in response.json()["data"]:
    print(attempt["attempt_number"], attempt["started_at"], attempt["result"], attempt["end_reason"])

response = requests.patch(
    f"{API}/campaigns/{campaign_id}/contacts/{contact_id}",
    headers=HEADERS,
    json={"status": "scheduled"},
    timeout=30,
)
response.raise_for_status()
print(response.json()["status"])
```

A number on the do-not-call list can't be requeued, and a contact being dialled can't change. A requeued contact still waits for an open calling window and passes the compliance checks again before the call.

## Test mode

Campaigns created with a test key are test objects: they never reach a phone network, and their calls are dialled by the virtual carrier. Calling windows, Shabbat, retries, outcomes and webhooks work exactly as in live mode, and the [test numbers](https://docs.morevoice.ai/get-started/quickstart/#test-numbers) behave the same in a list: `+972500000002` is busy and is retried by your retry policy, `+972500000004` is skipped as do-not-call.

A test campaign needs no SIP connection, and its pre-flight doesn't require recorded consent or the national do-not-call registry, because no real person can be called: the pre-flight lists them as warnings instead. Contacts on your own do-not-call list are still skipped. Test calls count against your plan's test-mode limits (calls per day, calls at once), not against billing.

> **Tip:** Before a big campaign, run the same settings on a small list of your own team's numbers with a live key. You'll hear the disclosure, the first message and the pacing exactly as your customers will.
