WhatsApp API Documentation

Back
Base URL: https://whatsappmanager.olspark.net/api/v1/whatsapp

Authentication

All API requests require authentication using your API credentials. Include both publicKey and secretKey as query parameters.

Headers:
No headers required - use query parameters
Query Parameters:
ParameterTypeRequiredDescription
publicKeystringYesYour API public key
secretKeystringYesYour API secret key

Get Instance Information

Retrieve instance details including connection status and WhatsApp number.

Endpoint:
GET /api/v1/whatsapp/instance
Response Example:
{
    "success": true,
    "message": "Instance information retrieved successfully",
    "data": {
        "id": 1,
        "instanceId": "abc123-def456",
        "instanceName": "Main WhatsApp",
        "status": "Connected",
        "isConnected": true,
        "whatsappNumber": "1234567890",
        "createdAt": "2024-01-01T12:00:00",
        "connectedAt": "2024-01-01T12:05:00",
        "subscription": {
            "type": "Premium",
            "period": "Monthly",
            "monthlyQuota": 1000,
            "messagesUsed": 245,
            "messagesRemaining": 755,
            "usagePercentage": 24.5,
            "startDate": "2024-01-01T00:00:00",
            "endDate": "2024-02-01T00:00:00",
            "isActive": true,
            "isExpired": false,
            "autoRenew": true
        }
    }
}

Get QR Code

Get QR code to connect WhatsApp to this instance.

Endpoint:
GET /api/v1/whatsapp/instance/qrcode
Response Example:
{
    "success": true,
    "message": "QR code generated successfully",
    "data": {
        "qrCode": "data:image/png;base64,iVBORw0KGgo...",
        "expiresIn": 60
    }
}

Send Message

Send a WhatsApp message to a phone number.

Endpoint:
POST /api/v1/whatsapp/send
Request Body:
{
    "phoneNumber": "1234567890",
    "message": "Hello from API!"
}
Response Example:
{
    "success": true,
    "message": "Message sent successfully",
    "data": {
        "messageId": "123",
        "status": "sent",
        "phoneNumber": "1234567890",
        "message": "Hello from API!",
        "sentAt": "2024-01-01T12:00:00",
        "quotaRemaining": 755,
        "quotaUsed": 245,
        "quotaTotal": 1000
    }
}

Get Quota Status

Check current quota usage and subscription status.

Endpoint:
GET /api/v1/whatsapp/quota
Response Example:
{
    "success": true,
    "message": "Quota status retrieved successfully",
    "data": {
        "monthlyQuota": 1000,
        "messagesUsed": 245,
        "messagesRemaining": 755,
        "usagePercentage": 24.5,
        "periodStart": "2024-01-01T00:00:00",
        "periodEnd": "2024-02-01T00:00:00",
        "hasQuotaAvailable": true,
        "isSubscriptionActive": true
    }
}

Renew Subscription

Renew or upgrade your subscription plan.

Endpoint:
POST /api/v1/whatsapp/subscription/renew
Request Body:
{
    "subscriptionType": 2,  // 1=Basic, 2=Standard, 3=Premium, 4=Enterprise
    "period": 1,            // 1=Monthly, 2=Yearly
    "monthlyQuota": 1000,
    "amount": 49.99,
    "autoRenew": true
}

Error Codes

Error CodeDescription
INSTANCE_NOT_CONNECTEDWhatsApp instance is not connected. Scan QR code first.
QUOTA_EXCEEDEDMonthly message quota exceeded or subscription expired.
ALREADY_CONNECTEDInstance is already connected to WhatsApp.
INVALID_CREDENTIALSInvalid or revoked API credentials.

Code Examples


# Get instance status
curl -X GET "https://yourdomain.com/api/v1/whatsapp/instance?publicKey=YOUR_KEY&secretKey=YOUR_SECRET"

# Send message
curl -X POST "https://yourdomain.com/api/v1/whatsapp/send?publicKey=YOUR_KEY&secretKey=YOUR_SECRET" \
  -H "Content-Type: application/json" \
  -d '{"phoneNumber":"1234567890","message":"Hello World!"}'

# Get quota status
curl -X GET "https://yourdomain.com/api/v1/whatsapp/quota?publicKey=YOUR_KEY&secretKey=YOUR_SECRET"
                            

// Send message using fetch
async function sendWhatsAppMessage(publicKey, secretKey, phoneNumber, message) {
    const response = await fetch(
        `https://yourdomain.com/api/v1/whatsapp/send?publicKey=${publicKey}&secretKey=${secretKey}`,
        {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
            },
            body: JSON.stringify({ phoneNumber, message })
        }
    );
    
    const data = await response.json();
    console.log(data);
}

// Get instance status
async function getInstanceStatus(publicKey, secretKey) {
    const response = await fetch(
        `https://yourdomain.com/api/v1/whatsapp/instance?publicKey=${publicKey}&secretKey=${secretKey}`
    );
    return await response.json();
}
                            

import requests

class WhatsAppAPI:
    def __init__(self, public_key, secret_key, base_url):
        self.public_key = public_key
        self.secret_key = secret_key
        self.base_url = base_url
    
    def send_message(self, phone_number, message):
        url = f"{self.base_url}/api/v1/whatsapp/send"
        params = {
            'publicKey': self.public_key,
            'secretKey': self.secret_key
        }
        data = {
            'phoneNumber': phone_number,
            'message': message
        }
        response = requests.post(url, params=params, json=data)
        return response.json()
    
    def get_quota(self):
        url = f"{self.base_url}/api/v1/whatsapp/quota"
        params = {
            'publicKey': self.public_key,
            'secretKey': self.secret_key
        }
        response = requests.get(url, params=params)
        return response.json()

# Usage
api = WhatsAppAPI("YOUR_PUBLIC_KEY", "YOUR_SECRET_KEY", "https://yourdomain.com")
result = api.send_message("1234567890", "Hello from Python!")
print(result)
                            

using System;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;

public class WhatsAppApiClient
{
    private readonly HttpClient _httpClient;
    private readonly string _publicKey;
    private readonly string _secretKey;
    private readonly string _baseUrl;

    public WhatsAppApiClient(string baseUrl, string publicKey, string secretKey)
    {
        _baseUrl = baseUrl;
        _publicKey = publicKey;
        _secretKey = secretKey;
        _httpClient = new HttpClient();
    }

    public async Task SendMessageAsync(string phoneNumber, string message)
    {
        var url = $"{_baseUrl}/api/v1/whatsapp/send?publicKey={_publicKey}&secretKey={_secretKey}";
        var data = new { phoneNumber, message };
        var json = JsonSerializer.Serialize(data);
        var content = new StringContent(json, Encoding.UTF8, "application/json");
        
        var response = await _httpClient.PostAsync(url, content);
        return await response.Content.ReadAsStringAsync();
    }

    public async Task GetQuotaAsync()
    {
        var url = $"{_baseUrl}/api/v1/whatsapp/quota?publicKey={_publicKey}&secretKey={_secretKey}";
        var response = await _httpClient.GetAsync(url);
        return await response.Content.ReadAsStringAsync();
    }
}