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

# Bulk Add Customers

> Add multiple customer records to an existing campaign in a single request with optional call initiation.

### Headers

<ParamField header="Authorization" type="string" required>
  Bearer token for authentication (e.g., `Bearer <your_token>`).
</ParamField>

### Body Parameters

<ParamField body="campaignId" type="string" required>
  Target campaign ID. The campaign must already exist.
</ParamField>

<ParamField body="records" type="array" required>
  Array of customer objects. Maximum **10,000** records per request. The required fields depend on your campaign's service type.

  <Tabs>
    <Tab title="Debt Collection">
      **Use this structure if you are managing existing loans.**

      <Expandable title="item properties">
        <ParamField body="loan_id" type="string" required>Unique identifier for the loan record.</ParamField>
        <ParamField body="first_name" type="string" required>Customer's first name.</ParamField>
        <ParamField body="last_name" type="string" required>Customer's last name.</ParamField>
        <ParamField body="phone_number" type="string" required>Customer's primary contact number.</ParamField>
        <ParamField body="loan_amount" type="number" required>Total principal amount of the loan.</ParamField>
        <ParamField body="emi_amount" type="number" required>EMI amount due for the current billing cycle.</ParamField>
        <ParamField body="loan_period" type="number" required>Total loan tenure in monthly installments.</ParamField>
        <ParamField body="current_emi" type="number" required>Current installment number in the repayment schedule (e.g., 5 of 12).</ParamField>
        <ParamField body="emi_due_date" type="string" required>Due date for the current EMI. Format: `YYYY-MM-DD`.</ParamField>

        <ParamField body="payment_status" type="string" required>
          Current status of the customer's EMI payment.

          <Expandable title="options">
            * `bounced` — Payment was attempted but failed (e.g., insufficient funds).
            * `pending` — Payment is due but not yet initiated.
            * `partial` — Customer has made a partial payment.
            * `paid` — Payment has been completed by the customer.
            * `received` — Payment has been received and confirmed.
          </Expandable>
        </ParamField>

        <ParamField body="language" type="string">Preferred language for the AI agent (e.g., `english`, `hindi`, `tamil`).</ParamField>
      </Expandable>
    </Tab>

    <Tab title="Lead Generation">
      **Use this structure for new sales or lead acquisition.**

      <Expandable title="item properties">
        <ParamField body="lead_id" type="string">Unique identifier for the lead. Auto-generated (UUID) if not provided.</ParamField>
        <ParamField body="first_name" type="string" required>Customer's first name.</ParamField>
        <ParamField body="last_name" type="string" required>Customer's last name.</ParamField>
        <ParamField body="phone_number" type="string" required>Customer's primary contact number.</ParamField>
        <ParamField body="lead_date" type="string" required>Date the lead was captured. Format: `YYYY-MM-DD`.</ParamField>
        <ParamField body="language" type="string">Preferred language for the AI agent (e.g., `english`, `hindi`, `tamil`).</ParamField>
      </Expandable>
    </Tab>
  </Tabs>
</ParamField>

<ParamField body="initiateCall" type="boolean" default={false}>
  If `true`, initiates calls for all successfully added customers. Requires `callConfig`. Calls are triggered in batches of 500 after all records are added. Cannot be `true` if `useWorkflow` is `true`.
</ParamField>

<ParamField body="callConfig" type="object">
  Required when `initiateCall` is `true`.

  <Expandable title="properties">
    <ParamField body="agentId" type="string" required>AI agent ID to handle the calls.</ParamField>
    <ParamField body="dispositionId" type="string" required>Disposition ID for call categorization.</ParamField>
  </Expandable>
</ParamField>

<ParamField body="useWorkflow" type="boolean" default={false}>
  If `true`, triggers workflow execution asynchronously for all successfully added customers. Cannot be `true` if `initiateCall` is `true`.
</ParamField>

### Response

<ResponseField name="success" type="boolean">
  `true` if all records were added successfully, `false` if any failed.
</ResponseField>

<ResponseField name="message" type="string">
  Summary of the operation result.
</ResponseField>

<ResponseField name="results" type="object">
  Detailed breakdown of the operation.

  <Expandable title="properties">
    <ResponseField name="total" type="integer">Total records in the request.</ResponseField>
    <ResponseField name="valid" type="integer">Records that passed validation.</ResponseField>
    <ResponseField name="invalid" type="integer">Records that failed validation.</ResponseField>
    <ResponseField name="successful" type="integer">Records successfully added.</ResponseField>
    <ResponseField name="failed" type="integer">Records that failed to add.</ResponseField>
    <ResponseField name="batchesProcessed" type="integer">Number of batches processed.</ResponseField>

    <ResponseField name="errors" type="array">
      Array of error objects for failed records.

      <Expandable title="error object">
        <ResponseField name="id" type="string">The record ID that failed.</ResponseField>
        <ResponseField name="error" type="string">Error type.</ResponseField>
        <ResponseField name="reason" type="string">Human-readable error reason.</ResponseField>
      </Expandable>
    </ResponseField>

    <ResponseField name="invalidRecords" type="array">
      Array of records that failed validation. Only present when there are invalid records.

      <Expandable title="invalid record object">
        <ResponseField name="index" type="integer">Position of the record in the input array.</ResponseField>
        <ResponseField name="id" type="string">The record ID, or `null` if missing.</ResponseField>
        <ResponseField name="errors" type="array">List of validation error messages.</ResponseField>
      </Expandable>
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="callResults" type="object">
  Call initiation results. Only present when `initiateCall` was `true`.

  <Expandable title="properties">
    <ResponseField name="totalRequested" type="integer">Number of customers for whom calls were requested.</ResponseField>
    <ResponseField name="initiated" type="integer">Calls successfully initiated.</ResponseField>
    <ResponseField name="failed" type="integer">Calls that failed to initiate.</ResponseField>
    <ResponseField name="errors" type="array">Array of call initiation errors.</ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="workflowTriggered" type="boolean">
  Whether workflow execution was triggered for successfully added customers. Only present when `useWorkflow` was `true`.
</ResponseField>

<Note>
  **Response Status Codes:**

  * `201` — All records added successfully
  * `207` — Partial success (some added, some failed)
  * `400` — All records failed or validation error
</Note>

<ResponseExample>
  ```json 201 All Added Successfully theme={null}
  {
    "success": true,
    "message": "Added 3 of 3 records",
    "results": {
      "total": 3,
      "valid": 3,
      "invalid": 0,
      "successful": 3,
      "failed": 0,
      "batchesProcessed": 1,
      "errors": []
    }
  }
  ```

  ```json 201 All Added with Calls theme={null}
  {
    "success": true,
    "message": "Added 3 of 3 records | Calls initiated for 3 customers",
    "results": {
      "total": 3,
      "valid": 3,
      "invalid": 0,
      "successful": 3,
      "failed": 0,
      "batchesProcessed": 1,
      "errors": []
    },
    "callResults": {
      "totalRequested": 3,
      "initiated": 3,
      "failed": 0,
      "errors": []
    }
  }
  ```

  ```json 201 All Added with Workflow theme={null}
  {
    "success": true,
    "message": "Added 3 of 3 records | Workflow triggered for 3 customers",
    "results": {
      "total": 3,
      "valid": 3,
      "invalid": 0,
      "successful": 3,
      "failed": 0,
      "batchesProcessed": 1,
      "errors": []
    },
    "workflowTriggered": true
  }
  ```

  ```json 207 Partial Success theme={null}
  {
    "success": false,
    "message": "Added 2 of 3 records",
    "results": {
      "total": 3,
      "valid": 2,
      "invalid": 1,
      "successful": 2,
      "failed": 1,
      "batchesProcessed": 1,
      "errors": [],
      "invalidRecords": [
        {
          "index": 2,
          "id": null,
          "errors": [
            "Record 2: Missing required field 'phone_number'",
            "Record 2: Missing required field 'loan_amount'"
          ]
        }
      ]
    }
  }
  ```

  ```json 400 Validation Error theme={null}
  {
    "success": false,
    "message": "Validation failed",
    "errors": [
      "campaignId is required and must be a string"
    ]
  }
  ```

  ```json 400 No Valid Records theme={null}
  {
    "success": false,
    "message": "No valid records to add",
    "invalidRecords": [
      {
        "index": 0,
        "id": null,
        "errors": [
          "Record 0: Missing required field 'first_name'",
          "Record 0: Missing required field 'phone_number'"
        ]
      }
    ]
  }
  ```

  ```json 404 Campaign Not Found theme={null}
  {
    "success": false,
    "message": "Campaign not found"
  }
  ```

  ```json 403 Forbidden theme={null}
  {
    "success": false,
    "message": "Campaign ID invalid or mismatch for your organization."
  }
  ```

  ```json 500 Server Error theme={null}
  {
    "success": false,
    "error": "Internal Server Error",
    "message": "An unexpected error occurred"
  }
  ```
</ResponseExample>
