Quick Reference
NotifyHub API - Quick Reference
A one-page cheat sheet for the most common NotifyHub API operations.
Base URL
https://api.notifyhub.com
Authentication
Sign Up
POST /auth/signup
{
"firstName": "John", "lastName": "Doe",
"email": "john@example.com", "password": "SecurePass123!",
"countryCode": "+254", "phoneNumber": "712345678",
"companyName": "Acme", "sector": "Tech", "country": "Kenya"
}Login
POST /auth/login
{
"email": "john@example.com",
"password": "SecurePass123!"
}
→ Returns: { "token": "...", "user": {...} }Use Token
Authorization: Bearer YOUR_TOKEN_HEREUse API Key
# Header
UNIFIED-API-Key: YOUR_API_KEY_HERE
# Query Parameter
http://localhost:3040/notifications/send?apikey=YOUR_API_KEY_HERESend Messages
SMS
POST /notifications/send
{
"type": "sms",
"to": "+254712345678",
"message": "Your OTP: 483920"
}POST /notifications/send
{
"type": "email",
"to": "user@example.com",
"subject": "Welcome!",
"message": "<h1>Hello!</h1>"
}POST /notifications/send
{
"type": "whatsapp",
"to": "+254712345678",
"message": "Order shipped!"
}Bulk Send
POST /notifications/send
{
"type": "sms",
"to": ["+254712345678", "+254723456789"],
"message": "Bulk message"
}Contacts
Create Contact
POST /contacts
{
"name": "John Doe",
"email": "john@example.com",
"phone": "712345678",
"countryCode": "+254",
"tags": ["vip"]
}List Contacts
GET /contactsUpdate Contact
PUT /contacts/:id
{
"name": "John Updated",
"tags": ["vip", "premium"]
}Delete Contact
DELETE /contacts/:idGroups
Create Group
POST /groups
{
"name": "VIP Customers",
"description": "High-value clients",
"color": "bg-blue-500/10 text-blue-500 border-blue-500/20"
}List Groups
GET /groupsDelete Group
DELETE /groups/:idCampaigns
Create Campaign
POST /campaigns
{
"name": "Winter Sale",
"type": "broadcast",
"channels": ["email", "sms"],
"recipients": {
"contacts": [],
"groups": ["GROUP_ID"],
"manual": []
},
"messages": {
"email": {
"subject": "Sale!",
"content": "<h1>50% off!</h1>"
},
"sms": {
"content": "Sale! 50% off"
}
},
"scheduleDate": "2026-02-01T09:00:00Z"
}Launch Campaign
POST /campaigns/:id/launchCancel Campaign
POST /campaigns/:id/cancelList Campaigns
GET /campaignsMessage Logs
Get All Logs
GET /message-logsFilter Logs
GET /message-logs?channel=email&status=failed&dateFrom=2026-01-01&dateTo=2026-01-31Users
List Users
GET /users
# Admin onlyGet Current User
GET /users/meCreate User
POST /users
{
"firstName": "Jane", "lastName": "Smith",
"email": "jane@example.com", "password": "Pass123!",
"countryCode": "+254", "phoneNumber": "723456789",
"role": "user"
}
# Admin onlyChange Password
PUT /users/:id/password
{
"oldPassword": "OldPass123!",
"newPassword": "NewPass456!"
}Organization
Get Organization
GET /organizations/currentUpdate Credentials
PUT /organizations/current/credentials
{
"sms_apiKey": "new-key",
"email_host": "smtp.custom.com",
"email_user": "sender@custom.com",
"email_pass": "app-password"
}
# Admin onlyCommon Patterns
Error Handling
try {
const response = await fetch(url, options);
if (!response.ok) {
const error = await response.json();
throw new Error(error.message);
}
return await response.json();
} catch (error) {
console.error('API error:', error);
}Retry Logic
async function withRetry(fn, maxRetries = 3) {
for (let i = 0; i < maxRetries; i++) {
try {
return await fn();
} catch (error) {
if (i === maxRetries - 1) throw error;
await new Promise(r => setTimeout(r, 1000 * (i + 1)));
}
}
}Pagination (Future)
GET /contacts?page=1&limit=50HTTP Status Codes
| Code | Meaning | |------|---------| | 200 | Success | | 201 | Created | | 400 | Bad Request (invalid input) | | 401 | Unauthorized (invalid token) | | 403 | Forbidden (insufficient permissions) | | 404 | Not Found | | 500 | Server Error |
Code Examples
JavaScript/Node.js
const token = 'YOUR_TOKEN';
// Send SMS
const smsResponse = await fetch('https://api.notifyhub.com/notifications/send', {
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
type: 'sms',
to: '+254712345678',
message: 'Hello!'
})
});
const result = await smsResponse.json();
console.log(result);Python
import requests
token = 'YOUR_TOKEN'
headers = {
'Authorization': f'Bearer {token}',
'Content-Type': 'application/json'
}
# Send Email
response = requests.post(
'https://api.notifyhub.com/notifications/send',
headers=headers,
json={
'type': 'email',
'to': 'user@example.com',
'subject': 'Test',
'message': '<p>Hello!</p>'
}
)
print(response.json())PHP
<?php
$token = 'YOUR_TOKEN';
$ch = curl_init('https://api.notifyhub.com/notifications/send');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
'type' => 'sms',
'to' => '+254712345678',
'message' => 'Hello!'
]));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $token,
'Content-Type: application/json'
]);
$response = curl_exec($ch);
curl_close($ch);
print_r(json_decode($response));
?>Phone Number Format
Valid:
+254712345678✅254712345678✅
Invalid:
712345678❌ (missing country code)+254-712-345-678❌ (dashes not allowed)
Email Attachments
{
"type": "email",
"to": "user@example.com",
"subject": "Invoice",
"message": "<p>Attached invoice</p>",
"attachments": [
{
"filename": "invoice.pdf",
"content": "JVBERi0xLjQK...", // base64
"contentType": "application/pdf"
}
]
}Convert file to base64:
// Browser
const base64 = await new Promise((resolve) => {
const reader = new FileReader();
reader.onload = () => resolve(reader.result.split(',')[1]);
reader.readAsDataURL(file);
});
// Node.js
const base64 = require('fs').readFileSync('file.pdf', 'base64');
// Python
import base64
base64_content = base64.b64encode(open('file.pdf', 'rb').read()).decode()Best Practices
✅ DO:
- Validate input before sending
- Implement retry logic
- Use HTTPS only
- Rotate tokens regularly
- Batch bulk sends (max 100 per request)
- Use campaigns for scheduled sends
❌ DON'T:
- Commit tokens to version control
- Send tokens in URLs
- Ignore error responses
- Spam recipients
- Use production credentials in development
Support
- Docs: https://docs.notifyhub.com
- Email: support@notifyhub.com
- Status: https://status.notifyhub.com
Print this page for quick reference!