How to Send WhatsApp Messages via API in 2025 (Step-by-Step Guide)
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.
What You Need
- A WhatsApp account (regular or business)
- A WAPDeskPro account (free to start)
- Any programming language that supports HTTP requests
Step 1: Create Your Free Account
Go to wapdeskpro.com/register.html and create your free account. No credit card required. You'll get 30 free recipients to test with.
Step 2: Connect Your WhatsApp Number
After logging in:
- Click "Add Phone" in your dashboard
- Give your phone a name (e.g., "Business Line")
- A QR code will appear on screen
- Open WhatsApp on your phone โ Settings โ Linked Devices โ Link a Device
- Scan the QR code โ your phone is now connected
Step 3: Get Your API Token
In your dashboard, go to Settings โ API Token. Copy your token โ you'll use this in every API request.
Step 4: Get Your Phone ID
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
Step 5: Send Your First Message
Now you're ready to send messages. Here's how to do it in different languages:
Using cURL
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 ๐"
}'
Using Python
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'}
Using PHP
<?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;
Using Node.js
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();
Sending Images, Videos and Documents
To send media, use the respective endpoints. The media must be at a publicly accessible URL:
Send Image with Caption
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! ๐๏ธ"
}'
Sending Bulk Messages
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())
Receiving Incoming Messages (Webhook)
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
}
}
Tips to Avoid WhatsApp Bans
- Only message people who have opted in to receive messages
- Use a delay of 2โ5 seconds between bulk messages
- Personalize messages โ avoid copy-paste identical blasts
- Don't send promotional content to cold contacts
- Use a phone number dedicated to API use, not your personal number
Ready to Send Your First WhatsApp Message?
Free trial โ 30 recipients, no credit card. Your number connected in 2 minutes.
Start Free โ