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

# Listar templates

> Consulte os templates aprovados de uma conexão WABA

```http theme={null}
GET https://api.hustapp.com/template
```

Templates são mensagens pré-aprovadas pela Meta. Em conexões WABA, são a única forma de iniciar uma conversa com um contato fora da janela de 24 horas desde a última mensagem dele.

Cada template é aprovado por conta WABA, por isso a listagem é feita por conexão.

## Parâmetros de consulta

| Parâmetro    | Tipo      | Obrigatório | Descrição                                |
| ------------ | --------- | ----------- | ---------------------------------------- |
| `type`       | `string`  | Sim         | Tipo do template. Use `waba`.            |
| `connection` | `integer` | Sim         | ID numérico da conexão. Não aceita UUID. |

<Warning>
  Sem `type=waba` e `connection`, a rota responde `200` com uma lista vazia, não com erro.
</Warning>

## Exemplo

<CodeGroup>
  ```bash cURL theme={null}
  curl -G https://api.hustapp.com/template \
    -H "Authorization: Bearer SEU_TOKEN" \
    --data-urlencode "type=waba" \
    --data-urlencode "connection=919872"
  ```

  ```javascript Node.js theme={null}
  const params = new URLSearchParams({ type: "waba", connection: "919872" });

  const res = await fetch(`https://api.hustapp.com/template?${params}`, {
    headers: { Authorization: `Bearer ${token}` },
  });

  const templates = await res.json();
  ```

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

  res = requests.get(
      "https://api.hustapp.com/template",
      headers={"Authorization": f"Bearer {token}"},
      params={"type": "waba", "connection": 919872},
  )

  templates = res.json()
  ```

  ```php PHP theme={null}
  <?php
  $query = http_build_query(['type' => 'waba', 'connection' => 919872]);

  $ch = curl_init("https://api.hustapp.com/template?{$query}");
  curl_setopt_array($ch, [
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . $token],
  ]);

  $templates = json_decode(curl_exec($ch), true);
  curl_close($ch);
  ```

  ```pascal Delphi theme={null}
  uses
    System.Net.HttpClient, System.JSON;

  var
    HttpClient: THTTPClient;
    Response: IHTTPResponse;
    Templates: TJSONArray;
  begin
    HttpClient := THTTPClient.Create;
    try
      HttpClient.CustomHeaders['Authorization'] := 'Bearer ' + Token;
      Response := HttpClient.Get(
        'https://api.hustapp.com/template?type=waba&connection=919872');

      Templates := TJSONObject.ParseJSONValue(Response.ContentAsString) as TJSONArray;
      try
        // percorra Templates
      finally
        Templates.Free;
      end;
    finally
      HttpClient.Free;
    end;
  end;
  ```
</CodeGroup>

## Resposta

Retorna `200` com a lista de templates disponíveis na conexão.

| Campo        | Tipo      | Descrição                                                                                              |
| ------------ | --------- | ------------------------------------------------------------------------------------------------------ |
| `id`         | `integer` | ID do template no Hust. Usado no [envio dentro de um atendimento](/chat/atendimentos/enviar-template). |
| `name`       | `string`  | Nome do template.                                                                                      |
| `identifier` | `string`  | Identificador único do template.                                                                       |

```json theme={null}
[
  {
    "id": 3021,
    "name": "confirmacao_pedido",
    "identifier": "confirmacao_pedido_v2"
  }
]
```

## Erros

Se a conexão não existir ou não pertencer à sua empresa, a rota responde `400` com o corpo `false`.
