WhatsApp API for Developers — Build, Ship, Scale
A developer-first WhatsApp API with clean REST endpoints, webhooks, code samples in six languages, and infrastructure that scales with your project.
Your First API Call
const response = await fetch('https://api2whats.com/send-text', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
to: '971501234567',
message: 'Hello from my app!'
})
});
const data = await response.json();
console.log(data.id); // message ID
Why Developers Choose This API
Most WhatsApp API solutions are designed for non-technical users first and developers second. The documentation is sparse, the error messages are unhelpful, and you spend more time fighting the API than building with it. We built this API the other way around — developers first, everything else second.
Every endpoint returns structured JSON with clear error codes. Every request has a predictable response format. The documentation includes working code samples you can copy and run immediately. And the webhook system delivers incoming messages to your server in real time with signed payloads so you can verify authenticity.
Whether you are building a customer support chatbot, an order notification system, a marketing automation tool, or a custom integration for a client, the API gets out of your way and lets you focus on your code.
Architecture Overview
The API sits between your application and WhatsApp's servers. Here is what happens when you send a message:
- Your application sends an HTTP POST request to the API endpoint
- The API authenticates your request using the API key in the Authorization header
- The message is routed to the correct WhatsApp instance (if you have multiple)
- The message is delivered over a persistent WebSocket connection to WhatsApp
- You receive a response with the message ID and delivery status
- Subsequent status updates (delivered, read) are pushed to your webhook
The entire round-trip typically takes less than 50 milliseconds. There is no browser involved, no screenshot processing, no DOM manipulation. The WebSocket connection is persistent and handles reconnection, authentication refresh, and error recovery automatically.
REST API Reference
All endpoints follow REST conventions. Requests use JSON bodies. Responses use JSON. Authentication is via Bearer tokens in the Authorization header.
Sending Messages
| Method | Endpoint | Description |
|---|---|---|
| POST | /send-text | Send a text message |
| POST | /send-image | Send an image (URL or Base64) |
| POST | /send-video | Send a video |
| POST | /send-document | Send a document or file |
| POST | /send-audio | Send an audio file |
| POST | /send-location | Send a location pin |
| POST | /send-sticker | Send a sticker |
Managing Instances
| Method | Endpoint | Description |
|---|---|---|
| GET | /instance/status | Check connection status |
| POST | /instance/connect | Get QR code for connection |
| POST | /instance/pairing-code | Get pairing code |
| POST | /instance/disconnect | Disconnect the instance |
Webhooks
| Method | Endpoint | Description |
|---|---|---|
| POST | /set-webhook | Set your webhook URL |
| GET | /get-webhook | Get current webhook URL |
Webhook Integration
Webhooks are how you receive incoming messages. When someone sends a message to your connected WhatsApp number, the API makes a POST request to your webhook URL with the message data.
A webhook payload looks like this:
{
"event": "message",
"instance": "instance_abc123",
"data": {
"id": "3EB0A1B2C3D4E5F6",
"from": "971501234567",
"message": "Hi, I need help with my order",
"timestamp": 1691234567,
"type": "text"
}
}
Your webhook handler processes this data and can trigger any automated response. The webhook system supports retry logic — if your server is temporarily unavailable, the API retries delivery multiple times before giving up.
For security, all webhook payloads include an X-Signature header that you can verify to ensure the request actually came from our API and not from a third party.
Code Samples in Six Languages
We provide working code samples for every common operation. Each sample is a complete, runnable script — not a snippet that leaves you guessing about imports, error handling, or configuration.
PHP
<?php
$ch = curl_init('https://api2whats.com/send-text');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ***',
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => json_encode([
'to' => '971501234567',
'message' => 'Hello from PHP!',
]),
CURLOPT_RETURNTRANSFER => true,
]);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
Python
import requests
response = requests.post(
'https://api2whats.com/send-text',
headers={
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json',
},
json={
'to': '971501234567',
'message': 'Hello from Python!',
}
)
print(response.json())
JavaScript (Node.js)
const response = await fetch('https://api2whats.com/send-text', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json',
},
body: JSON.stringify({
to: '971501234567',
message: 'Hello from Node.js!',
}),
});
const data = await response.json();
console.log(data);
Error Handling
The API uses standard HTTP status codes and returns structured error responses:
{
"success": false,
"error": {
"code": "INSTANCE_DISCONNECTED",
"message": "The WhatsApp instance is not connected"
}
}
Common error codes include:
- 401 Unauthorized — Invalid or missing API key
- 400 Bad Request — Missing required fields or invalid data
- 404 Not Found — Instance or resource does not exist
- 429 Too Many Requests — Rate limit exceeded
- 500 Internal Server Error — Something went wrong on our end (rare)
Webhook Security
Every webhook request includes an X-Signature header that contains an HMAC-SHA256 signature of the request body. Your webhook handler should verify this signature to ensure the request actually came from our API and not from a third party.
// Node.js webhook signature verification
const crypto = require('crypto');
function verifySignature(payload, signature, secret) {
const expected = crypto
.createHmac('sha256', secret)
.update(payload)
.digest('hex');
return crypto.timingSafeEqual(
Buffer.from(signature),
Buffer.from(expected)
);
}
app.post('/webhook', (req, res) => {
const sig = req.headers['x-signature'];
const body = JSON.stringify(req.body);
if (!verifySignature(body, sig, WEBHOOK_SECRET)) {
return res.status(401).json({ error: 'Invalid signature' });
}
// Process the message...
res.json({ success: true });
});
Testing and Debugging
The API provides several tools for testing and debugging your integration:
- Dashboard logs — View all API requests and their responses in real time from your dashboard
- Webhook test endpoint — Send a test webhook to verify your handler is working correctly
- Message status tracking — Query the status of any message by its ID
- Error rate monitoring — Track your API error rates over time in the dashboard
We recommend starting with a test instance connected to your personal number. Send test messages, verify webhooks, and check error handling before going live with production traffic.
Best Practices for Developers
- Store API keys securely — Use environment variables, not hardcoded strings. Never commit API keys to version control.
- Handle errors gracefully — Implement retry logic with exponential backoff for transient errors (5xx, network timeouts).
- Validate webhook signatures — Never trust unverified webhook requests. Always check the X-Signature header.
- Use connection pooling — Reuse HTTP connections across requests instead of creating new ones for each API call.
- Monitor rate limits — Check the X-RateLimit-Remaining header and implement proactive throttling when approaching limits.
- Log everything — Record request/response pairs for debugging. Redact sensitive data (phone numbers, message content) in production logs.
Rate Limits
Rate limits are enforced per API key and vary by plan. The API returns a 429 status code with a Retry-After header when you hit the limit. Here are the defaults:
- Basic plan — 100 requests per minute
- Professional plan — 300 requests per minute
- Enterprise plan — 1000 requests per minute
If you consistently hit rate limits, consider upgrading your plan or batching requests where possible.
Webhook Payload Formats
Incoming messages arrive in different formats depending on the message type:
Text Message
{
"event": "message",
"data": {
"id": "3EB0A1B2C3D4E5F6",
"from": "971501234567",
"message": "Hello!",
"type": "text",
"timestamp": 1691234567
}
}
Image Message
{
"event": "message",
"data": {
"id": "3EB0A1B2C3D4E5F7",
"from": "971501234567",
"type": "image",
"caption": "Check this out!",
"mediaUrl": "https://api2whats.com/media/...",
"mimeType": "image/jpeg",
"timestamp": 1691234568
}
}
Status Update
{
"event": "status",
"data": {
"id": "3EB0A1B2C3D4E5F6",
"status": "delivered",
"timestamp": 1691234600
}
}
Status values include: sent (handed to WhatsApp), delivered (reached the device), and read (opened by the recipient).
Getting Started
- Create an account (free, no credit card)
- Choose a plan from the pricing page
- Create an instance from your dashboard
- Connect your phone number via QR or pairing code
- Read the full API documentation
- Send your first message and start building
Community and Support
Join our developer community to get help, share integrations, and stay updated on new features. We have an active community of developers building WhatsApp integrations across every industry.
- Documentation — Comprehensive API reference with working examples
- Code samples — Complete, runnable scripts in PHP, Python, JavaScript, and cURL
- Email support — Response within 24 hours for all plan tiers
- Dashboard logs — Real-time visibility into API requests and webhook deliveries
- Status page — Live system status and incident history
Whether you are building your first WhatsApp integration or scaling an existing one, our resources and support team are here to help you succeed.
Start Building Today
Clean API, real documentation, code samples that actually work. Ship your WhatsApp integration in hours, not weeks.