# WhatsApp Official templates: variables, buttons, and OTP codes.

Templates are created and approved in WhatsApp Official › Templates (WhatsApp Official › Template), or submitted with `POST /api/v2/templates`. Through the API, you send the template name and its variable values. `GET /api/v2/templates` shows the variables to fill per template.

Sumber: https://klikflow.id/docs/en/api/templates-and-otp

## Variables

Named templates (`{{nama}}`, `{{orderid}}`) are filled with an object; numbered templates (`{{1}}`, `{{2}}`) with an array, in order.

```
{
  "channel": "whatsapp_official",
  "to": "6281234567890",
  "type": "template",
  "template": {
    "name": "konfirmasi_pesanan",
    "language": "id",
    "variables": { "nama": "Rina", "orderid": "INV-2207" },
    "button_url": "INV-2207"
  }
}
```

- `header_variables`: text header variables.
- `media_url`: https link for an image, video, or document header.
- `button_url`: suffix of a dynamic website button link.
- `coupon_code`: code for the copy coupon button, at most 15 characters.
- `language` can be left empty when the template exists in only one language.

## OTP codes

OTP codes are generated and checked by your system (login, sign-up, checkout). Klik Flow only sends them through an approved Authentication template.

```
curl -X POST "https://klikflow.id/api/v2/messages" \
  -H "Authorization: Bearer KUNCI_API" \
  -H "Idempotency-Key: 0b8d6c1e-2f4a-4e7b-9c3d-5a6b7c8d9e0f" \
  -H "Content-Type: application/json" \
  -d '{"channel":"whatsapp_official","to":"6281234567890","type":"otp","otp":{"template":"kode_login","code":"482913"}}'
```

- Codes of 1–15 letters, digits, or `-` characters.
- The code fills the message text and the Copy code button at the same time.
- Klik Flow does not store the code; in the Inbox and logs it is shown hidden.
- Use a new Idempotency-Key for every new code, so an old code is not sent again.

## Template names

Lowercase letters, digits, and underscores, at most 512 characters. Spaces and `-` in the template builder automatically become `_`.
