SMS remains one of the most reliable ways to reach customers instantly. Whether you are sending a single One-Time Password (OTP) for login verification or blasting a marketing campaign to thousands of users, Moolre's SMS API scales with your needs.
Overview
Moolre's SMS API is designed for flexibility. The endpoint supports a messages array, meaning you can send:
- Single Message: An array with one object.
- Bulk Messages: An array with multiple objects.
- Personalized Bulk: Each object in the array can have a completely different message text and recipient.
Prerequisite
You must have a registered Sender ID before sending messages. Unregistered IDs may be blocked by networks or replaced with a generic name.
Transactional SMS (OTP)
Transactional messages require high priority and instant delivery. Common use cases include OTPs, order confirmations, and account alerts.
When sending critical messages, always provide a unique ref ID. This allows you to programmatically check the delivery status later if the user claims they didn't receive it.
const axios = require('axios');async function sendOTP(phoneNumber, otpCode) { try { const response = await axios.post('https://api.moolre.com/open/sms/send', { type: 1, senderid: 'MoolreAuth', // Must be a registered Sender ID messages: [ { recipient: phoneNumber, message: `Your verification code is ${otpCode}. Do not share this code.`, ref: `OTP_${Date.now()}` // Unique reference for tracking } ] }, { headers: { 'X-API-VASKEY': process.env.SMS_API_KEY } }); console.log("SMS Sent:", response.data.message); return response.data; } catch (error) { console.error("Failed to send SMS", error.response?.data || error.message); }}Bulk SMS and marketing
Sending messages one by one in a loop is inefficient and can lead to rate limiting. Instead, batch your messages into a single API call.
The Moolre API accepts an array of message objects. This allows you to personalize the content for each user (e.g., "Hello Kwame" vs "Hello Ama") within the same HTTP request.
const axios = require('axios');// List of users to notifyconst users = [ { phone: "233244000001", name: "Kwame" }, { phone: "233244000002", name: "Ama" }, { phone: "233244000003", name: "Kojo" }];async function sendBulkNotification() { // 1. Construct the messages array const messages = users.map(user => ({ recipient: user.phone, message: `Hello ${user.name}, our end-of-year sale starts tomorrow! Visit our store for 50% off.`, ref: `BULK_${Date.now()}_${user.phone}` })); // 2. Send in a single API call try { const response = await axios.post('https://api.moolre.com/open/sms/send', { type: 1, senderid: 'MoolrePromo', messages: messages }, { headers: { 'X-API-VASKEY': process.env.SMS_API_KEY } }); console.log("Batch Sent Successfully"); } catch (error) { console.error("Bulk SMS Failed", error); }}Tracking delivery
After sending messages, you can verify their delivery using the SMS Status endpoint. Pass the array of ref IDs you generated during sending to get the status of each message. Each result has status, sent (handed to the network) and delivered (the handset's delivery report), all on the scale below.
Delivery status values
- 0
- Pending
- 1
- Sent to the network
- 2
- Delivered to the handset
- 3
- Failed or undelivered
