The Bulk SMS Sender API is a powerful tool that allows you to send SMS messages in bulk to multiple recipients quickly and efficiently. Whether you’re sending notifications, alerts, or marketing messages, this API simplifies the process.
Before you start using the Bulk SMS API, make sure you have the following:
To use the Bulk SMS API, you need to provide your Twilio account credentials and a Twilio phone number. These should be included in the headers of your HTTP request:
X-Twilio-AccountSid
: Your Twilio Account SIDX-Twilio-AuthToken
: Your Twilio Auth TokenX-Twilio-Number
: Your Twilio phone number (from which the SMS messages will be sent)To send SMS messages in bulk, make a POST request to the API endpoint. The request should include the following:
numbers
: An array of recipient phone numbers (in E.164 format).message
: The text message you want to send.Here’s an example using cURL:
curl -X POST https://rapid-api-url.com/sendBulkSMS \
-H "X-Twilio-AccountSid: YOUR_TWILIO_ACCOUNT_SID" \
-H "X-Twilio-AuthToken: YOUR_TWILIO_AUTH_TOKEN" \
-H "X-Twilio-Number: YOUR_TWILIO_PHONE_NUMBER" \
-H "Content-Type: application/json" \
-d '{
"numbers": ["+1234567890", "+9876543210"],
"message": "Hello from Bulk SMS API!"
}'
Nodejs example:
const axios = require('axios');
const RAPIDAPI_KEY = 'YOUR_RAPIDAPI_KEY';
const BULK_SMS_API_ENDPOINT = 'https://rapidapi.com/bulksms/sendBulkSMS';
// Twilio credentials
const TWILIO_ACCOUNT_SID = 'YOUR_TWILIO_ACCOUNT_SID';
const TWILIO_AUTH_TOKEN = 'YOUR_TWILIO_AUTH_TOKEN';
const TWILIO_NUMBER = 'YOUR_TWILIO_NUMBER';
async function sendBulkSMS(numbers, message) {
try {
const response = await axios.post(BULK_SMS_API_ENDPOINT, {
numbers: numbers,
message: message
}, {
headers: {
'X-RapidAPI-Key': RAPIDAPI_KEY,
'X-Twilio-AccountSid': TWILIO_ACCOUNT_SID,
'X-Twilio-AuthToken': TWILIO_AUTH_TOKEN,
'X-Twilio-Number': TWILIO_NUMBER,
'Content-Type': 'application/json'
}
});
return response.data;
} catch (error) {
throw error;
}
}
// Usage example
const numbers = ['+1234567890', '+9876543210'];
const message = 'Hello from Bulk SMS API!';
sendBulkSMS(numbers, message)
.then(data => {
console.log('SMS sent successfully!');
console.log(`Successful: ${data.successful}`);
console.log(`Failed: ${data.failed}`);
})
.catch(error => {
console.error('Error sending SMS:', error.message);
});
POST /sendBulkSMS
: Send SMS messages in bulk.Request Body:
{
"numbers": ["string"],
"message": "string"
}
Response:
{
"successful": 2,
"failed": 0,
"messages": [
{
"to": "+1234567890",
"body": "Hello from BulkSMSSender"
"status": "delivered",
"errorMessage": null,
"success": true
},
{
"to": "+9876543210",
"body": "Hello from BulkSMSSender"
"status": "delivered",
"errorMessage": null,
"success": true
}
]
}
The API provides detailed error messages to help you identify and resolve issues. Common error scenarios include:
Check out the examples directory for sample code and usage scenarios.
A: You can sign up for a Twilio account at https://www.twilio.com/. Once registered, you will find your Account SID and Auth Token in your Twilio Dashboard.
A: E.164 is a standardized format for phone numbers. It includes the country code, area code, and the local number. For example, a U.S. phone number in E.164 format looks like this: +1XXXXXXXXXX
.