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

# Manage Templates

> List, query, and sync WhatsApp Business templates

## List Templates

```bash theme={null}
GET /backend/templates
```

### Filters (Query Parameters)

| Parameter        | Type   | Description                                                   |
| ---------------- | ------ | ------------------------------------------------------------- |
| `gupshup_app_id` | string | Filter by Gupshup app                                         |
| `status`         | string | Filter by status (`APPROVED`, `PENDING`, `REJECTED`)          |
| `category`       | string | Filter by category (`MARKETING`, `UTILITY`, `AUTHENTICATION`) |
| `language`       | string | Filter by language (e.g., `pt_BR`, `en`)                      |

### Example

<CodeGroup>
  ```bash cURL theme={null}
  curl -X GET "https://api.leavo.ai/backend/templates?status=APPROVED&language=en" \
    -H "Authorization: Bearer your_api_key_here"
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch(
    'https://api.leavo.ai/backend/templates?status=APPROVED&language=en',
    {
      headers: { 'Authorization': 'Bearer your_api_key_here' }
    }
  );
  const templates = await response.json();
  ```
</CodeGroup>

**Response (200):**

```json theme={null}
[
  {
    "id": "uuid",
    "tenant_id": "uuid",
    "gupshup_app_id": "app_12345",
    "template_name": "welcome_v1",
    "template_id": "gupshup_id",
    "language": "en",
    "status": "APPROVED",
    "category": "MARKETING",
    "components": [...],
    "last_synced_at": "2024-01-15T10:00:00Z"
  }
]
```

## Get Template

```bash theme={null}
GET /backend/templates/{id}
```

Returns complete template details including all components.

## Delete Template

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

<Warning>
  Deleting a template automatically removes all cadence associations.
</Warning>

**Response:** 204 No Content

## Sync Templates

```bash theme={null}
POST /backend/templates/sync
```

Endpoint called by meta-service to sync templates from Gupshup.

**Body:**

```json theme={null}
{
  "app_id": "app_12345",
  "templates": [
    {
      "id": "gupshup_template_id",
      "name": "welcome_v1",
      "language": "en",
      "status": "APPROVED",
      "category": "MARKETING",
      "components": [
        {
          "type": "BODY",
          "text": "Hello {{1}}, welcome to {{2}}!"
        }
      ]
    }
  ]
}
```

**Response (200):**

```json theme={null}
{
  "synced_count": 5,
  "app_id": "app_12345"
}
```

<Note>
  Existing templates are updated (upsert). New templates are created automatically. The uniqueness key is `(tenant_id, gupshup_app_id, template_name, language)`.
</Note>
