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

# Listar Templates

> Obtén todos los templates de WhatsApp aprobados

<RequestExample>
  ```bash cURL theme={null}
  curl -X GET "https://api.whaapy.com/templates/v1" \
    -H "Authorization: Bearer wha_xxxxx"
  ```

  ```javascript Node.js theme={null}
  const response = await fetch('https://api.whaapy.com/templates/v1', {
    headers: { 'Authorization': 'Bearer wha_xxxxx' }
  });
  const { data } = await response.json();
  ```

  ```python Python theme={null}
  import requests

  response = requests.get(
      'https://api.whaapy.com/templates/v1',
      headers={'Authorization': 'Bearer wha_xxxxx'}
  )
  templates = response.json()['data']
  ```

  ```php PHP theme={null}
  $curl = curl_init();

  curl_setopt_array($curl, [
    CURLOPT_URL => "https://api.whaapy.com/templates/v1",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
      "Authorization: Bearer wha_xxxxx"
    ],
  ]);

  $response = curl_exec($curl);
  $data = json_decode($response, true);
  ```
</RequestExample>

<ResponseExample>
  ```json 200 OK theme={null}
  {
    "data": [
      {
        "id": "tmpl-uuid-1",
        "name": "order_confirmation",
        "category": "UTILITY",
        "language": "es_MX",
        "status": "APPROVED",
        "content": "Hola {{1}}, tu pedido #{{2}} ha sido confirmado.",
        "variables": ["{{1}}", "{{2}}"],
        "components": [
          {
            "type": "BODY",
            "text": "Hola {{1}}, tu pedido #{{2}} ha sido confirmado.",
            "example": {
              "body_text": [["Juan", "12345"]]
            }
          }
        ],
        "createdAt": "2026-01-15T10:00:00Z",
        "updatedAt": "2026-01-15T10:00:00Z"
      },
      {
        "id": "tmpl-uuid-2",
        "name": "welcome_message",
        "category": "MARKETING",
        "language": "es_MX",
        "status": "APPROVED",
        "content": "¡Bienvenido {{1}}! Gracias por contactarnos.",
        "variables": ["{{1}}"],
        "components": [
          {
            "type": "HEADER",
            "format": "IMAGE"
          },
          {
            "type": "BODY",
            "text": "¡Bienvenido {{1}}! Gracias por contactarnos."
          },
          {
            "type": "FOOTER",
            "text": "Equipo de Soporte"
          },
          {
            "type": "BUTTONS",
            "buttons": [
              {
                "type": "QUICK_REPLY",
                "text": "Ver catálogo"
              },
              {
                "type": "URL",
                "text": "Visitar web",
                "url": "https://ejemplo.com"
              }
            ]
          }
        ],
        "createdAt": "2026-01-10T08:00:00Z",
        "updatedAt": "2026-01-10T08:00:00Z"
      }
    ]
  }
  ```
</ResponseExample>

## Campos del template

| Campo        | Tipo   | Descripción                              |
| ------------ | ------ | ---------------------------------------- |
| `id`         | string | UUID interno de Whaapy                   |
| `name`       | string | Nombre del template (slug)               |
| `category`   | string | `MARKETING`, `UTILITY`, `AUTHENTICATION` |
| `language`   | string | Código de idioma (ej: `es_MX`, `en_US`)  |
| `status`     | string | `APPROVED`, `PENDING`, `REJECTED`        |
| `content`    | string | Texto del body con placeholders          |
| `variables`  | array  | Lista de variables detectadas            |
| `components` | array  | Componentes del template                 |

## Estructura de componentes

Cada template puede tener los siguientes componentes:

### HEADER

```json theme={null}
{
  "type": "HEADER",
  "format": "TEXT" | "IMAGE" | "VIDEO" | "DOCUMENT",
  "text": "Texto del header (solo si format=TEXT)",
  "example": {
    "header_text": ["Ejemplo"]
  }
}
```

### BODY

```json theme={null}
{
  "type": "BODY",
  "text": "Texto con {{1}} variables {{2}}",
  "example": {
    "body_text": [["valor1", "valor2"]]
  }
}
```

### FOOTER

```json theme={null}
{
  "type": "FOOTER",
  "text": "Texto del footer"
}
```

### BUTTONS

```json theme={null}
{
  "type": "BUTTONS",
  "buttons": [
    {
      "type": "QUICK_REPLY",
      "text": "Opción 1"
    },
    {
      "type": "URL",
      "text": "Visitar web",
      "url": "https://ejemplo.com/{{1}}"
    },
    {
      "type": "PHONE_NUMBER",
      "text": "Llamar",
      "phone_number": "+5215512345678"
    }
  ]
}
```

<Info>
  Solo se devuelven templates con estado `APPROVED`. Para ver templates pendientes o rechazados, usa el dashboard de Whaapy o el Meta Business Manager.
</Info>

## Usar template para enviar mensaje

Una vez que tienes el template, puedes enviarlo así:

```javascript theme={null}
const template = templates[0]; // order_confirmation

await fetch('https://api.whaapy.com/messages/v1', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer wha_xxxxx',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    to: '+5215512345678',
    type: 'template',
    template: {
      name: template.name,
      language: template.language,
      components: [
        {
          type: 'body',
          parameters: [
            { type: 'text', text: 'Juan' },      // {{1}}
            { type: 'text', text: '12345' }      // {{2}}
          ]
        }
      ]
    }
  })
});
```
