Sending WhatsApp messages programmatically is one of the most powerful ways to automate customer communication. In this guide, you'll learn exactly how to send WhatsApp messages via REST API using WAPDeskPro — with working code examples in Python, PHP, and Node.js.
Go to wapdeskpro.com/register.html and create your free account. No credit card required. You'll get 30 free recipients to test with.
After logging in:
In your dashboard, go to Settings → API Token. Copy your token — you'll use this in every API request.
Every connected WhatsApp number has a unique phone_id. You can find it in your dashboard next to each phone, or call:
GET https://wapdeskpro.com/api/phones
Authorization: Bearer YOUR_API_TOKEN
Now you're ready to send messages. Here's how to do it in different languages:
curl -X POST https://wapdeskpro.com/api/send \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"phone_id": "ph_abc123",
"to": "919876543210",
"message": "Hello! This is my first WhatsApp API message 🎉"
}'
import requests
API_TOKEN = "YOUR_API_TOKEN"
PHONE_ID = "ph_abc123"
response = requests.post(
"https://wapdeskpro.com/api/send",
headers={
"Authorization": f"Bearer {API_TOKEN}",
"Content-Type": "application/json"
},
json={
"phone_id": PHONE_ID,
"to": "919876543210",
"message": "Hello from Python! 🐍"
}
)
print(response.json())
# {'success': True, 'message_id': '3EB0C...', 'status': 'sent'}
<?php
$token = 'YOUR_API_TOKEN';
$phoneId = 'ph_abc123';
$data = [
'phone_id' => $phoneId,
'to' => '919876543210',
'message' => 'Hello from PHP! 🐘'
];
$ch = curl_init('https://wapdeskpro.com/api/send');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $token,
'Content-Type: application/json'
]);
$result = curl_exec($ch);
curl_close($ch);
echo $result;
const axios = require('axios');
const API_TOKEN = 'YOUR_API_TOKEN';
const PHONE_ID = 'ph_abc123';
async function sendWhatsApp() {
const response = await axios.post(
'https://wapdeskpro.com/api/send',
{
phone_id: PHONE_ID,
to: '919876543210',
message: 'Hello from Node.js! 🟢'
},
{
headers: {
Authorization: `Bearer ${API_TOKEN}`,
'Content-Type': 'application/json'
}
}
);
console.log(response.data);
}
sendWhatsApp();
To send media, use the respective endpoints. The media must be at a publicly accessible URL:
curl -X POST https://wapdeskpro.com/api/send-image \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"phone_id": "ph_abc123",
"to": "919876543210",
"url": "https://example.com/product.jpg",
"caption": "Check out our new product! 🛍️"
}'
To send the same message to multiple recipients at once, use the bulk endpoint. WAPDeskPro automatically adds a delay between messages to prevent WhatsApp flagging:
import requests
contacts = [
"919876543210",
"918765432109",
"917654321098"
# add as many as needed on Pro plan
]
response = requests.post(
"https://wapdeskpro.com/api/bulk-send",
headers={"Authorization": f"Bearer {API_TOKEN}"},
json={
"phone_id": "ph_abc123",
"numbers": contacts,
"message": "🎉 Our sale starts NOW! Visit wapdeskpro.com",
"delay": 3000 # 3 seconds between each message
}
)
print(response.json())
To receive messages sent to your WhatsApp number, set up a webhook:
curl -X POST https://wapdeskpro.com/api/webhook/set \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"phone_id": "ph_abc123",
"webhook_url": "https://yourserver.com/whatsapp-hook"
}'
WAPDeskPro will send a POST request to your URL for every incoming message with this payload:
{
"event": "message.received",
"from": "919876543210",
"message": {
"type": "text",
"text": "Hello, I need help!",
"timestamp": 1713254400
}
}
Free trial — 30 recipients, no credit card. Your number connected in 2 minutes.
Start Free →