API Reference
Complete reference for the AmanahAgent WhatsApp Business API. Integrate messaging capabilities into your applications.
API Overview
🌐 Base URL
https://api.amanahagent.cloud/v1
All API requests should use HTTPS
🔑 Authentication
Bearer token authentication required
Authorization: Bearer YOUR_API_KEY
⚡ Rate Limits
Messages API
Send Message
POST
/messages
Send a WhatsApp message to a recipient.
Request Parameters
Parameter | Type | Required | Description |
---|---|---|---|
to | string | Required | Recipient phone number with country code |
type | string | Required | Message type: text, media, template |
message | string | Optional | Message text content (required for text messages) |
media_url | string | Optional | URL for media messages (image, video, document) |
template_id | string | Optional | Template ID for template messages |
Example Request
JavaScript
const response = await fetch('https://api.amanahagent.cloud/v1/messages', { method: 'POST', headers: { 'Authorization': 'Bearer YOUR_API_KEY', 'Content-Type': 'application/json' }, body: JSON.stringify({ to: '+1234567890', type: 'text', message: 'Hello from AmanahAgent!' }) }); const data = await response.json(); console.log(data);
Python
import requests response = requests.post('https://api.amanahagent.cloud/v1/messages', headers={ 'Authorization': 'Bearer YOUR_API_KEY', 'Content-Type': 'application/json' }, json={ 'to': '+1234567890', 'type': 'text', 'message': 'Hello from AmanahAgent!' } ) data = response.json() print(data)
PHP
<?php $ch = curl_init('https://api.amanahagent.cloud/v1/messages'); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([ 'to' => '+1234567890', 'type' => 'text', 'message' => 'Hello from AmanahAgent!' ])); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Authorization: Bearer YOUR_API_KEY', 'Content-Type: application/json' ]); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); $data = json_decode($response, true); curl_close($ch); print_r($data); ?>
Example Response
{ "message_id": "msg_abc123xyz789", "status": "sent", "to": "+1234567890", "type": "text", "timestamp": "2024-01-15T10:30:00Z", "credits_used": 1, "delivery_status": "pending" }
Get Message Status
GET
/messages/{message_id}
Retrieve the delivery status and details of a sent message.
Example Response
{ "message_id": "msg_abc123xyz789", "status": "delivered", "to": "+1234567890", "type": "text", "message": "Hello from AmanahAgent!", "sent_at": "2024-01-15T10:30:00Z", "delivered_at": "2024-01-15T10:30:15Z", "read_at": null, "credits_used": 1 }
Contacts API
Create Contact
POST
/contacts
Add a new contact to your address book.
Request Parameters
Parameter | Type | Required | Description |
---|---|---|---|
phone | string | Required | Phone number with country code |
name | string | Optional | Contact's full name |
tags | array | Optional | Tags for organizing contacts |
custom_fields | object | Optional | Custom field values |
Example Request
{ "phone": "+1234567890", "name": "John Doe", "tags": ["customer", "premium"], "custom_fields": { "company": "Acme Corp", "department": "Sales" } }
List Contacts
GET
/contacts
Retrieve a paginated list of your contacts.
Query Parameters
Parameter | Type | Default | Description |
---|---|---|---|
page | integer | 1 | Page number |
limit | integer | 50 | Number of contacts per page (max 100) |
search | string | - | Search by name or phone |
tags | string | - | Filter by tags (comma-separated) |
Media API
Upload Media
POST
/media
Upload images, videos, documents, or audio files to use in messages.
Supported formats: Images (JPG, PNG, GIF), Videos (MP4, 3GP), Documents (PDF, DOC, XLS, PPT), Audio (MP3, OGG, AMR)
Request Parameters
Parameter | Type | Required | Description |
---|---|---|---|
file | file | Required | Media file (max 16MB) |
filename | string | Optional | Custom filename |
Example Request (JavaScript)
const formData = new FormData(); formData.append('file', fileInput.files[0]); formData.append('filename', 'custom-name.jpg'); const response = await fetch('https://api.amanahagent.cloud/v1/media', { method: 'POST', headers: { 'Authorization': 'Bearer YOUR_API_KEY' }, body: formData }); const data = await response.json(); console.log(data);
Example Response
{ "media_id": "media_xyz789abc123", "url": "https://cdn.amanahagent.cloud/media/xyz789abc123.jpg", "filename": "custom-name.jpg", "content_type": "image/jpeg", "size": 245760, "created_at": "2024-01-15T10:30:00Z" }
Templates API
Create Template
POST
/templates
Create a message template for reuse. Templates must be approved by WhatsApp before use.
Request Parameters
Parameter | Type | Required | Description |
---|---|---|---|
name | string | Required | Template name (lowercase, underscore separated) |
language | string | Required | Language code (e.g., "en", "ar") |
category | string | Required | Category: MARKETING, UTILITY, AUTHENTICATION |
components | array | Required | Template components (header, body, footer, buttons) |
Example Request
{ "name": "welcome_message", "language": "en", "category": "UTILITY", "components": [ { "type": "HEADER", "format": "TEXT", "text": "Welcome to {{1}}" }, { "type": "BODY", "text": "Hello {{1}}, thanks for joining us! Your account is now active." }, { "type": "FOOTER", "text": "AmanahAgent Team" } ] }
List Templates
GET
/templates
Retrieve all your message templates with their approval status.
Example Response
{ "templates": [ { "id": "tpl_abc123xyz789", "name": "welcome_message", "language": "en", "category": "UTILITY", "status": "APPROVED", "created_at": "2024-01-10T10:30:00Z", "approved_at": "2024-01-12T14:20:00Z" } ], "pagination": { "page": 1, "limit": 50, "total": 1, "total_pages": 1 } }
Webhooks API
Configure Webhook
POST
/webhooks
Configure webhook endpoints to receive real-time updates about message status, delivery receipts, and incoming messages.
Request Parameters
Parameter | Type | Required | Description |
---|---|---|---|
url | string | Required | HTTPS URL to receive webhook events |
events | array | Required | Event types to subscribe to |
secret | string | Optional | Secret for webhook signature verification |
Available Events
message.sent
- Message successfully sentmessage.delivered
- Message delivered to recipientmessage.read
- Message read by recipientmessage.failed
- Message delivery failedmessage.received
- Incoming message from user
Example Request
{ "url": "https://your-app.com/webhooks/amanahagent", "events": [ "message.sent", "message.delivered", "message.read", "message.received" ], "secret": "your-webhook-secret" }
Webhook Payload Example
{ "event": "message.delivered", "timestamp": "2024-01-15T10:30:15Z", "data": { "message_id": "msg_abc123xyz789", "status": "delivered", "to": "+1234567890", "delivered_at": "2024-01-15T10:30:15Z" } }
Analytics API
Get Usage Statistics
GET
/analytics/usage
Retrieve usage statistics and metrics for your account.
Query Parameters
Parameter | Type | Default | Description |
---|---|---|---|
period | string | 7d | Time period: 1d, 7d, 30d, 90d |
start_date | string | - | Custom start date (YYYY-MM-DD) |
end_date | string | - | Custom end date (YYYY-MM-DD) |
Example Response
{ "period": "7d", "start_date": "2024-01-08", "end_date": "2024-01-15", "metrics": { "messages_sent": 1250, "messages_delivered": 1180, "messages_read": 950, "messages_failed": 70, "delivery_rate": 94.4, "read_rate": 80.5, "credits_used": 1250, "unique_contacts": 485 }, "daily_breakdown": [ { "date": "2024-01-15", "messages_sent": 180, "messages_delivered": 175, "credits_used": 180 } ] }
Error Codes
The API uses standard HTTP status codes to indicate success or failure. Error responses include a JSON object with error details.
HTTP Status Codes
Code | Status | Description |
---|---|---|
200 | OK | Request successful |
201 | Created | Resource created successfully |
400 | Bad Request | Invalid request parameters |
401 | Unauthorized | Invalid or missing API key |
403 | Forbidden | Insufficient permissions |
404 | Not Found | Resource not found |
429 | Too Many Requests | Rate limit exceeded |
500 | Internal Server Error | Server error |
Error Response Format
{ "error": { "code": "INVALID_PHONE_NUMBER", "message": "The phone number format is invalid", "details": { "field": "to", "value": "invalid-number" } } }