WhatsApp Account
Obtaining WhatsApp credentials.
Checkout the Official guide for the latest info on getting started to WhatsApp Cloud API.
This guide will help you configure and test your WhatsApp API integration using Meta's WhatsApp Business Platform. The process will focus on obtaining the following credentials for use in your engine:
- Access Token
- Phone Number ID
- Webhook Verification Token
We'll also configure a test environment with a test phone number for development purposes.
Prerequisites
-
Meta Developer Account:
- Create an account at Meta for Developers.
- Verify your account by providing valid details (phone number, email, and business info).
-
WhatsApp Business Account:
- A WhatsApp Business Account (WABA) is required. You can create or link one via the Facebook Business Manager.
-
Test Phone Number:
- Use the test number provided by the WhatsApp Business Platform for development purposes. No real phone number is required for testing.
Step 1: Set Up a WhatsApp App
- Go to the Meta for Developers Dashboard.
- Click "Create App" and select Business App as the type.
- App Name: Choose a descriptive name for your app.
- Contact Email: Provide your contact email.
- Business Account: Select your WABA (or create one if not available).
- After creating the app, you'll land on the app's dashboard.
Step 2: Access the WhatsApp Business Platform
- On the app dashboard, scroll down to the "Add Products to Your App" section.
- Find WhatsApp and click "Set Up".
- You'll be redirected to the WhatsApp Business API section.
Step 3: Obtain a Test Token
- In the Getting Started section:
- A Temporary Access Token will be displayed. This is your initial token for testing.
- Copy the token and save it securely for later use.
- Under the Phone Numbers section:
- Meta provides a test phone number by default. Note down its Phone Number ID.
- You'll use this ID to send messages.
Note: The temporary token expires after 24 hours. For production, you'll need to generate a permanent token (covered in the "Upgrading to Production" section below).
Step 4: Set Up a Webhook URL and Verification Token
- In the app dashboard, navigate to WhatsApp > Configuration.
- Click "Add Webhook".
- Provide the following:
- Callback URL: Your webhook endpoint (e.g.,
https://yourdomain.com/webhook
). - Verification Token: Create a unique token (
HUB_TOKEN
) (e.g.,your_custom_verification_token
) and save it securely. This will be used to verify your webhook.
- Callback URL: Your webhook endpoint (e.g.,
- Click "Verify and Save". Meta will send a GET request to your webhook with a challenge parameter. Your webhook must respond with the challenge value to complete verification.
Step 5: Test Your API
Meta provides a simple interface to test API calls.
- In the "Send and Receive Messages" section:
- Use the Test Phone Number to send messages to yourself or other test numbers.
- Example API Call (using cURL):
curl -X POST https://graph.facebook.com/v21.0/<PHONE_NUMBER_ID>/messages \ -H "Authorization: Bearer <ACCESS_TOKEN>" \ -H "Content-Type: application/json" \ -d '{ "messaging_product": "whatsapp", "to": "<RECIPIENT_PHONE_NUMBER>", "type": "text", "text": { "body": "Hello, this is a test message!" } }'
- Replace the placeholders (
<PHONE_NUMBER_ID>
,<ACCESS_TOKEN>
,<RECIPIENT_PHONE_NUMBER>
) with the values you obtained earlier.
Key Credentials Overview
Credential | Purpose | Example Value |
---|---|---|
Access Token | Authenticates API requests | EAAJZCzQxyzv... |
Phone Number ID | Identifies the phone number in API | 123456789 |
Webhook Verification Token | Verifies webhook authenticity | your_hub_token |
Step 6: Upgrading to Production (Optional)
For production use:
-
Generate a Permanent Access Token:
- In the app dashboard, navigate to Settings > Basic.
- Click Generate Token, select the required permissions, and save the token securely.
-
Verify Your Business:
- Complete the business verification process via the Facebook Business Manager.
-
Use a Real Phone Number:
- Add a real phone number under the Phone Numbers section in the WhatsApp configuration.
Troubleshooting Tips
- Ensure your webhook is publicly accessible for Meta to verify and deliver events.
- Check the API Reference for additional details on endpoints and payloads.
- Use Meta's Graph API Explorer for testing API requests interactively.