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

# Initiate Call(s)

> Initiate AI agent calls for customers in a campaign with optional filters to target specific subsets.

### Headers

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

### Path Parameters

<ParamField path="campaignId" type="string" required>
  The campaign ID containing the customers to call.
</ParamField>

### Body Parameters

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

<ParamField body="limit" type="integer">
  Maximum number of customers to call. If omitted, all matching customers are called.
</ParamField>

<ParamField body="filters" type="object">
  Optional filters to target specific customers. If omitted, all customers in the campaign are called. Multiple filters are combined with **AND** logic.

  <Expandable title="filter properties">
    <ParamField body="ids" type="string[]">
      Call only these specific customer IDs (`loan_id` or `lead_id`).
    </ParamField>

    <ParamField body="exclude_ids" type="string[]">
      Exclude these customer IDs from calling.
    </ParamField>

    <ParamField body="payment_status" type="string[]">
      Filter by payment status. Accepts a single value or an array.

      <Expandable title="options">
        * `bounced` — Payment was attempted but failed.
        * `pending` — Payment is due but not yet initiated.
        * `partial` — Customer has made a partial payment.
        * `paid` — Payment has been completed.
        * `received` — Payment has been received and confirmed.
      </Expandable>
    </ParamField>

    <ParamField body="language" type="string[]">
      Filter by customer language preference. Accepts a single value or an array (e.g., `"hindi"` or `["hindi", "english"]`).
    </ParamField>

    <ParamField body="custom" type="object">
      Custom field exact-match filters as key-value pairs. Values can be a single string or an array of strings.

      ```json Example theme={null}
            {
              "branch": "mumbai",
              "product_type": ["personal_loan", "home_loan"]
            }
      ```
    </ParamField>
  </Expandable>
</ParamField>

### Response

<ResponseField name="success" type="boolean">
  `true` if all calls were initiated successfully, `false` otherwise.
</ResponseField>

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

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

  <Expandable title="properties">
    <ResponseField name="totalMatched" type="integer">Total customers matching the query/filters in the campaign.</ResponseField>
    <ResponseField name="customersSelected" type="integer">Customers selected for calling (respects `limit` if provided).</ResponseField>
    <ResponseField name="initiated" type="integer">Calls successfully initiated.</ResponseField>
    <ResponseField name="failed" type="integer">Calls that failed to initiate.</ResponseField>
    <ResponseField name="batchesProcessed" type="integer">Number of call batches processed (500 customers per batch).</ResponseField>

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

      <Expandable title="error object">
        <ResponseField name="batch" type="integer">Batch number that failed.</ResponseField>
        <ResponseField name="error" type="string">Error type.</ResponseField>
        <ResponseField name="reason" type="string">Human-readable error reason.</ResponseField>
        <ResponseField name="affectedCustomers" type="integer">Number of customers affected in the failed batch.</ResponseField>
      </Expandable>
    </ResponseField>
  </Expandable>
</ResponseField>

<Note>
  **Response Status Codes:**

  * `200` — All calls initiated successfully
  * `207` — Partial success (some calls initiated, some failed)
  * `400` — Validation error, no active numbers, or missing agent variables
  * `404` — Campaign, agent, or customers not found
  * `500` — All calls failed or internal server error
</Note>

<ResponseExample>
  ```json 200 All Calls Initiated theme={null}
  {
    "success": true,
    "message": "Calls initiated for 250 customers",
    "results": {
      "totalMatched": 500,
      "customersSelected": 250,
      "initiated": 250,
      "failed": 0,
      "batchesProcessed": 1,
      "errors": []
    }
  }
  ```

  ```json 207 Partial Success theme={null}
  {
    "success": false,
    "message": "Calls initiated for 200 of 250 customers",
    "results": {
      "totalMatched": 500,
      "customersSelected": 250,
      "initiated": 200,
      "failed": 50,
      "batchesProcessed": 1,
      "errors": [
        {
          "batch": 1,
          "error": "Call initiation failed",
          "reason": "Workflow runner timeout",
          "affectedCustomers": 50
        }
      ]
    }
  }
  ```

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

  ```json 400 No Active Numbers theme={null}
  {
    "success": false,
    "message": "No active numbers available for this organization"
  }
  ```

  ```json 400 Missing Agent Variables theme={null}
  {
    "success": false,
    "message": "Cannot initiate calls: Missing variables: emi_due_date, loan_amount",
    "totalMatched": 250,
    "customersSelected": 250
  }
  ```

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

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

  ```json 404 No Customers Found theme={null}
  {
    "success": false,
    "message": "No customers found matching the given filters"
  }
  ```

  ```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>

### Usage Examples

**Call all customers in a campaign:**

```json theme={null}
{
  "agentId": "agent_abc123",
  "dispositionId": "disp_xyz789"
}
```

**Call only bounced and pending customers:**

```json theme={null}
{
  "agentId": "agent_abc123",
  "dispositionId": "disp_xyz789",
  "filters": {
    "payment_status": ["bounced", "pending"]
  }
}
```

**Call customers with EMI due this month, limited to 100:**

```json theme={null}
{
  "agentId": "agent_abc123",
  "dispositionId": "disp_xyz789",
  "limit": 100,
  "filters": {
    "emi_due_date": {
      "from": "2025-08-01",
      "to": "2025-08-31"
    },
    "payment_status": "pending"
  }
}
```

**Call specific customers by ID:**

```json theme={null}
{
  "agentId": "agent_abc123",
  "dispositionId": "disp_xyz789",
  "filters": {
    "ids": ["LOAN-2025-00123", "LOAN-2025-00456", "LOAN-2025-00789"]
  }
}
```

**Call with custom field filters:**

```json theme={null}
{
  "agentId": "agent_abc123",
  "dispositionId": "disp_xyz789",
  "filters": {
    "payment_status": ["bounced", "pending"],
    "emi_amount": {
      "min": 5000,
      "max": 20000
    },
    "language": "hindi",
    "custom": {
      "branch": "mumbai",
      "product_type": ["personal_loan", "home_loan"]
    }
  }
}
```

**Call all customers except specific ones:**

```json theme={null}
{
  "agentId": "agent_abc123",
  "dispositionId": "disp_xyz789",
  "filters": {
    "exclude_ids": ["LOAN-2025-00789", "LOAN-2025-00999"]
  }
}
```
