Learn how to send SMS messages using the Zend.
Send a simple SMS message to a single recipient:
POST /messages
{
"to": "+233593152134",
"body": "Hello! This is a test SMS message.",
"preferred_channels": ["sms"]
}
Response:
{
"id": "6884da240f0e633b7b979bff",
"status": "pending",
"estimated_cost": 0.02,
"message": "Message queued for processing"
}
Use a specific sender ID for your messages:
{
"to": "+233593152134",
"body": "Your order has been confirmed!",
"preferred_channels": ["sms"],
"sender_id": "RODIN"
}
Send SMS with automatic fallback to WhatsApp if SMS fails:
{
"to": "+233593152134",
"body": "Important notification: Your order has been shipped!",
"preferred_channels": ["sms", "whatsapp"],
"fallback_enabled": true,
"delivery_priority": "reliability"
}
Set message priority for faster processing:
{
"to": "+233593152134",
"body": "URGENT: System maintenance in 30 minutes",
"preferred_channels": ["sms"],
"priority": "urgent"
}
Priority levels: low
, normal
, high
, urgent
Send SMS at a specific time:
{
"to": "+233593152134",
"body": "Reminder: Your appointment is in 1 hour",
"preferred_channels": ["sms"],
"scheduled_for": "2024-01-15T13:00:00Z"
}
Receive delivery status updates via webhook:
{
"to": "+233593152134",
"body": "Your order has been shipped!",
"preferred_channels": ["sms"],
"webhook_url": "https://yourapp.com/webhooks/message-status"
}
Optimize for lowest cost:
{
"to": "+233593152134",
"body": "Your monthly statement is ready",
"preferred_channels": ["sms"],
"delivery_priority": "cost",
"fallback_enabled": false
}
// Check your message length
const message = "Your verification code is: 123456";
console.log(`Characters: ${message.length}`);
console.log(`SMS parts: ${Math.ceil(message.length / 160)}`);
Always use international format:
+233593152134
233593152134
0593152134
try {
const response = await fetch('/messages', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
to: '+233593152134',
body: 'Test message',
preferred_channels: ['sms']
})
});
if (!response.ok) {
const error = await response.json();
console.error('SMS failed:', error.message);
}
} catch (error) {
console.error('Network error:', error);
}
GET /messages/{id}
Response:
{
"id": "6884da240f0e633b7b979bff",
"status": "delivered",
"channel_used": "sms",
"to": "+233593152134",
"body": "Your verification code is: 123456",
"total_cost": 0.02,
"delivery_attempts": [
{
"channel": "sms",
"status": "delivered",
"attempted_at": "2024-01-15T10:30:00Z",
"cost": 0.02
}
],
"created_at": "2024-01-15T10:29:55Z",
"sent_at": "2024-01-15T10:30:00Z",
"delivered_at": "2024-01-15T10:30:05Z"
}
PUT /messages/{id}/retry
{
"statusCode": 400,
"message": "Insufficient credits. Required: 0.020, Available: 0.015. Please purchase more credits.",
"error": "Bad Request"
}
{
"statusCode": 400,
"message": "Invalid phone number format. Please use international format (e.g., +233593152134)",
"error": "Bad Request"
}
{
"statusCode": 400,
"message": "Sender ID 'INVALID' is not approved. Please use an approved sender ID.",
"error": "Bad Request"
}
{
"name": "order_confirmation_sms",
"description": "Simple order confirmation SMS",
"category": "transactional",
"variables": [
{"name": "order_number", "type": "text", "required": true},
{"name": "tracking_url", "type": "url", "required": true}
],
"channel_variants": [
{
"channel": "sms",
"content": "Order #{{order_number}} confirmed! Track at: {{tracking_url}}"
}
]
}
{
"to": "+233593152134",
"body": "Order confirmation",
"template_id": "123456789123412",
"template_params": {
"order_number": "ORD-2024-001",
"tracking_url": "https://track.yourapp.com/ORD-2024-001"
},
"preferred_channels": ["sms"]
}