Tutorial April 16, 2025 8 min read

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

Step 1: Create Your Free Account

1

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

2

After logging in:

  1. Click "Add Phone" in your dashboard
  2. Give your phone a name (e.g., "Business Line")
  3. A QR code will appear on screen
  4. Open WhatsApp on your phone → Settings → Linked Devices → Link a Device
  5. Scan the QR code — your phone is now connected
Once connected, WAPDeskPro maintains the session on the server. Your phone doesn't need to stay online.

Step 3: Get Your API Token

3

In your dashboard, go to Settings → API Token. Copy your token — you'll use this in every API request.

Keep your API token secret. Never expose it in public code or frontend JavaScript.

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

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
<?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

javascript
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:

python
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())
Pro tip: Always use a delay of at least 2–3 seconds between bulk messages to avoid WhatsApp temporarily restricting your number.

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

Ready to Send Your First WhatsApp Message?

Free trial — 30 recipients, no credit card. Your number connected in 2 minutes.

Start Free →