# Import a contact list in the background

`POST https://api.morevoice.ai/v1/campaigns/{id}/contacts/import`

Imports a CSV or XLSX list in the background through the dashboard's import path and answers 202 with the import; poll GET /v1/imports/{id} until it succeeds or fails. Send the file as multipart/form-data (a `file` part plus the options as text fields, `mapping` as a JSON string), or as JSON: CSV text, a base64 file, or an https URL to download. An Idempotency-Key is required, so a retried upload never imports twice.

Authenticate with a secret API key: `Authorization: Bearer $MOREVOICE_API_KEY`.

Operation ID: `campaigns_contacts_import`.

## Parameters

### Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | `string` | yes | A campaign ID (`cmp_…`). |

### Headers

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `MoreVoice-Version` | `string` | no | The API version to use for this request. Defaults to the version the API key is pinned to. |
| `Idempotency-Key` | `string` | no | A unique key (for example a UUID) that makes this request safe to retry: for 24 hours, a retry with the same key and parameters returns the first response instead of acting twice. |

## Request body

Required, `application/json` or `multipart/form-data`.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `consent_channel` | `"web" \| "phone" \| "sms" \| "email" \| "whatsapp" \| "app" \| "written" \| "in_person" \| …` | no | How every consenting row consented, when the file has no channel column. |
| `consent_source` | `string` | no | Where every consenting row consented, when the file has no source column. |
| `csv` | `string` | no | The list as CSV text (UTF-8; comma, semicolon, tab or pipe separated). |
| `default_country` | `string` | no | Country of numbers written without a country code (ISO 3166-1 alpha-2, default IL). |
| `drop_dnc` | `boolean` | no | Leave do-not-call numbers out entirely (default false: kept with status dnc, never dialled). |
| `file` | `object` | no | A CSV or XLSX file. |
| `file.filename` | `string` | yes | Its name; .xlsx is read as a spreadsheet, anything else as CSV. |
| `file.content_base64` | `string` | yes | The file, base64-encoded (≤ 10 MB decoded). |
| `has_header` | `boolean` | no | The first row holds column names (default: detected). |
| `mapping` | `ImportMappingInput` | no | Which column holds what: contact field → header name (or 0-based index). Any other key names a {{variable}}. Omit the mapping to detect the columns like the dashboard does. |
| `mapping.phone` | `string \| integer` | yes | A header name, or a 0-based column index. |
| `mapping.consent` | `string \| integer \| null` | no | Yes / no: the person consented to marketing calls (needs the evidence columns or defaults). |
| `mapping.consent_at` | `string \| integer \| null` | no | When they consented. |
| `mapping.consent_channel` | `string \| integer \| null` | no | How they consented. |
| `mapping.consent_source` | `string \| integer \| null` | no | Where they consented. |
| `mapping.name` | `string \| integer \| null` | no | — |
| `mapping.timezone` | `string \| integer \| null` | no | — |
| `mapping.variables` | `Record<string, string \| integer>` | no | {{variable}} name → column (or name them at the top level, as {"plan": "Plan"}). |
| `url` | `string` | no | An https URL to download the CSV / XLSX from (public addresses only, ≤ 10 MB). |

Example:

```json
{
  "csv": "Mobile,Name,Plan\n0501234567,Dana Levi,Gold\n0527654321,Yossi Cohen,Silver\n",
  "default_country": "IL",
  "mapping": {
    "name": "Name",
    "phone": "Mobile",
    "variables": {
      "plan": "Plan"
    }
  }
}
```

## Responses

### 202 Accepted

Accepted: the import runs in the background. Returns `ContactImport`.

| Field | Type | Description |
| --- | --- | --- |
| `id` | `string` | A import ID (prefix `imp_`). |
| `object` | `"import"` | — |
| `livemode` | `boolean` | `true` in live mode, `false` in test mode. |
| `campaign_id` | `string` | A campaign ID (prefix `cmp_`). |
| `status` | `"pending" \| "processing" \| "succeeded" \| "failed"` | pending → processing → succeeded \| failed. Poll GET /v1/imports/{id}. |
| `source` | `"csv" \| "xlsx" \| "url"` | — |
| `filename` | `string \| null` | — |
| `received` | `integer` | Non-empty contacts / rows received. |
| `imported` | `integer` | Contacts added to the campaign for dialling. |
| `rejected` | `integer` | Contacts not added for dialling (invalid, duplicate, do-not-call). |
| `rejected_reasons` | `ContactRejectedReasons` | Rejected contacts per reason. |
| `rejected_reasons.invalid` | `integer` | Not a valid phone number. |
| `rejected_reasons.duplicate` | `integer` | Repeated in the request, or already in the campaign. |
| `rejected_reasons.dnc` | `integer` | On the organisation's do-not-call list. |
| `without_consent` | `integer` | Marketing: contacts added without a consent record. The dialer skips them (§30A) unless consent is recorded first. |
| `consent_recorded` | `integer` | Consent records created from the evidence sent. |
| `errors` | `object[]` | Rejected rows (the first 100). |
| `warnings` | `object[]` | Rows added with a problem (the first 100). |
| `error` | `object \| null` | Why the import failed (status failed): a stable code and a message to show. |
| `error.code` | `string` | — |
| `error.message` | `string` | — |
| `created_at` | `string` | An ISO-8601 timestamp in UTC. |
| `started_at` | `string \| null` | — |
| `completed_at` | `string \| null` | — |

Example:

```json
{
  "campaign_id": "cmp_2Yb7mCq9aPLk",
  "completed_at": "2026-11-02T07:00:03.870Z",
  "consent_recorded": 0,
  "created_at": "2026-11-02T07:00:00.000Z",
  "error": null,
  "errors": [
    {
      "message": "too-short",
      "phone": "05012",
      "reason": "invalid",
      "row": 17
    }
  ],
  "filename": "contacts.csv",
  "id": "imp_7RkXq2Lm9PvTz4nB1c8Ya",
  "imported": 4890,
  "livemode": true,
  "object": "import",
  "received": 5000,
  "rejected": 110,
  "rejected_reasons": {
    "dnc": 20,
    "duplicate": 40,
    "invalid": 50
  },
  "source": "csv",
  "started_at": "2026-11-02T07:00:00.120Z",
  "status": "succeeded",
  "warnings": [],
  "without_consent": 0
}
```

### 400 Bad Request

The request is invalid: a parameter is missing, malformed or unknown, or the version header is unknown. Returns `ErrorEnvelope`.

### 401 Unauthorized

No valid API key was sent. Returns `ErrorEnvelope`.

### 403 Forbidden

The key may not do this (a missing scope, a plan limit, or a compliance block). Returns `ErrorEnvelope`.

### 404 Not Found

No object with this ID (in the path or the body) exists in this organisation and mode. Returns `ErrorEnvelope`.

### 409 Conflict

The request conflicts with the object's state, or the Idempotency-Key was reused with other parameters. Returns `ErrorEnvelope`.

### 413 Payload Too Large

The request body is larger than the endpoint accepts, or has more parts or files than it takes. Returns `ErrorEnvelope`.

### 415 Unsupported Media Type

The request body's Content-Type is not one the endpoint takes. Returns `ErrorEnvelope`.

### 429 Too Many Requests

Too many requests, or no call capacity right now. Retry after the Retry-After delay. Returns `ErrorEnvelope`.

### 500 Internal Server Error

Something went wrong on MoreVoice's side. Retry with the same Idempotency-Key. Returns `ErrorEnvelope`.

## Code samples

**TypeScript**

```ts
import MoreVoice from "@morevoice/sdk";

const mv = new MoreVoice(); // MOREVOICE_API_KEY from the environment

const contactImport = await mv.campaigns.contacts.import("cmp_7Hk2Lm9Qp", {
	csv: "Mobile,Name,Plan\n0501234567,Dana Levi,Gold\n0527654321,Yossi Cohen,Silver\n",
	default_country: "IL",
	mapping: {
		name: "Name",
		phone: "Mobile",
		variables: {
			plan: "Plan",
		},
	},
});
console.log(contactImport);
```

**Python**

```python
from morevoice import MoreVoice

client = MoreVoice()  # MOREVOICE_API_KEY from the environment

contact_import = client.campaigns.contacts.import_("cmp_7Hk2Lm9Qp", {
    "csv": "Mobile,Name,Plan\n0501234567,Dana Levi,Gold\n0527654321,Yossi Cohen,Silver\n",
    "default_country": "IL",
    "mapping": {
        "name": "Name",
        "phone": "Mobile",
        "variables": {
            "plan": "Plan",
        },
    },
})
print(contact_import)
```

**cURL**

```sh
curl -X POST https://api.morevoice.ai/v1/campaigns/cmp_7Hk2Lm9Qp/contacts/import \
  -H "Authorization: Bearer $MOREVOICE_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{
  "csv": "Mobile,Name,Plan\n0501234567,Dana Levi,Gold\n0527654321,Yossi Cohen,Silver\n",
  "default_country": "IL",
  "mapping": {
    "name": "Name",
    "phone": "Mobile",
    "variables": {
      "plan": "Plan"
    }
  }
}'
```
