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.
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
-
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.
-
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.
-
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.
-
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.
- 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
- Navigate to REST API โ API Keys tab
- Select a device from the dropdown menu
- Click the "Generate" button
- Copy the generated API key immediately (it won't be shown again)
- Store the API key securely in your application
Available API Endpoints
1. Send Message
Send a text message to a single recipient.
{
"phone": "1234567890",
"message": "Hello from Siteadda Labs!"
}
2. 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
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
Check if the WhatsApp session is active and connected.
5. 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
- 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'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
- 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
- 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
- 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