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

> Initiate SMS messages 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 message.
</ParamField>

### Body Parameters

<ParamField body="templateId" type="string" required>
  The ID of the SMS template to be sent.
</ParamField>

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

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

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

    <ParamField body="exclude_ids" type="string[]">
      Exclude these customer IDs from messaging.
    </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 messages 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 message 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 messaging (respects `limit` if provided).</ResponseField>
    <ResponseField name="initiated" type="integer">Messages successfully initiated.</ResponseField>
    <ResponseField name="failed" type="integer">Messages that failed to initiate.</ResponseField>
    <ResponseField name="batchesProcessed" type="integer">Number of message batches processed.</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 messages initiated successfully
  * `207` — Partial success (some messages initiated, some failed)
  * `400` — Validation error
  * `404` — Campaign or customers not found
  * `500` — All messages failed or internal server error
</Note>

<ResponseExample>
  ```json 200 All Messages Initiated theme={null}
  {
    "success": true,
    "message": "SMS messages 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": "SMS messages initiated for 200 of 250 customers",
    "results": {
      "totalMatched": 500,
      "customersSelected": 250,
      "initiated": 200,
      "failed": 50,
      "batchesProcessed": 1,
      "errors": [
        {
          "batch": 1,
          "error": "Initiation failed",
          "reason": "Workflow runner timeout",
          "affectedCustomers": 50
        }
      ]
    }
  }
  ```

  ```json 400 Validation Error theme={null}
  {
    "success": false,
    "message": "Validation failed",
    "errors": [
      "templateId is required"
    ]
  }
  ```

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

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

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

### Usage Examples

**Message all customers in a campaign:**

```json theme={null}
{
  "templateId": "hfu7VL6sBhI6NPm"
}
```

**Message specific customers:**

```json theme={null}
{
  "templateId": "hfu7VL6sBhI6NPm",
  "filters": {
    "ids": ["LOANID-2043153", "LOANID-2043154"]
  }
}
```

**Message bounced and pending customers:**

```json theme={null}
{
  "templateId": "hfu7VL6sBhI6NPm",
  "filters": {
    "payment_status": ["bounced", "pending"]
  }
}
```

**Message all customers except specific ones:**

```json theme={null}
{
  "templateId": "hfu7VL6sBhI6NPm",
  "filters": {
    "exclude_ids": ["LOANID-2043153", "LOANID-2043154"]
  }
}
```
