← Back to Blog

How to Send WhatsApp Messages via API — Complete Guide 2026

Sending WhatsApp messages programmatically has become one of the most effective ways to communicate with customers. With a 98% open rate — compared to 20% for email — WhatsApp API is rapidly replacing traditional SMS and email for critical business notifications.

In this guide, you'll learn exactly how to send WhatsApp messages via REST API using WapiConnect, with working code examples in Node.js and Python.

Start Sending WhatsApp Messages Today

7-day free trial — 50 message credits included. No credit card required.

Create Free Account

What You Need Before You Start

To send WhatsApp messages via API with WapiConnect, you need:

Note: Phone numbers must include the country code without the + prefix. For India: 919876543210. For US: 19876543210.

Step 1 — Connect Your WhatsApp Session

Log in to the WapiConnect portal, go to Sessions, and click New Session. Scan the QR code with WhatsApp on your phone. Once connected, your session ID will appear — you'll need this for all API calls.

Step 2 — Get Your API Key

Navigate to Settings → API Keys in the portal and copy your API key. Keep this secret — treat it like a password.

Step 3 — Send a Text Message

Use the POST /api/send-message endpoint to send a text message:

Node.js (fetch)

const response = await fetch('https://api.wapiconnect.cloud/api/send-message', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'x-api-key': 'YOUR_API_KEY'
  },
  body: JSON.stringify({
    sessionId: 'YOUR_SESSION_ID',
    number: '919876543210',
    message: 'Hello! Your order #12345 has been confirmed.'
  })
});

const data = await response.json();
console.log(data);
// { success: true, messageId: 'msg_abc123' }

Python (requests)

import requests

url = 'https://api.wapiconnect.cloud/api/send-message'
headers = {
    'Content-Type': 'application/json',
    'x-api-key': 'YOUR_API_KEY'
}
payload = {
    'sessionId': 'YOUR_SESSION_ID',
    'number': '919876543210',
    'message': 'Hello! Your order #12345 has been confirmed.'
}

response = requests.post(url, json=payload, headers=headers)
print(response.json())
# {'success': True, 'messageId': 'msg_abc123'}

Step 4 — Send an Image or Document

To send media, add a mediaUrl field pointing to a publicly accessible file URL:

const response = await fetch('https://api.wapiconnect.cloud/api/send-message', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'x-api-key': 'YOUR_API_KEY'
  },
  body: JSON.stringify({
    sessionId: 'YOUR_SESSION_ID',
    number: '919876543210',
    message: 'Your invoice is ready.',
    mediaUrl: 'https://yourdomain.com/invoice-12345.pdf',
    mediaType: 'document'   // 'image' | 'document' | 'audio' | 'video'
  })
});

Step 5 — Handle the Response

Every API response returns a JSON object. Check the success field and handle errors gracefully:

const data = await response.json();

if (data.success) {
  console.log('Delivered:', data.messageId);
} else {
  console.error('Failed:', data.error);
  // Common errors:
  // 'SESSION_NOT_CONNECTED' — reconnect your WhatsApp session
  // 'INVALID_NUMBER' — check phone number format
  // 'RATE_LIMIT_EXCEEDED' — slow down your send rate
}

Message Types Supported

TypeFieldExample
TextmessageAny plain text string
ImagemediaUrl + mediaType: "image"JPG, PNG, WebP
DocumentmediaUrl + mediaType: "document"PDF, DOCX, XLSX
AudiomediaUrl + mediaType: "audio"MP3, OGG
VideomediaUrl + mediaType: "video"MP4

Best Practices

Frequently Asked Questions

Can I send messages to any WhatsApp number?

Yes — you can send to any number that has WhatsApp installed, as long as you have obtained proper consent from the recipient.

What is the message rate limit?

On the Pro plan, you can send up to 200 messages per day and 4,000 per month. The Pay As You Go plan scales with your credit purchase.

Will messages show my business name?

Messages are sent from the WhatsApp number you connected as a session, so recipients will see that phone number (or your saved contact name if they have you saved).

Ready to Send Your First WhatsApp Message?

Get started with 50 free message credits. No credit card required.

Start Free Trial