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

# Получаване на шаблони

> Списък с шаблони за WhatsApp съобщения за определен подател

Този endpoint връща всички шаблони за съобщения, свързани с определен WhatsApp подател. Шаблоните са необходими за започване на разговори или изпращане на съобщения до потребители извън 24-часовия прозорец за съобщения.

### Параметри в пътя

<ParamField path="senderId" type="integer" required>
  ID-то на WhatsApp подателя (получено от [Get Senders](/api-reference/whatsapp/get-senders) endpoint)
</ParamField>

### Query параметри

<ParamField query="status" type="string" optional>
  Филтриране на шаблони по статус на одобрение. По подразбиране: `approved`. Използвайте `all` за да върнете всички шаблони независимо от статуса.
</ParamField>

### Полета в отговора

<ResponseField name="data" type="array">
  <Expandable title="Свойства на обекта шаблон">
    <ResponseField name="id" type="integer">
      Уникалният идентификатор на шаблона. Използвайте го при изпращане на шаблонни съобщения.
    </ResponseField>

    <ResponseField name="name" type="string">
      Името на шаблона както е регистрирано в Meta (напр. `order_confirmation`, `appointment_reminder`)
    </ResponseField>

    <ResponseField name="language" type="string">
      Кодът на езика на шаблона (напр. `en`, `es`, `pt_BR`)
    </ResponseField>

    <ResponseField name="category" type="string">
      Категорията на шаблона: `marketing`, `utility` или `authentication`
    </ResponseField>

    <ResponseField name="status" type="string">
      Статусът на одобрение: `approved`, `pending` или `rejected`
    </ResponseField>

    <ResponseField name="body_text" type="string">
      Текстът на тялото на шаблона, с местозапълвачи за променливи показани като `{{1}}`, `{{2}}` и т.н.
    </ResponseField>

    <ResponseField name="variables" type="array">
      Списък с имената на променливите дефинирани за шаблона. Празен масив ако шаблонът няма променливи.
    </ResponseField>

    <ResponseField name="has_variables" type="boolean">
      Дали този шаблон изисква предоставяне на променливи при изпращане
    </ResponseField>
  </Expandable>
</ResponseField>

### Грешни отговори

<ResponseField name="404 Not Found">
  <Expandable title="Отговор при грешка">
    <ResponseField name="success" type="boolean">
      `false`
    </ResponseField>

    <ResponseField name="error" type="string">
      `Sender not found`
    </ResponseField>

    <ResponseField name="error_code" type="string">
      `SENDER_NOT_FOUND`
    </ResponseField>
  </Expandable>
</ResponseField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X GET "https://call.aiployees.com/api/user/whatsapp/senders/12/templates" \
    -H "Authorization: Bearer YOUR_API_KEY"
  ```

  ```bash Всички шаблони (включително pending/rejected) theme={null}
  curl -X GET "https://call.aiployees.com/api/user/whatsapp/senders/12/templates?status=all" \
    -H "Authorization: Bearer YOUR_API_KEY"
  ```

  ```javascript JavaScript theme={null}
  const senderId = 12;

  const response = await fetch(
    `https://call.aiployees.com/api/user/whatsapp/senders/${senderId}/templates`,
    {
      headers: {
        'Authorization': 'Bearer YOUR_API_KEY'
      }
    }
  );

  const data = await response.json();
  console.log(data.data); // Array of templates
  ```

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

  sender_id = 12

  response = requests.get(
      f'https://call.aiployees.com/api/user/whatsapp/senders/{sender_id}/templates',
      headers={'Authorization': 'Bearer YOUR_API_KEY'}
  )

  templates = response.json()['data']
  for template in templates:
      print(f"{template['name']} ({template['language']}): {template['body_text']}")
  ```
</RequestExample>

<ResponseExample>
  ```json 200 Response theme={null}
  {
    "data": [
      {
        "id": 45,
        "name": "appointment_reminder",
        "language": "en",
        "category": "utility",
        "status": "approved",
        "body_text": "Hi {{1}}, this is a reminder for your appointment on {{2}} at {{3}}. Reply YES to confirm or NO to reschedule.",
        "variables": ["customer_name", "date", "time"],
        "has_variables": true
      },
      {
        "id": 46,
        "name": "welcome_message",
        "language": "en",
        "category": "marketing",
        "status": "approved",
        "body_text": "Welcome to Acme Corp! We're excited to have you. How can we help you today?",
        "variables": [],
        "has_variables": false
      }
    ]
  }
  ```

  ```json 404 Подател не е намерен theme={null}
  {
    "success": false,
    "error": "Sender not found",
    "error_code": "SENDER_NOT_FOUND"
  }
  ```
</ResponseExample>

### Забележки

* По подразбиране се връщат само `approved` шаблони. Шаблони със статус `pending` или `rejected` не могат да се използват за изпращане на съобщения.
* Статусът на одобрение на шаблона се синхронизира с Meta автоматично на всеки 4 часа.
* Променливите в `body_text` са показани като `{{1}}`, `{{2}}` и т.н. Масивът `variables` предоставя четими имена за всеки местозапълвач.
* Шаблоните са необходими при първо съобщение до потребител или извън 24-часовия прозорец за съобщения.

***
