Tutorials
Authenticate users with a WhatsApp template message
Authenticate users with WhatsApp API

Authenticate users with a WhatsApp template message

This tutorial will show you how to send a simple authorization message using Infobip WhatsApp API templates.

What is a WhatsApp template message?

As opposed to regular messages that need to be user-initiated and can only happen within a 24-hour window, template messages can be sent and delivered at any time. Check out our Product Documentation for more details.

Prerequisites

Summary of the steps

  • Create and register WhatsApp template.
  • Send a WhatsApp template message.

Create a WhatsApp template

Use the Create a WhatsApp template (opens in a new tab) endpoint to create your template.

curl
curl -L -g 'https://{baseUrl}/whatsapp/2/senders/{sender}/templates' \
-H 'Authorization: {authorization}' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-d '{
  "name": "authentication_template_with_copy_code_button",
  "language": "en",
  "category": "AUTHENTICATION",
  "allowCategoryChange": false,
  "structure": {
    "body": {
      "addSecurityRecommendation": true
    },
    "footer": {
      "codeExpirationMinutes": 5
    },
    "buttons": [
      {
        "text": "Copy code",
        "otpType": "COPY_CODE"
      }
    ]
  }
}'

Key points:

  • Once you create a template, Infobip sends it for the WhatsApp validation process. You can edit the template, following the editing rules (opens in a new tab).
  • For category, use the AUTHENTICATION value. This will adapt further field options in the API docs.
  • For buttons, use COPY_CODE. This will adapt further field options in the API docs.

Register a WhatsApp template

Infobip takes care of your template registration. During the process, you can edit your template following the editing rules (opens in a new tab). You can also set up a webhook (opens in a new tab) to get the updates about your template registration process.

Send a WhatsApp template message

Once registered, use the template to contact users for authentication.

Key points:

  • Use the international number formatting when adding a number to the to field. For example, for British numbers, the value will look like this: 44754322576.
  • For buttons, use URL. This is to adhere to Meta's convention for button types.
curl
curl -L -g 'https://{baseUrl}/whatsapp/1/message/template' \
-H 'Authorization: {authorization}' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-d '{
  "messages": [
    {
      "from": "441134960000",
      "to": "441134960001",
      "messageId": "a28dd97c-1ffb-4fcf-99f1-0b557ed381da",
      "content": {
        "templateName": "template_name",
        "templateData": {
          "body": {
            "placeholders": [
              "Authentication Code Value"
            ]
          },
          "buttons": [
            {
              "type": "URL",
              "parameter": "Authentication Code Value"
            }
          ]
        },
        "language": "en_GB"
      },
      "callbackData": "Callback data",
      "notifyUrl": "https://www.example.com/whatsapp",
      "urlOptions": {
        "shortenUrl": true,
        "trackClicks": true,
        "trackingUrl": "https://example.com/click-report",
        "removeProtocol": true,
        "customDomain": "example.com"
      }
    }
  ]
}'

Track message delivery

Once you send the request, you should receive a WhatsApp message on the handset you've specified in the to field and see a 200 OK response.

json
{
  "to": "441134960001",
  "messageCount": 1,
  "messageId": "a28dd97c-1ffb-4fcf-99f1-0b557ed381da",
  "status": {
    "groupId": 1,
    "groupName": "PENDING",
    "id": 7,
    "name": "PENDING_ENROUTE",
    "description": "Message sent to next instance"
  }
}

The response informs you that the message has successfully been queued within the Infobip platform and will be then sent to Meta depending on throughput.

If you want to know whether it's been delivered to the recipient, use the Delivery Report (opens in a new tab) feature.

Troubleshoot and analyze your message

For troubleshooting and analytics, Use the auto-generated messageId to view the message and its details.

Need assistance

Explore Infobip Tutorials

Encountering issues

Contact our support

What's new? Check out

Release Notes

Unsure about a term? See

Glossary
Service status

Copyright @ 2006-2025 Infobip ltd.

Service Terms & ConditionsPrivacy policyTerms of use