API Reference
Complete API reference for Whatify WhatsApp API
API Reference
Complete API reference for Whatify WhatsApp API.
Table of Contents
Authentication
All API requests require authentication using an API token. You can obtain an API token from your Whatify dashboard under Settings → API.
Authentication Methods
Bearer Token (Recommended)
Authorization: Bearer YOUR_API_TOKENQuery Parameter
?token=YOUR_API_TOKENEndpoints
Connect
Connect to WhatsApp using QR code or pairing code.
Endpoint: POST /api/whatsapp/v1/connect
Rate Limit: 15 requests/minute
Query Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
method | string | No | Connection method: qrCode or pairingCode (default: qrCode) |
phoneNumber | string | No | Phone number for pairing code method |
forceNew | boolean | No | Force new connection session |
rawQrCode | boolean | No | Return raw QR code data |
Response
{
success: boolean;
qrCode?: string; // QR code data (if method is qrCode)
pairingCode?: string; // Pairing code (if method is pairingCode)
status?: string; // Connection status
error?: string; // Error message if failed
}Examples
Using SDK:
const result = await client.connect({
method: "qrCode",
forceNew: true,
});Using cURL:
curl -X POST "https://whatify.dev/api/whatsapp/v1/connect?method=qrCode" \
-H "Authorization: Bearer YOUR_API_TOKEN"Disconnect
Disconnect from WhatsApp and log out.
Endpoint: POST /api/whatsapp/v1/disconnect
Rate Limit: 5 requests/minute
Response
{
success: boolean;
message?: string;
error?: string;
}Examples
Using SDK:
const result = await client.disconnect();Using cURL:
curl -X POST "https://whatify.dev/api/whatsapp/v1/disconnect" \
-H "Authorization: Bearer YOUR_API_TOKEN"Status
Get current WhatsApp connection status and account information.
Endpoint: GET /api/whatsapp/v1/status
Rate Limit: 20 requests/minute
Response
{
success: boolean;
status?: string; // connected, disconnected, connecting
phone?: string; // WhatsApp phone number
name?: string; // WhatsApp account name
profilePic?: string; // Profile picture URL
error?: string;
}Examples
Using SDK:
const status = await client.status();
console.log(status.status); // "connected"Using cURL:
curl -X GET "https://whatify.dev/api/whatsapp/v1/status" \
-H "Authorization: Bearer YOUR_API_TOKEN"Send Message
Send a WhatsApp message with optional attachments.
Endpoint: POST /api/whatsapp/v1/send
Rate Limit: 30 requests/minute
Request Body
{
to: string | string[]; // Recipient phone number(s)
text?: string; // Message text (optional if attachment provided)
attachment?: { // Optional attachment
type: 'image' | 'video' | 'audio' | 'document' | 'sticker';
url?: string; // URL to attachment
base64?: string; // Base64 encoded attachment data
filename?: string; // Filename for the attachment
caption?: string; // Caption for media
mimeType?: string; // MIME type
};
existingMessageId?: string; // Message ID to reply to
}Note: Either text or attachment must be provided.
Response
{
success: boolean;
messageId?: string;
error?: string;
details?: any;
}Examples
Send Text Message:
await client.send({
to: "1234567890",
text: "Hello, World!",
});curl -X POST "https://whatify.dev/api/whatsapp/v1/send" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"to": "1234567890",
"text": "Hello, World!"
}'Send Image with Caption:
await client.send({
to: "1234567890",
text: "Check this out!",
attachment: {
type: "image",
url: "https://example.com/image.jpg",
caption: "Beautiful sunset",
},
});curl -X POST "https://whatify.dev/api/whatsapp/v1/send" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"to": "1234567890",
"text": "Check this out!",
"attachment": {
"type": "image",
"url": "https://example.com/image.jpg",
"caption": "Beautiful sunset"
}
}'Send Document from Base64:
await client.send({
to: "1234567890",
attachment: {
type: "document",
base64: "JVBERi0xLjQKJeLjz9MKMSAwIG9iago8PC...",
filename: "report.pdf",
mimeType: "application/pdf",
caption: "Monthly Report",
},
});Send to Multiple Recipients:
await client.send({
to: ["1234567890", "0987654321", "1111111111"],
text: "Bulk message to multiple recipients",
});Send OTP
Send One-Time Password (OTP) codes via WhatsApp with multi-language support.
Endpoint: POST /api/whatsapp/v1/otp
Rate Limit: 10 requests/minute
Request Body
{
phone: string; // Recipient phone number with country code
code: string | number; // OTP code (4-8 digits)
language?: "Arabic" | "English"; // Message language (default: "English")
}Response
{
success: boolean;
message?: string;
data?: {
messageId: string;
whatsappMessageId: string;
phone: string;
code: string;
language: string;
sentAt: string;
};
error?: string;
}Examples
Send OTP (English):
await client.sendOTP({
phone: "1234567890",
code: "123456",
language: "English",
});curl -X POST "https://whatify.dev/api/whatsapp/v1/otp" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"phone": "1234567890",
"code": "123456",
"language": "English"
}'Send OTP (Arabic):
await client.sendOTP({
phone: "1234567890",
code: "654321",
language: "Arabic",
});OTP Message Templates:
The API automatically formats OTP messages with bold codes for easy copying:
- English:
123456 is your verification code. For your security, do not share this code - Arabic:
123456 هذا هو رمز التحقق الخاص بك. لحمايتك، يرجى عدم مشاركة هذا الرمز.
Code Validation:
- Length: 4-8 digits
- Format: Numbers only (0-9)
- Type: Accepts string or number
Error Handling
All endpoints return a consistent error structure:
{
success: false,
error: string, // Error message
details?: any // Additional error details (for validation errors)
}Common Error Codes
| HTTP Status | Error | Description |
|---|---|---|
| 401 | Unauthorized | Invalid or missing API token |
| 400 | Bad Request | Invalid request data |
| 413 | Payload Too Large | File size exceeds 10MB limit |
| 429 | Rate Limit Exceeded | Too many requests |
| 500 | Internal Server Error | Server error |
Error Examples
Invalid Token:
{
"success": false,
"error": "Invalid API token"
}Validation Error:
{
"success": false,
"error": "Invalid request data",
"details": [
{
"path": ["text"],
"message": "Either text or attachment must be provided"
}
]
}Rate Limit:
{
"success": false,
"error": "Rate limit exceeded",
"resetIn": 45
}Rate Limits
Rate limits are applied per API token:
| Endpoint | Limit | Window |
|---|---|---|
/connect | 15 requests | 1 minute |
/disconnect | 5 requests | 1 minute |
/status | 20 requests | 1 minute |
/send | 30 requests | 1 minute |
/otp | 10 requests | 1 minute |
Rate Limit Headers
Response headers include rate limit information:
X-RateLimit-Limit: 30
X-RateLimit-Remaining: 25
X-RateLimit-Reset: 1234567890Handling Rate Limits
When rate limited, wait for the time specified in the resetIn field before retrying:
const result = await client.send({ to: "123", text: "Hi" });
if (!result.success && result.error === "Rate limit exceeded") {
// Wait and retry
await new Promise((resolve) => setTimeout(resolve, result.resetIn * 1000));
// Retry the request
}Best Practices
- Store API Tokens Securely: Never commit tokens to version control
- Handle Errors Gracefully: Always check the
successfield in responses - Respect Rate Limits: Implement exponential backoff for retries
- Validate Phone Numbers: Ensure phone numbers are in international format
- Optimize File Sizes: Keep attachments under 10MB
- Use Environment Variables: Store configuration in
.envfiles
TypeScript Support
The Whatify SDK includes full TypeScript support with type definitions:
import {
Whatify,
ConnectResponse,
StatusResponse,
SendMessageResponse,
} from "whatify";
const client = new Whatify({ apiToken: "token" });
const status: StatusResponse = await client.status();