🚀 What Is WhatsApp Cloud API?
The WhatsApp Cloud API is the official API provided by Meta Platforms for businesses to send and receive WhatsApp messages programmatically.
Common use cases:
- CRM integration
- Chatbots
- Customer support
- Lead management
- Automated notifications
📋 Prerequisites
Before starting, you need:
✔ Meta Developer Account
✔ Meta Business Manager
✔ WhatsApp Business Account
✔ PHP Hosting / Server
✔ HTTPS Domain
✔ Webhook URL
🔥 Step 1: Create Meta Developer App
Go to Meta Developers.
Create a new app.
Choose:
Business
Enter:
- App Name
- Business Account
After creation, open the dashboard.
🔥 Step 2: Add WhatsApp Product
Inside your app:
Click:
Add Product
Choose:
Setup the product.
Meta will provide:
✔ Temporary Access Token
✔ Phone Number ID
✔ Test Number
✔ WhatsApp Business Account ID
Save these.
🔥 Step 3: Create PHP Config File
Create:
config.php
<?php
$token = "YOUR_ACCESS_TOKEN";
$phone_number_id = "YOUR_PHONE_NUMBER_ID";
$verify_token = "anjok_verify_token";
?>
🔥 Step 4: Create Webhook Verification File
Create:
webhook.php
<?php
include "config.php";
$mode = $_GET['hub.mode'] ?? '';
$token = $_GET['hub.verify_token'] ?? '';
$challenge = $_GET['hub.challenge'] ?? '';
if ($mode === 'subscribe' && $token === $verify_token) {
echo $challenge;
exit;
}
http_response_code(403);
?>
This verifies your webhook with Meta.
🔥 Step 5: Configure Webhook in Meta
Inside WhatsApp dashboard:
Open:
Configuration
Enter:
Callback URL
Example:
https://yourdomain.com/webhook.php
Verify Token
Example:
anjok_verify_token
Click:
Verify and Save
If successful:
✔ Webhook connected
🔥 Step 6: Receive Incoming Messages
Extend webhook to capture POST payload.
<?php
$data = file_get_contents("php://input");
file_put_contents("log.txt", $data . PHP_EOL, FILE_APPEND);
?>
Whenever a message arrives, Meta sends JSON data.
Example payload:
{
"entry": [
{
"changes": [
{
"value": {
"messages": [
{
"from": "919999999999",
"text": {
"body": "Hello"
}
}
]
}
}
]
}
]
}
🔥 Step 7: Parse Incoming Message
Example PHP:
$data = json_decode(file_get_contents("php://input"), true);
$message = $data['entry'][0]['changes'][0]['value']['messages'][0]['text']['body'] ?? '';
if ($message) {
file_put_contents("messages.txt", $message . PHP_EOL, FILE_APPEND);
}
🔥 Step 8: Send WhatsApp Message Using PHP
Create:
send.php
<?php
include "config.php";
$url = "https://graph.facebook.com/v22.0/$phone_number_id/messages";
$data = [
"messaging_product" => "whatsapp",
"to" => "919999999999",
"type" => "text",
"text" => [
"body" => "Hello from Anjok Technologies!"
]
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer $token",
"Content-Type: application/json"
]);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
?>
🔥 Step 9: Test Sending Messages
Run:
https://yourdomain.com/send.php
If configured correctly:
✔ WhatsApp message delivered
⚠️ Common Errors
Webhook Verification Failed
Check:
✔ Verify token
✔ HTTPS
✔ Correct response
Invalid Token
Temporary token may expire.
Use permanent token for production.
Permission Error
Ensure required permissions:
✔ WhatsApp Business Messaging
✔ WhatsApp Business Management
🔐 Production Best Practices
Never store secrets in public code.
Use:
✔ Environment variables
✔ HTTPS
✔ Permanent access token
✔ Secure server
🏢 WhatsApp Cloud API Setup by Anjok Technologies
Anjok Technologies helps businesses with:
✔ WhatsApp Cloud API Setup
✔ PHP Integration
✔ Webhook Configuration
✔ CRM Integration
✔ Automation Setup
✔ Multi-Agent WhatsApp CRM
📞 Need Help With Setup?
📱 +91 80729 70517
🌐 https://www.anjoktechnologies.in
👉 Message: WhatsApp Cloud API PHP Setup
🧠 Final Thoughts
Setting up WhatsApp Cloud API with PHP is straightforward once you understand the workflow:
- Create Meta App
- Add WhatsApp Product
- Configure Webhook
- Verify Webhook
- Receive Messages
- Send Messages
Once completed, you can build powerful business applications using WhatsApp automation.