WhatsApp has become the world’s most popular messaging application, with over 2.5 billion users worldwide. For businesses, this represents a direct channel to customers where they already spend their time. While the WhatsApp Business App is suitable for small merchants, larger organizations require automation, scalability, and system integration. This is where the WhatsApp Cloud API comes in.

1. Introduction

The WhatsApp Cloud API, launched by Meta (formerly Facebook), allows businesses to build powerful, automated messaging solutions without hosting their own WhatsApp Business API client. Instead, Meta hosts and maintains the infrastructure, and developers interact via a simple RESTful API.

In this article, we will explore how to set up WhatsApp Cloud API using Meta for Developers, step by step — from sending your first message to handling interactive buttons and list messages. This guide will be both conceptual and hands-on, with code samples and JSON payloads.


2. Why WhatsApp Cloud API?

Unlike the standard WhatsApp Business App, the Cloud API provides:

  • Scalability: Support for thousands of messages per second.
  • Automation: Integrate with CRMs, ERPs, or chatbots.
  • Interactive Messages: Quick replies, list menus, call-to-action buttons.
  • Global Availability: Hosted by Meta with high availability.
  • Lower Cost: No need for BSP (Business Solution Provider) hosting fees.

Businesses such as e-commerce platforms, financial institutions, and service companies rely on Cloud API to deliver notifications, authentication codes, and customer support.


3. Core Concepts of WhatsApp Business Messaging

Before diving into setup, let’s understand some key concepts:

  • Phone Number ID: The unique identifier of the phone number registered with WhatsApp Cloud API.
  • WhatsApp Business Account (WABA) ID: The container for your WhatsApp numbers, templates, and business info.
  • Access Token: Bearer token for API calls (temporary vs permanent).
  • Session Messages: Free-form messages sent within 24 hours of last user interaction.
  • Message Templates: Pre-approved structured messages required to initiate conversations.
  • Interactive Messages: Buttons and list messages to engage users.
  • Webhook: Your server endpoint to receive incoming messages and delivery status.

4. Prerequisites Before You Begin

  • Meta Developer Account at developers.facebook.com.
  • Facebook Business Account (verified for production use).
  • A phone number that is not already registered on WhatsApp/WA Business App.
  • Basic knowledge of REST APIs and tools like cURL or Postman.
  • Optional: a server (Node.js, Python, PHP, Go, etc.) to host webhook logic.

5. Step 1 – Creating a Meta App and Enabling WhatsApp

  1. Log into Meta for Developers.
  2. Navigate to My AppsCreate App → Select Business.
  3. Give your app a name and link it to your Business Account.
  4. Under App Dashboard, click Set Up for the WhatsApp product.
  5. Meta will automatically provision:
    • A Test Business Number.
    • A Temporary Access Token (valid for 24 hours).
    • The Phone Number ID and WABA ID.

This test number can only send messages to up to 5 pre-registered recipients that you manually add in the dashboard. This is sufficient for initial development.


6. Step 2 – Sending Your First Test Message

Using cURL:

curl -X POST "https://graph.facebook.com/v20.0/{PHONE_NUMBER_ID}/messages" \
  -H "Authorization: Bearer {TEMPORARY_USER_ACCESS_TOKEN}" \
  -H "Content-Type: application/json" \
  -d '{
        "messaging_product": "whatsapp",
        "to": "6281234567890",
        "type": "text",
        "text": { "body": "Hello from WhatsApp Cloud API!" }
      }'

If successful, the response will contain a messages array with id. Your phone should immediately receive the message from the test number.


7. Step 3 – Setting Up a Permanent Access Token

The temporary token expires. For production:

  1. Go to Business SettingsUsers → System Users.
  2. Add a System User with the Admin role.
  3. Assign assets: your App and WhatsApp Account.
  4. Generate a token with permissions:
    • whatsapp_business_messaging
    • whatsapp_business_management
  5. Save the token securely — treat it like a password.

Now you can use this permanent token for API calls.


8. Step 4 – Adding a Production Phone Number

  1. In your WhatsApp product dashboard, click Add Phone Number.
  2. Enter your business information and select a phone number.
  3. Verify ownership via SMS or voice call.
  4. Submit your Display Name for approval.

⚠️ Important: The number must not already be active in WhatsApp. If so, deregister it first.


9. Step 5 – Configuring Webhooks for Incoming Messages

To receive messages or delivery events, configure a Webhook:

  1. Prepare an HTTPS endpoint on your server.
  2. Implement two handlers:
    • GET: for verification. Return hub.challenge if hub.verify_token matches.
    • POST: for incoming messages and statuses.

Example verification handler (Node.js/Express):

app.get('/webhook', (req, res) => {
  if (req.query['hub.verify_token'] === "MY_VERIFY_TOKEN") {
    res.send(req.query['hub.challenge']);
  } else {
    res.sendStatus(403);
  }
});

Incoming messages will be JSON objects, e.g.:

{
  "object": "whatsapp_business_account",
  "entry": [
    {
      "id": "WABA_ID",
      "changes": [
        {
          "value": {
            "messages": [
              {
                "from": "6281234567890",
                "id": "wamid.ID",
                "timestamp": "1691234567",
                "text": { "body": "Hello" },
                "type": "text"
              }
            ]
          }
        }
      ]
    }
  ]
}

10. Step 6 – Creating and Using Message Templates

Templates are required to start conversations outside the 24-hour window.

  • Go to WhatsApp ManagerMessage Templates.
  • Create a new template:
    • Category: Utility, Marketing, or Authentication.
    • Language: e.g., English, Indonesian.
    • Content: structured with placeholders ({{1}}, {{2}}).
    • Optional CTA buttons: open URL or call phone.
  • Submit for approval. Once approved, you can send templates via API.

Example API call to send a template:

{
  "messaging_product": "whatsapp",
  "to": "6281234567890",
  "type": "template",
  "template": {
    "name": "order_update",
    "language": { "code": "en_US" },
    "components": [
      {
        "type": "body",
        "parameters": [
          { "type": "text", "text": "Andi" },
          { "type": "text", "text": "INV12345" }
        ]
      }
    ]
  }
}

11. Step 7 – Sending Interactive Messages

a) Reply Buttons

{
  "messaging_product": "whatsapp",
  "to": "6281234567890",
  "type": "interactive",
  "interactive": {
    "type": "button",
    "body": { "text": "Choose an option:" },
    "action": {
      "buttons": [
        { "type": "reply", "reply": { "id": "opt1", "title": "Check Status" } },
        { "type": "reply", "reply": { "id": "opt2", "title": "Contact Support" } }
      ]
    }
  }
}

b) List Messages

{
  "messaging_product": "whatsapp",
  "to": "6281234567890",
  "type": "interactive",
  "interactive": {
    "type": "list",
    "body": { "text": "Please select a service:" },
    "action": {
      "button": "View Options",
      "sections": [
        {
          "title": "Services",
          "rows": [
            { "id": "svc1", "title": "Preventive Maintenance" },
            { "id": "svc2", "title": "Root Cause Analysis" }
          ]
        }
      ]
    }
  }
}

c) Call-to-Action (CTA) Buttons

  • Open a website link.
  • Call a phone number directly.

12. Step 8 – Understanding the 24-Hour Customer Service Window

WhatsApp enforces a 24-hour session rule:

  • You may send free-form messages only within 24 hours of last user message.
  • Outside 24 hours, you must use pre-approved templates.
  • Once the user replies, a new 24-hour window starts.

13. Step 9 – Messaging Limits and Business Quality Ratings

  • Messaging limits scale from 1,000 to unlimited conversations per day depending on engagement and business rating.
  • Quality Rating is based on user feedback (block/report).
  • Poor quality can lead to limits or suspension.

14. Step 10 – Security, Token Management, and Best Practices

  • Always use Permanent Tokens for production.
  • Store tokens securely (not in frontend).
  • Use webhook verification and validate signatures.
  • Rotate tokens periodically.
  • Respect opt-in policies: never spam.

15. Example Use Cases in Industry

  • E-commerce: Order confirmations, delivery updates, abandoned cart recovery.
  • Banking/Fintech: Transaction alerts, OTP authentication, fraud notifications.
  • Utilities: Bill reminders, outage updates.
  • Healthcare: Appointment reminders, test results.
  • HR/Recruitment: Interview scheduling, onboarding.

16. Troubleshooting Common Errors

  • (#131000) Recipient phone number not in allowed list: Add to test list.
  • (#132000) Template not found: Ensure template is approved and name matches.
  • (#100) Invalid parameter: Check JSON structure and phone format (E.164).
  • Message not delivered: Verify opt-in, template approval, and 24-hour rule.

17. Conclusion

WhatsApp Cloud API provides businesses with a powerful, scalable, and flexible way to connect with customers. By leveraging interactive buttons, list messages, and template notifications, you can deliver an engaging customer experience that goes beyond simple text messaging.

The step-by-step setup includes:

  1. Creating an app and test environment.
  2. Sending your first test message.
  3. Setting up permanent access tokens.
  4. Adding and verifying a production phone number.
  5. Configuring webhooks to receive events.
  6. Creating and using templates to initiate conversations.
  7. Sending interactive messages for richer engagement.

With careful compliance, token management, and template strategy, businesses can harness the full potential of WhatsApp Cloud API to improve customer service, drive sales, and increase brand trust.

Sign In

Register

Reset Password

Please enter your username or email address, you will receive a link to create a new password via email.