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

# Add Calls to Campaign

> Add contacts to an existing outbound or mixed campaign as JSON.

## Overview

Add contacts to an existing campaign. Each contact needs a `phoneNumber`; any other fields are stored with the contact and passed to the agent as variables.

Contacts are queued for calling straight away and are called during the campaign's calling hours. You don't need to call **Start Campaign** afterwards. A `completed` campaign is moved back to `pending` so the new contacts get called.

## Prerequisites

* An outbound or mixed campaign and its `batchId`, created by the user who owns the API key. Contacts can't be added to `inbound` campaigns.
* The campaign's calling numbers have an outbound agent assigned.

## Request

**x-api-key** `string` *required*

Your workspace API key. Create one from the profile menu in the dashboard → **API Keys**.

**batchId** `string` *required*

ID of the campaign, from [Create Campaign](https://docs.weya.ai/api-reference/Campaigns/createBatch.md) or [Get Campaigns](https://docs.weya.ai/api-reference/Campaigns/getBatch.md).

**callData** `array[object]` *required*

Contacts to add, up to 10,000 per request. Each object must include `phoneNumber` in E.164 format, for example `+919876543210`. Other fields are stored with the contact.

* `timezone` – optional per-contact timezone. Defaults to the campaign's timezone.
* Agent variables you leave out are stored as `null`. They are not rejected.
* These field names are reserved and rejected: `call_status`, `retry_count`, `call_duration`, `insertuuid`, `_id`, `x_weya_transliterated_name`, `x_weya_transliterated_language`.

```bash cURL theme={null}
curl -X POST 'https://api.weya.live/backend/api/call/addCallsToBatch' \
  -H "Content-Type: application/json" \
  -H "x-api-key: YOUR_API_KEY" \
  -d '{
    "batchId": "64e5f12345abcdef98765432",
    "callData": [
      {
        "phoneNumber": "+918800000000",
        "name": "Asha Rao",
        "amount": "500.00"
      },
      {
        "phoneNumber": "+919900000000",
        "name": "Test User",
        "amount": "100.00"
      }
    ]
  }'
```

## Response

This endpoint returns a summary object, not the standard `status`/`data` wrapper. Errors use the standard wrapper (see below).

```json 200 OK theme={null}
{
  "success": true,
  "added": 2,
  "callIds": ["2f6c1a3e-6b1d-4c52-9f0a-3a7d2e9b8c11", "8a1d0c55-1e2f-4b8a-a0c3-5d6e7f8a9b10"],
  "summary": {
    "totalChunks": 1,
    "successfulChunks": 1,
    "failedChunks": 0,
    "skippedRows": 0
  },
  "message": "All calls processed successfully"
}
```

```json 207 Multi-Status theme={null}
{
  "success": false,
  "added": 1000,
  "callIds": ["2f6c1a3e-6b1d-4c52-9f0a-3a7d2e9b8c11"],
  "summary": {
    "totalChunks": 2,
    "successfulChunks": 1,
    "failedChunks": 1,
    "skippedRows": 0
  },
  "partial": true,
  "message": "Partial success: Some chunks failed",
  "failedChunks": [
    { "chunkNum": 2, "error": "..." }
  ]
}
```

**success** `boolean` *required*

`true` when every chunk was saved.

**added** `integer` *required*

Number of new contacts added. Contacts whose phone number is already in the campaign are updated instead and aren't counted.

**callIds** `array[string]` *required*

IDs of the contacts added or updated by this request. All of them are queued for calling.

**summary** `object` *required*

Contacts are saved in chunks of 1,000: `totalChunks`, `successfulChunks`, `failedChunks` (a count) and `skippedRows` (rows skipped because the phone number was invalid).

**message** `string` *required*

`All calls processed successfully`, `Calls saved but with warnings` (some rows were skipped), or `Partial success: Some chunks failed`.

**partial** `boolean`

`true` when some chunks failed. The HTTP status is then `207`.

**failedChunks** `array[object]`

Present when chunks failed: each `{ chunkNum, error }`. Send the contacts of those chunks again.

**warnings.invalidRows** `array[object]`

Present when rows were skipped: each `{ rowNumber, phoneNumber, error }`. `rowNumber` is the 1-based position in `callData`.

## Error Handling

Errors return `status: false`, with the reason in `errorMessage`.

* **400 Bad Request**
  * `Valid callData is required` – `callData` is missing or empty.
  * `Upload exceeds the maximum of 10,000 rows…` – split the contacts into several requests.
  * `Call data contains restricted headers: …` – a contact uses a reserved field name.
  * `No valid phone numbers in callData…` – every phone number was invalid.
  * `Cannot add lead data to an inbound batch`.
  * `Batch has no calling numbers`.
* **401 Unauthorized** – Missing or invalid API key.
* **403 Forbidden** – `Batch not found or not authorized for this user`: the campaign doesn't exist, was deleted, or wasn't created by the user who owns the API key.
* **404 Not Found** – `Agent not found for the provided calling numbers`: no calling number has an outbound agent.
* **500 Internal Server Error** – Unexpected server error.

> [!NOTE]
>
> **Duplicates:**
>
> * When the same phone number appears more than once in `callData`, only the first is kept.
> * When a phone number is already in the campaign, that contact's data is replaced with the new values and it becomes callable again: its retry counter is reset to 0 and it is no longer expired. Its earlier call history is kept.


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