WhatsApp API
Templates

WhatsApp Templates

WhatsApp requires all business messages to use pre-approved templates. This endpoint allows you to fetch all approved templates for a specific phone number.

Fetch Templates

Retrieve all WhatsApp templates associated with a specific phone number.

Endpoint

GET /v1/phone_number_ids/{id}/templates

Path Parameters

ParameterTypeRequiredDescription
idintegerYesThe id from the phone numbers endpoint. Use id and not phone_number_id which is also present in the endpoint

Request

curl -X GET "https://whatsapp.smsleopard.com/v1/phone_number_ids/1/templates" \
  -H "Authorization: Basic <your_credentials>" \
  -H "Content-Type: application/json"

Response

[
  {
    "id": "1250589476699956",
    "account_id": 0,
    "button": [
      {
        "phone_number": "",
        "text": "Copy code",
        "type": "URL",
        "url": "https://www.whatsapp.com/otp/code/?otp_type=COPY_CODE&code_expiration_minutes=5&code=otp{{1}}"
      }
    ],
    "footer": "This code expires in 5 minutes.",
    "header": null,
    "language": "en_US",
    "message": "*{{1}}* is your verification code. For your security, do not share this code.",
    "name": "authentication",
    "status": "APPROVED",
    "type": "AUTHENTICATION"
  }
]

Template Fields

FieldTypeDescription
idstringUnique template ID (use this when sending messages)
account_idintegerWhatsApp Business Account ID
buttonarrayInteractive buttons (if any)
footerstringFooter text (optional)
headerobjectHeader content (optional)
languagestringTemplate language code
messagestringMain message body with placeholders
namestringTemplate name identifier
statusstringApproval status (APPROVED, PENDING, REJECTED)
typestringTemplate category

Template Management Tips

  1. Only use APPROVED templates - Templates with other statuses cannot be used for messaging
  2. Check template variables - Ensure you have values for all placeholders
  3. Check button order - Button variables use the zero-based position of each item in the button array. The first button is index 0, the second is index 1, and so on.

Button Variables

Some template buttons require values when sending:

  • Dynamic URL buttons use placeholders in the url, for example https://pay.example.com/{{1}}.
  • Quick reply buttons can receive a custom payload that is returned in webhook responses.
  • Phone number buttons cannot be changed at send time. Create a separate approved template if the number must be different.

When sending a message, pass button values in the BUTTONS component. See Sending Messages: Button Variables.

Error Response Shape

The API returns a consistent error response shape for all errors:

{
  "error_code": string, // e.g., "bad_request", "invalid_format", "unauthorized"
  "error_message": string, // actual error message describing the issue
  "status_code": integer // e.g., 400, 401, 404, 500
}

Next Steps

With your templates ready:

  1. Learn how to send template messages
  2. See practical examples