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

# Enviar Template

<Card title="Webhook relacionado: Botão / Lista" icon="bolt" href="/webhook-reference/events/botao" horizontal>
  Respostas aos botões do template disparam o evento **Botão / Lista**.
</Card>

## Descrição

Este endpoint permite enviar mensagens usando templates pré-definidos com variáveis personalizadas, para um número ou grupo.

### Parâmetros

<ParamField body="appkey" type="string" required>
  Chave de aplicação.
</ParamField>

<ParamField body="authkey" type="string" required>
  Chave de autenticação do usuário.
</ParamField>

<ParamField body="to" type="string" required>
  Número de telefone no formato internacional ou ID do grupo.
</ParamField>

<ParamField body="template_id" type="string" required>
  Identificador único do template a ser utilizado.
</ParamField>

<ParamField body="variables" type="object" required>
  Objeto com chave-valor para substituir as variáveis do template.
</ParamField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST https://chatbot.menuia.com/api/create-message \
    -H "Content-Type: application/json" \
    -d '{
      "appkey": "SUA_APPKEY_AQUI",
      "authkey": "SUA_AUTHKEY_AQUI",
      "to": "+5511999999999",
      "template_id": "TEMPLATE_ID",
      "variables": {
        "variableKey1": "jhone",
        "variableKey2": "replaceable value"
      }
    }'
  ```

  ```javascript Node.js theme={null}
  const response = await fetch('https://chatbot.menuia.com/api/create-message', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      appkey: 'SUA_APPKEY_AQUI',
      authkey: 'SUA_AUTHKEY_AQUI',
      to: '+5511999999999',
      template_id: 'TEMPLATE_ID',
      variables: {
        variableKey1: 'jhone',
        variableKey2: 'replaceable value'
      }
    })
  });
  ```

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

  response = requests.post(
      'https://chatbot.menuia.com/api/create-message',
      json={
          'appkey': 'SUA_APPKEY_AQUI',
          'authkey': 'SUA_AUTHKEY_AQUI',
          'to': '+5511999999999',
          'template_id': 'TEMPLATE_ID',
          'variables': {
              'variableKey1': 'jhone',
              'variableKey2': 'replaceable value'
          }
      }
  )
  ```

  ```php PHP theme={null}
  $response = Http::post('https://chatbot.menuia.com/api/create-message', [
      'appkey' => 'SUA_APPKEY_AQUI',
      'authkey' => 'SUA_AUTHKEY_AQUI',
      'to' => '+5511999999999',
      'template_id' => 'TEMPLATE_ID',
      'variables' => [
          'variableKey1' => 'jhone',
          'variableKey2' => 'replaceable value'
      ]
  ]);
  ```
</RequestExample>

<ResponseExample>
  ```json 200 - Sucesso theme={null}
  {
    "status": 200,
    "message": "Template enviado com sucesso."
  }
  ```

  ```json 401 - Erro de validação theme={null}
  {
    "status": 401,
    "message": "validation.required"
  }
  ```

  ```json 404 - Template não encontrado theme={null}
  {
    "status": 404,
    "message": "Template não encontrado."
  }
  ```
</ResponseExample>
