# Templates

> Create, submit for approval, sync, and delete WhatsApp message templates via the WAFlow Public API.

Source: https://edesy.in/docs/waflow/api/templates

Templates are pre‑approved message formats required to start conversations with customers. This API creates a template locally and submits it to Meta for approval in one call, then lets you track its status.

**Required scopes:** `templates.read` for reads/sync, `templates.write` for create/delete.

## List approved templates

```http
GET /api/v1/templates
```

**Required scope:** `templates.read`

Returns approved templates ready to send, with their variables.

```json
{
  "success": true,
  "templates": [
    { "name": "order_update", "language": "en_US", "category": "utility", "variables": ["1", "2"] }
  ],
  "totalTemplates": 1
}
```

---

## Create & submit a template

Creates the template and submits it to Meta for approval.

```http
POST /api/v1/templates
```

**Required scope:** `templates.write`

**Request Body:**
```json
{
  "name": "order_update",
  "category": "UTILITY",
  "language": "en_US",
  "body": "Hi {{1}}, your order {{2}} has shipped."
}
```

| Field | Type | Description |
|-------|------|-------------|
| `name` | string | Lowercase letters, digits, and underscores only |
| `category` | string | `MARKETING`, `UTILITY`, or `AUTHENTICATION` (default `UTILITY`) |
| `language` | string | Language code (default `en_US`) |
| `body` | string | Template body; use `{{1}}`, `{{2}}` for variables |

**Response:**
```json
{
  "success": true,
  "template": { "id": 12, "name": "order_update", "status": "pending", "whatsappStatus": "PENDING" },
  "meta": { "id": "1963056624506103", "status": "PENDING" }
}
```

**cURL Example:**
```bash
curl -X POST "https://waflow.edesy.in/api/v1/templates" \
  -H "X-API-Key: wc_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "order_update",
    "category": "UTILITY",
    "language": "en_US",
    "body": "Hi {{1}}, your order {{2}} has shipped."
  }'
```

> **Note:** Requires a connected WhatsApp account (otherwise `400 WHATSAPP_NOT_CONFIGURED`). Newly submitted templates start as `PENDING`; Meta typically reviews within minutes to a few hours. If Meta rejects the submission the endpoint returns `400 META_SUBMISSION_FAILED` with the reason, and keeps the local draft so you can fix and resubmit.

---

## Get a template

```http
GET /api/v1/templates/{id}
```

**Required scope:** `templates.read`

Returns the full template including its approval status (`whatsappStatus`: `PENDING`, `APPROVED`, or `REJECTED`).

---

## Sync a template's status from Meta

Refreshes the local approval status from Meta (e.g. after submission, to check if it's been approved).

```http
POST /api/v1/templates/{id}/sync
```

**Required scope:** `templates.read`

**cURL Example:**
```bash
curl -X POST "https://waflow.edesy.in/api/v1/templates/12/sync" \
  -H "X-API-Key: wc_your_api_key"
```

---

## Delete a template

```http
DELETE /api/v1/templates/{id}
```

**Required scope:** `templates.write`

**Response:**
```json
{ "success": true }
```
