Node.js SMS API Integration
Complete Node.js code examples for integrating with the SecureSMSC SMS API using axios.
Fast Integration
Get started in minutes with simple REST API calls
Global Reach
Send SMS to 200+ countries worldwide
Secure
Enterprise-grade SSL/TLS encryption
Reliable
99.9% uptime with delivery tracking
Quick Start: Get your API key from the dashboard to begin integration.
Installation
Install the required dependencies:
Terminal
npm install axios
Send Single SMS
Node.js
const axios = require('axios');
const API_KEY = 'YOUR_API_KEY';
const API_URL = 'https://whitelabled.securesmsc.com/api/v2/sms/send';
async function sendSMS(recipient, message) {
try {
const response = await axios.post(API_URL, {
sender_id: 'SENDER',
recipient: recipient,
message: message,
route: 'transactional'
}, {
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json'
}
});
console.log('Success:', response.data);
return response.data;
} catch (error) {
console.error('Error:', error.response?.data || error.message);
throw error;
}
}
// Usage
sendSMS('1234567890', 'Hello from Node.js!');
Send Bulk SMS
Node.js
const axios = require('axios');
async function sendBulkSMS(recipients, message) {
const response = await axios.post(
'https://whitelabled.securesmsc.com/api/v2/sms/send-bulk',
{
sender_id: 'SENDER',
recipients: recipients,
message: message,
route: 'promotional'
},
{
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json'
}
}
);
return response.data;
}
// Usage
sendBulkSMS(['1234567890', '0987654321'], 'Bulk message!');
Check SMS Status
Node.js
async function checkStatus(messageId) {
const response = await axios.get(
`https://whitelabled.securesmsc.com/api/v2/sms/status/${messageId}`,
{
headers: { 'Authorization': `Bearer ${API_KEY}` }
}
);
console.log('Status:', response.data.data.status);
return response.data;
}
Check Balance
Node.js
async function getBalance() {
const response = await axios.get(
'https://whitelabled.securesmsc.com/api/v2/balance',
{
headers: { 'Authorization': `Bearer ${API_KEY}` }
}
);
console.log('Balance:', response.data.data.balance, 'credits');
return response.data;
}
Error Handling
Node.js - Express.js
const express = require('express');
const axios = require('axios');
const app = express();
app.use(express.json());
class SMSService {
constructor(apiKey) {
this.apiKey = apiKey;
this.baseUrl = 'https://whitelabled.securesmsc.com/api/v2';
}
async send(recipient, message, retries = 3) {
for (let i = 0; i < retries; i++) {
try {
const response = await axios.post(`${this.baseUrl}/sms/send`, {
sender_id: 'SENDER',
recipient,
message,
route: 'transactional'
}, {
headers: {
'Authorization': `Bearer ${this.apiKey}`,
'Content-Type': 'application/json'
},
timeout: 10000
});
return response.data;
} catch (error) {
if (i === retries - 1) throw error;
await new Promise(r => setTimeout(r, Math.pow(2, i) * 1000));
}
}
}
}
// Express endpoint
app.post('/api/send-sms', async (req, res) => {
const sms = new SMSService(process.env.SMS_API_KEY);
try {
const result = await sms.send(req.body.phone, req.body.message);
res.json(result);
} catch (error) {
res.status(500).json({ error: error.message });
}
});
app.listen(3000);