Complete REST API for sending push notifications, managing subscribers, and analytics.
https://your-domain.com/notification/api/
All API requests require authentication using API keys. Include your API key in the request headers.
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json
Send notifications to devices, email subscribers, or broadcast to all users.
{
"title": "Your Notification Title",
"message": "Your notification message",
"type": "push|email|web",
"target_type": "single|bulk|broadcast",
"recipients": ["token1", "token2"] // Required for single/bulk
}
{
"payload": {
"action": "open_url",
"url": "https://example.com",
"custom_data": "any_value"
},
"scheduled_at": "2024-12-31 23:59:59",
"priority": "high|normal|low"
}
{
"success": true,
"message": "Notification sent successfully",
"data": {
"notification_id": 123,
"recipients_count": 2,
"estimated_delivery": "2024-01-15 10:30:00"
}
}
Add, update, or remove device tokens and email subscribers.
{
"action": "add_device",
"token": "device_token_here",
"device_type": "android|ios|web",
"device_info": {
"model": "iPhone 12",
"os_version": "15.0",
"app_version": "1.0.0"
}
}
{
"action": "add_email",
"email": "user@example.com"
}
{
"action": "remove",
"token": "device_token_here"
}
Get list of subscribers for your account.
type
- Filter by device type (android, ios, web, email)status
- Filter by status (active, inactive)limit
- Number of results (default: 50, max: 1000)offset
- Pagination offsetGet detailed analytics about your notifications and usage.
period
- Time period (today, week, month, year)start_date
- Start date (YYYY-MM-DD)end_date
- End date (YYYY-MM-DD)type
- Notification type filter{
"success": true,
"data": {
"summary": {
"total_sent": 1500,
"total_delivered": 1420,
"total_failed": 80,
"delivery_rate": 94.67
},
"by_type": {
"push": 1200,
"email": 250,
"web": 50
},
"daily_stats": [
{
"date": "2024-01-15",
"sent": 150,
"delivered": 142,
"failed": 8
}
]
}
}
Code | Meaning | Description |
---|---|---|
200 | OK | Request successful |
400 | Bad Request | Invalid request format or missing parameters |
401 | Unauthorized | Invalid or missing API key |
403 | Forbidden | API key doesn't have required permissions |
429 | Too Many Requests | Rate limit exceeded |
500 | Internal Server Error | Server error occurred |
{
"success": false,
"error": {
"code": "INVALID_TOKEN",
"message": "The provided device token is invalid",
"details": "Token format must be 152-164 characters"
}
}
'Hello World',
'message' => 'This is a test notification',
'type' => 'push',
'target_type' => 'broadcast'
]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
$result = json_decode($response, true);
if ($result['success']) {
echo "Notification sent!";
}
?>
const sendNotification = async () => {
try {
const response = await fetch('/notification/api/send-notification.php', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
title: 'Hello World',
message: 'This is a test notification',
type: 'push',
target_type: 'broadcast'
})
});
const result = await response.json();
if (result.success) {
console.log('Notification sent!');
}
} catch (error) {
console.error('Error:', error);
}
};
import requests
import json
url = 'https://your-domain.com/notification/api/send-notification.php'
headers = {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
}
data = {
'title': 'Hello World',
'message': 'This is a test notification',
'type': 'push',
'target_type': 'broadcast'
}
response = requests.post(url, headers=headers, json=data)
result = response.json()
if result['success']:
print('Notification sent!')
curl -X POST \
https://your-domain.com/notification/api/send-notification.php \
-H 'Authorization: Bearer YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"title": "Hello World",
"message": "This is a test notification",
"type": "push",
"target_type": "broadcast"
}'