API
Integrate WhatsApp messaging into your application with our simple REST API. Send text, images, audio, video, and documents programmatically.
Quick Setup
Get started in under 5 minutes with your API token and a single endpoint.
Secure by Default
Bearer token authentication over HTTPS with enterprise-grade security.
Real-time Webhooks
Receive incoming messages and status updates instantly via webhook callbacks.
https://megamsg.app/api
Authentication
All API requests require two credentials: your Instance ID and a Bearer Token. Both are provided when you create a WhatsApp instance in the dashboard.
Keep your credentials secret
Never expose your Instance ID or API token in client-side code or public repositories.
Required Headers
Include both headers in every API request:
Authorization: Bearer your_api_token_here
X-Instance-Id: your_instance_id_here
How It Works
Create an Instance
From your dashboard, create a new WhatsApp instance and scan the QR code.
Copy Your Credentials
Each instance gets a unique Instance ID and a 64-character Token. Copy both from the dashboard.
Start Sending
Use the token in your API calls to send messages through the connected WhatsApp number.
Send Message
Send a text, image, audio, video, or document message to a WhatsApp number.
POST /api/whatsapp/messages/send
Request Parameters
| Parameter | Type | Status | Description |
|---|---|---|---|
| phone_number | string | Required | Recipient phone with country code (e.g. +201234567890) |
| type | string | Optional | Message type: text, image, audio, video, document. Default: text |
| text | string | Required* | Message content. Required when type is text. |
| media | string | Required* | URL or base64 of media. Required for image, audio, video, document. |
| caption | string | Optional | Caption for media messages. |
| mime_type | string | Required* | MIME type. Required for document type. |
| file_name | string | Required* | File display name. Required for document type. |
| ptt | boolean | Optional | Push-to-talk (voice note). Only for audio type. |
Code Examples
curl -X POST https://megamsg.app/api/whatsapp/messages/send \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "X-Instance-Id: YOUR_INSTANCE_ID" \
-H "Content-Type: application/json" \
-d '{
"phone_number": "+201234567890",
"type": "text",
"text": "Hello from MegaMsg! 🚀"
}'$response = Http::withToken('YOUR_TOKEN')
->withHeaders(['X-Instance-Id' => 'YOUR_INSTANCE_ID'])
->post('https://megamsg.app/api/whatsapp/messages/send', [
'phone_number' => '+201234567890',
'type' => 'text',
'text' => 'Hello from MegaMsg! 🚀',
]);
$data = $response->json();
// { "ok": true, "to": "+201234567890", "type": "text" }const res = await fetch('https://megamsg.app/api/whatsapp/messages/send', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_TOKEN',
'X-Instance-Id': 'YOUR_INSTANCE_ID',
'Content-Type': 'application/json',
},
body: JSON.stringify({
phone_number: '+201234567890',
type: 'text',
text: 'Hello from MegaMsg! 🚀',
}),
});
const data = await res.json();import requests
resp = requests.post(
'https://megamsg.app/api/whatsapp/messages/send',
headers={
'Authorization': 'Bearer YOUR_TOKEN',
'X-Instance-Id': 'YOUR_INSTANCE_ID',
},
json={
'phone_number': '+201234567890',
'type': 'text',
'text': 'Hello from MegaMsg! 🚀',
}
)
data = resp.json()Response
✓ Success (200)
{
"ok": true,
"to": "+201234567890",
"type": "text"
}✗ Error (401)
{
"ok": false,
"message": "Unauthorized."
}Webhook Events
Configure a webhook URL in your instance settings to receive real-time events. We will POST JSON payloads to your URL with retry logic (3 attempts).
Message Received
Your webhook URL will receive incoming messages in this format:
{
"type": "message",
"message": {
"id": "ABCDEF123456",
"from": "201234567890",
"push_name": "John Doe",
"text": "Hello!",
"timestamp": 1714650000,
"is_group": false,
"type": "text"
},
"timestamp": "2026-05-02T12:00:00+00:00"
}
Webhook Fields
| Field | Type | Description |
|---|---|---|
| type | string | Always "message" for incoming messages |
| message.id | string | Unique WhatsApp message ID |
| message.from | string | Sender phone number (without @s.whatsapp.net) |
| message.push_name | string | Sender's WhatsApp display name |
| message.text | string | Message text content |
| message.is_group | boolean | Whether the message is from a group |
| message.type | string | Message type (text, image, audio, etc.) |
| timestamp | string | ISO 8601 timestamp |
API Sandbox
Test the Send Message API directly from your browser. Fill in your credentials and hit send.
Sending request…
Error Codes
All errors follow a consistent JSON format with an ok: false flag.
| Status | Meaning | Common Cause |
|---|---|---|
| 401 | Unauthorized | Missing or invalid Bearer token |
| 422 | Validation Error | Missing required fields or invalid values |
| 502 | Bad Gateway | WhatsApp service is unreachable or session disconnected |
| 500 | Server Error | Internal error — contact support |
Error Response Format
{
"ok": false,
"message": "Description of what went wrong."
}