> ## 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.

# Upload Campaign CSV

> Create a campaign and populate it by uploading a CSV file of contacts.

## Overview

Create a campaign and add its contacts from a CSV or Excel file in one request. The file is validated, the campaign is created, and each row becomes a contact. Calling starts when you call [Start Campaign](https://docs.weya.ai/api-reference/Campaigns/startCalling.md).

An `inbound` campaign takes no file: it only links the calling numbers to the new campaign so incoming calls are recorded on it.

## Prerequisites

* An API key for your workspace
* A CSV or Excel file with a `phoneNumber` column and any variables the agent needs (not needed for `inbound`).
* At least one phone number with an outbound agent assigned. All numbers must use agents of the same conversation type.

## Request

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

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

CSV (`.csv`) or Excel (`.xls`, `.xlsx`) file of contacts, with a header row. Required unless `batchType` is `inbound`.

Display name for the new campaign.

JSON stringified array of phone number IDs, from [Get Phone Numbers](https://docs.weya.ai/api-reference/PhoneNumbers/getPhoneNumbers.md). At least one. Example: `"[\"64e5f12345abcdef87654321\"]"`.

Type of campaign: `outbound` for outbound-only campaigns, `mixed` for outbound campaigns that also accept callbacks, or `inbound` for campaigns that only receive calls (no CSV needed).

The campaign's DNC setting, `"true"` or `"false"`. `"true"` is allowed only when DNC is enabled for your organization. Numbers on your organization's [DNC list](https://docs.weya.ai/api-reference/DNC/getDNCList.md) are skipped in every campaign whatever this value is.

Set to `"true"` to skip invalid rows and upload only the valid ones. Default is `"false"`, which rejects the upload if any row is invalid.

JSON stringified array of variables every row must have a value for. Example: `"[\"customer_name\"]"`.

Maximum attempts per contact. Use a value from 1 to 10, the range the dashboard allows. The API does not check the range.

Time to wait between attempts to the same contact, in **minutes**. Use a value from 5 to 1440, the range the dashboard allows. The API does not check the range.

Timezone for the campaign (e.g., "America/New\_York", "Asia/Kolkata").

JSON stringified daily calling window, with `start` and `end` in 24-hour `HH:MM` format. Required unless `batchType` is `inbound`. Example: `"{\"start\":\"09:00\",\"end\":\"17:00\"}"`.

JSON stringified array of day names. Example: `"[\"Monday\",\"Tuesday\",\"Wednesday\",\"Thursday\",\"Friday\"]"`.

Optional date and time (ISO 8601) to start calling. Leave out to start straight away.

ID of a holiday list in your organization. No calls are placed on the dates in that list.

JSON stringified array of destinations to send call outcomes to. Each item has `type` (`standard`, `custom`, `webhook` or `gsheet`), `schemaId` and `crmId`. For `custom` and `gsheet`, `crmId` is set to `schemaId`. At most one Google Sheet per campaign. Example: `"[]"`.

`inbound` campaigns only. Set to `"true"` to move calling numbers that are already active on another inbound campaign to this one. See the `409` error below.

```bash cURL theme={null}
curl --location 'https://api.weya.live/backend/api/call/upload' \
  --header 'x-api-key: YOUR_API_KEY' \
  --form 'file=@"/path/to/contacts.csv"' \
  --form 'batchName="Marketing Campaign May 2025"' \
  --form 'batchType="outbound"' \
  --form 'callingNumbers="[\"64e5f12345abcdef87654321\"]"' \
  --form 'enableDNC="true"' \
  --form 'timezone="America/New_York"' \
  --form 'callingHour="{\"start\":\"09:00\",\"end\":\"17:00\"}"' \
  --form 'allowedDays="[\"Monday\",\"Tuesday\",\"Wednesday\",\"Thursday\",\"Friday\"]"'
```

> [!NOTE]
>
> **CSV/Excel File Requirements:**
>
> * Supported formats: CSV (.csv) or Excel (.xls, .xlsx)
> * Must include a header row
> * Must include `phoneNumber` column (required)
> * Every row must have a value for each variable listed in `mandatoryVariables`
> * CSV headers should match agent variable keys (e.g., `phoneNumber`, `name`, `account_id`, `custom_field_1`)
> * The `phoneNumber` column is required; all other columns are flexible based on your agent's needs
> * Extra columns are stored and forwarded to the agent state machine
> * File encoding should be UTF-8
> * Empty files or files with no valid rows will be rejected
>
> **File Processing:**
>
> * The system automatically detects file type by extension
> * Excel files use the first sheet
> * Invalid rows are identified and reported (unless `type="true"`)
> * Data is normalized and validated against agent requirements
> * Phone numbers are deduplicated (only the first occurrence is kept)
> * A file with no valid rows is always rejected

## Response

```json 201 Created theme={null}
{
  "message": "Batch created successfully",
  "status": true,
  "code": 201,
  "errorMessage": null,
  "data": {
    "batch": [
      {
        "_id": "64e5f12345abcdef98765432",
        "batchName": "Marketing Campaign May 2025",
        "callingNumbers": ["64e5f12345abcdef87654321"],
        "totalCalls": 100
      }
    ],
    "uuid": "3f6c2a1e-8b4d-4f7a-9c1e-2d5b7a9e0f11"
  }
}
```

**data.batch** `array[object]` *required*

The created campaign. The campaign ID is `data.batch[0]._id`.

**data.uuid** `string` *required*

ID of this upload. Pass it as `uuid` to [Start Campaign](https://docs.weya.ai/api-reference/Campaigns/startCalling.md) to start calling these contacts. For `inbound` campaigns there are no contacts to start.

## Error Handling

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

* **400 Bad Request**
  * `Batch name required`, `Invalid batch type`, `callingNumbers required`, `CSV file required` or `Unsupported file type`.
  * `callHours required` or `Invalid callHours format` – `callingHour` is missing or not in `HH:MM` format.
  * `Invalid input format` – `callingHour`, `callingNumbers`, `allowedDays` or `mandatoryVariables` is not valid JSON.
  * `Invalid pushingCrms format`, or a `pushingCrms` entry fails validation.
  * `DNC not enabled for organization`.
  * `Invalid holidayListId` or `Holiday list not found`.
  * `All phoneNumbers must have same agent type` – the numbers' outbound agents have different conversation types.
  * The file is empty or has no valid rows.
* **404 Not Found** – `Phone(s) not found: …` or `No agent linked to phone …`: a calling number doesn't exist or has no outbound agent.
* **400 Bad Request (invalid rows)** – The file has invalid rows and `type` is `"false"`. `data` contains `code: "INVALID_CSV_ROWS"`, `totalInvalidRows`, `validRows`, `truncated` and `invalidRows` (each `{ rowNumber, phoneNumber, reason }`). Fix the rows, or resend with `type="true"` to skip them.
* **401 Unauthorized** – Missing or invalid API key.
* **409 Conflict** – `inbound` campaigns only. A calling number is already active on another inbound campaign. `data.requiresConfirmation` is `true` and `data.conflicts` lists each number as `{ phoneId, phoneNumber, currentBatchId, currentBatchName }`. Resend with `confirmReassign="true"` to move them.
* **500 Internal Server Error** – File parsing failed, database error, or other server errors.

> [!TIP]
>
> Then call `POST /api/call/start-calling` with the campaign ID and `data.uuid` to start calling. Use `GET /api/call/batch-details/{batchId}` to confirm the imported rows match the expected total.


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