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

# Cadence Associations

> Link approved templates to cadence steps

## Overview

Templates can be associated with specific cadence steps to send official WhatsApp Business messages. This is especially useful for re-engaging leads after the 24-hour window.

## Create Association

```bash theme={null}
POST /backend/templates/cadence-associations
```

**Body:**

```json theme={null}
{
  "cadence_id": "uuid",
  "step_index": 0,
  "message_index": 0,
  "template_id": "uuid",
  "parameter_mapping": {
    "1": "{{LEAD_NAME}}",
    "2": "Leavo"
  }
}
```

| Field               | Type    | Required | Description                      |
| ------------------- | ------- | -------- | -------------------------------- |
| `cadence_id`        | UUID    | Yes      | Cadence ID                       |
| `step_index`        | integer | Yes      | Step index in the cadence        |
| `message_index`     | integer | Yes      | Message index in the step        |
| `template_id`       | UUID    | Yes      | Template ID (must be `APPROVED`) |
| `parameter_mapping` | object  | No       | Template parameter mapping       |

<Warning>
  Only templates with `APPROVED` status can be associated with cadences.
</Warning>

**Response (201):**

```json theme={null}
{
  "id": "uuid",
  "tenant_id": "uuid",
  "cadence_id": "uuid",
  "step_index": 0,
  "message_index": 0,
  "template_id": "uuid",
  "parameter_mapping": {
    "1": "{{LEAD_NAME}}",
    "2": "Leavo"
  },
  "template": {
    "id": "uuid",
    "template_name": "welcome_v1",
    "language": "en",
    "status": "APPROVED"
  },
  "created_at": "2024-01-15T10:00:00Z"
}
```

## List Cadence Associations

```bash theme={null}
GET /backend/templates/cadence-associations?cadence_id={cadence_id}
```

## Update Parameter Mapping

```bash theme={null}
PUT /backend/templates/cadence-associations/{id}/params
```

**Body:**

```json theme={null}
{
  "parameter_mapping": {
    "1": "{{LEAD_FIRSTNAME}}",
    "2": "Leavo Team"
  }
}
```

## Remove Association

```bash theme={null}
DELETE /backend/templates/cadence-associations/{id}
```

**Response:** 204 No Content

## Available Variables

Use these variables in `parameter_mapping` to personalize messages:

| Variable             | Description                                           |
| -------------------- | ----------------------------------------------------- |
| `{{LEAD_NAME}}`      | Lead's full name                                      |
| `{{LEAD_FIRSTNAME}}` | Lead's first name                                     |
| `{{LEAD_NUMBER}}`    | Lead's phone number                                   |
| `{{COMPANY_NAME}}`   | Lead's company name                                   |
| `{{LEAD_FIELD_KEY}}` | Custom field value (replace `KEY` with the field key) |
