Complete Guide: WhatsApp Business API integration
WhatsApp Business API integration (officially the WhatsApp Business Platform / Cloud API) lets businesses send and receive messages at scale via Meta’s hosted API. It supports text, media, interactive messages (buttons, lists), templates, and more. The older on-premise API is deprecated; Cloud API is the standard path in 2026.
Key Components
WhatsApp Business Account (WABA): Container for phone numbers, templates, and assets.
Phone Number ID: The business number used for messaging.
Access Token: Authenticates API calls (temporary for testing; permanent system-user token for production).
Webhooks: Receive real-time inbound messages, delivery statuses, and events.
Message Templates: Required for initiating conversations outside the 24-hour customer care window (must be approved by Meta).
Prerequisites
Meta/Facebook Developer account + Meta Business portfolio (Business Manager).
Business verification (legal documents, often takes days).
A phone number not already registered on personal WhatsApp or the free WhatsApp Business app.
HTTPS endpoint for webhooks (with valid SSL).
Basic knowledge of REST APIs and JSON.
High-Level Setup Steps (Direct Cloud API)
Create a Meta App
Go to developers.facebook.com → Create App → Choose the WhatsApp / “Connect with customers through WhatsApp” use case.
Add WhatsApp Product & Set Up Assets
In the app dashboard, add the WhatsApp product. This creates a test WABA and phone number. Generate a temporary access token from the API Setup page.
Register a Production Phone Number
Add and verify a real business phone number (via SMS/voice OTP). Set display name and profile.
Configure Webhooks
Provide a public HTTPS URL. Subscribe to fields such as messages, message_status, etc. Handle Meta’s verification challenge (GET request with hub.challenge).
Create & Approve Templates
Use WhatsApp Manager or the Business Management API to create templates (utility, marketing, authentication categories). Wait for Meta approval.
Send Messages
Use the Graph API endpoint:
POST https://graph.facebook.com/vXX.0/{PHONE_NUMBER_ID}/messages
with a Bearer token and JSON body (e.g., text, template, interactive).
Example (text message):
JSON
{
"messaging_product": "whatsapp",
"recipient_type": "individual",
"to": "15551234567",
"type": "text",
"text": { "body": "Hello from the Cloud API!" }
}
Handle Inbound Messages & Statuses
Process webhook payloads for replies, read receipts, failures, etc. Implement opt-in/opt-out logic (required by WhatsApp policy).
Alternative: Business Solution Providers (BSPs)
For most businesses, using a BSP (Twilio, 360dialog, MessageBird/Infobip, Gupshup, etc.) is easier. They handle hosting, compliance, analytics, CRM integrations, and often provide dashboards + SDKs. You still need Meta Business verification, but onboarding is faster and less technical.
Official Resources
Get Started: developers.facebook.com/docs/whatsapp/cloud-api/get-started
Full Platform docs: developers.facebook.com/docs/whatsapp
Message templates, webhooks, calling, and error codes are all documented there.
WhatsApp Manager (for non-code management of numbers, templates, analytics).
Important Notes & Best Practices
Opt-in required: Users must explicitly consent to receive messages. Respect opt-outs.
Conversation windows & pricing: Free-form messages are limited to 24 hours after a user message; otherwise use approved templates. Pricing is conversation-based (varies by country and category).
Quality rating: High block/report rates can restrict or ban the number.
Rate limits & scaling: Start low; higher tiers unlock with good quality and verification.
Security: Store tokens securely, use system users for production, validate webhook signatures.
SDKs exist (official and community, e.g., Node/Python wrappers), but the core is the Graph API.
Comments
Post a Comment