Whatify LogoWhatify
API

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_TOKEN

Query Parameter

?token=YOUR_API_TOKEN

Endpoints

Connect

Connect to WhatsApp using QR code or pairing code.

Endpoint: POST /api/whatsapp/v1/connect

Rate Limit: 15 requests/minute

Query Parameters

ParameterTypeRequiredDescription
methodstringNoConnection method: qrCode or pairingCode (default: qrCode)
phoneNumberstringNoPhone number for pairing code method
forceNewbooleanNoForce new connection session
rawQrCodebooleanNoReturn 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 StatusErrorDescription
401UnauthorizedInvalid or missing API token
400Bad RequestInvalid request data
413Payload Too LargeFile size exceeds 10MB limit
429Rate Limit ExceededToo many requests
500Internal Server ErrorServer 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:

EndpointLimitWindow
/connect15 requests1 minute
/disconnect5 requests1 minute
/status20 requests1 minute
/send30 requests1 minute
/otp10 requests1 minute

Rate Limit Headers

Response headers include rate limit information:

X-RateLimit-Limit: 30
X-RateLimit-Remaining: 25
X-RateLimit-Reset: 1234567890

Handling 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

  1. Store API Tokens Securely: Never commit tokens to version control
  2. Handle Errors Gracefully: Always check the success field in responses
  3. Respect Rate Limits: Implement exponential backoff for retries
  4. Validate Phone Numbers: Ensure phone numbers are in international format
  5. Optimize File Sizes: Keep attachments under 10MB
  6. Use Environment Variables: Store configuration in .env files

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();