REST API

Integrate Siteadda Labs with external applications via REST API

๐Ÿ”Œ

REST API Overview

The REST API module allows you to integrate Siteadda Labs with external applications, websites, and services. You can send messages, manage contacts, retrieve session status, and more through simple HTTP requests.

๐Ÿ” Security First

All API requests require authentication using API keys. Your API keys are stored securely in your local database and should never be shared publicly.

๐Ÿš€

Getting Started

  1. Enable the REST API Server

    Navigate to REST API โ†’ Settings tab and enable the REST API server. Configure the port (default: 3000) and other settings as needed.

  2. Generate an API Key

    Go to the API Keys tab, select a device, and click "Generate" to create a new API key for that device.

  3. Test the API

    Use the Documentation tab to test API endpoints directly from the interface. Each endpoint has a "Test Now" button for quick testing.

  4. Integrate with Your Application

    Use the generated API key in your application's HTTP requests to interact with Siteadda Labs.

โš™๏ธ

Server Settings

๐Ÿ”Œ

Server Port

Configure the port number for the REST API server (default: 3000). Make sure the port is not used by other applications.

โฑ๏ธ

Rate Limiting

Set maximum requests per minute to prevent API abuse and ensure stable performance.

๐ŸŒ

External Access

Enable external access to allow API requests from outside your local network. Use with caution and ensure proper security.

๐Ÿ””

Webhooks

Configure webhook URLs to receive real-time notifications about message events and status updates.

๐Ÿ”‘

API Keys Management

API keys are device-specific and provide secure access to the REST API. Each key is associated with a single WhatsApp device.

โš ๏ธ Security Best Practices
  • Never share your API keys publicly or commit them to version control
  • Generate separate API keys for different applications or environments
  • Regenerate API keys immediately if you suspect they have been compromised
  • Store API keys securely using environment variables or secure vaults

Generating API Keys

  1. Navigate to REST API โ†’ API Keys tab
  2. Select a device from the dropdown menu
  3. Click the "Generate" button
  4. Copy the generated API key immediately (it won't be shown again)
  5. Store the API key securely in your application
๐Ÿ“ก

Available API Endpoints

1. Send Message

POST /api/send-message

Send a text message to a single recipient.

{
  "phone": "1234567890",
  "message": "Hello from Siteadda Labs!"
}

2. Send Media

POST /api/send-media

Send images, videos, or documents to a recipient.

{
  "phone": "1234567890",
  "mediaUrl": "https://example.com/image.jpg",
  "caption": "Check this out!",
  "mediaType": "image"
}

3. Send Buttons

POST /api/send-buttons

Send interactive button messages.

{
  "phone": "1234567890",
  "message": "Choose an option:",
  "buttons": [
    {"id": "1", "text": "Option 1"},
    {"id": "2", "text": "Option 2"}
  ]
}

4. Get Session Status

GET /api/session-status

Check if the WhatsApp session is active and connected.

5. List Groups

GET /api/list-groups

Retrieve a list of all WhatsApp groups the device is part of.

๐Ÿ”

Authentication

All API requests must include your API key in the request headers:

X-API-Key: your-api-key-here

Example Request (cURL)

curl -X POST http://localhost:3000/api/send-message \
  -H "Content-Type: application/json" \
  -H "X-API-Key: your-api-key-here" \
  -d '{
    "phone": "1234567890",
    "message": "Hello from Siteadda Labs!"
  }'
๐Ÿ’ป

Code Examples

JavaScript (Node.js)

const axios = require('axios');

const sendMessage = async () => {
  try {
    const response = await axios.post(
      'http://localhost:3000/api/send-message',
      {
        phone: '1234567890',
        message: 'Hello from Siteadda Labs!'
      },
      {
        headers: {
          'X-API-Key': 'your-api-key-here',
          'Content-Type': 'application/json'
        }
      }
    );
    console.log('Message sent:', response.data);
  } catch (error) {
    console.error('Error:', error.response?.data || error.message);
  }
};

sendMessage();

Python

import requests

url = 'http://localhost:3000/api/send-message'
headers = {
    'X-API-Key': 'your-api-key-here',
    'Content-Type': 'application/json'
}
data = {
    'phone': '1234567890',
    'message': 'Hello from Siteadda Labs!'
}

response = requests.post(url, json=data, headers=headers)
print('Response:', response.json())

PHP

<?php
$url = 'http://localhost:3000/api/send-message';
$data = array(
    'phone' => '1234567890',
    'message' => 'Hello from Siteadda Labs!'
);

$options = array(
    'http' => array(
        'header'  => "Content-Type: application/json\r\n" .
                     "X-API-Key: your-api-key-here\r\n",
        'method'  => 'POST',
        'content' => json_encode($data)
    )
);

$context  = stream_context_create($options);
$result = file_get_contents($url, false, $context);
echo $result;
?>
โš ๏ธ

Error Handling

The API returns standard HTTP status codes and JSON error messages:

โœ…

200 OK

Request successful, message sent or data retrieved.

โŒ

400 Bad Request

Invalid request parameters or missing required fields.

๐Ÿ”’

401 Unauthorized

Invalid or missing API key.

โฑ๏ธ

429 Too Many Requests

Rate limit exceeded. Wait before making more requests.

Error Response Format

{
  "success": false,
  "error": "Error message description",
  "code": "ERROR_CODE"
}
โญ

Best Practices

โœ… Do's
  • Always validate phone numbers before sending messages
  • Implement retry logic with exponential backoff for failed requests
  • Use webhooks to receive real-time status updates instead of polling
  • Monitor your API usage and respect rate limits
  • Keep your API keys secure and rotate them regularly
  • Test endpoints using the built-in Documentation tab before integration
โŒ Don'ts
  • Don't hardcode API keys in your source code
  • Don't send spam or unsolicited messages
  • Don't exceed rate limits - it may result in temporary blocking
  • Don't share API keys across multiple applications without proper tracking
  • Don't ignore error responses - always implement proper error handling
๐Ÿ”ง

Troubleshooting

Common Issues

Server Not Starting
  • Check if the port is already in use by another application
  • Verify that the REST API module is enabled in your license
  • Check the application logs for error messages
401 Unauthorized Errors
  • Verify that the API key is correct and hasn't been regenerated
  • Ensure the X-API-Key header is included in the request
  • Check that the device associated with the API key is connected
Messages Not Sending
  • Verify the WhatsApp session is active (check session status endpoint)
  • Ensure the phone number format is correct (no spaces or special characters)
  • Check that the device has an active internet connection
  • Review the error message in the API response for specific details
๐Ÿ’ฌ

Need Help?

If you encounter any issues or have questions about the REST API:

  • Check the built-in Documentation tab for interactive API testing
  • Review the application logs for detailed error messages
  • Visit the Troubleshooting page for common solutions
  • Contact Siteadda Labs support for technical assistance