💬 Send SMS
Prerequisites
- A NotificationAPI account - sign up for free
- An SMS notification configured in the dashboard (see Configure Notification)
Overview
SMS notifications provide instant, direct communication with your users. NotificationAPI makes it easy to send personalized SMS messages with features like proper phone number formatting, delivery tracking, and global reach.
This guide covers everything you need to know about sending SMS notifications, from basic setup to advanced features.
Step 1: Verify Your SMS Notification
If you haven’t already configured an SMS notification, follow our Configure Notification guide to create one with the SMS channel enabled.
Once configured, note the Notification Type - you’ll need this in your code (e.g., welcome_sms
, order_update
, security_alert
).
Step 2: Install the SDK
Install the node package using one of the following package managers:
npm install notificationapi-node-server-sdk
yarn add notificationapi-node-server-sdk
pnpm add notificationapi-node-server-sdk
pip install notificationapi_python_server_sdk
composer require notificationapi/notificationapi-php-server-sdk
go get github.com/notificationapi-com/notificationapi-go-server-sdk
dotnet add package NotificationAPI --version 0.5.0
Add the following dependency to your Maven project:
<dependency>
<groupId>com.notificationapi</groupId>
<artifactId>notificationapi-java-server-sdk</artifactId>
<version>0.2.0</version>
</dependency>
For optimal functionality, you’ll also need:
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.14</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.15.2</version>
</dependency>
Add the NotificationAPI class to your application - see the full Ruby implementation.
Step 3: Send a Basic SMS
Here’s how to send a basic SMS notification:
import notificationapi from 'notificationapi-node-server-sdk';
// Initialize (default US region)
// For CA region: add 'https://api.ca.notificationapi.com' after CLIENT_SECRET
// For EU region: add 'https://api.eu.notificationapi.com' after CLIENT_SECRET
notificationapi.init('YOUR_CLIENT_ID', 'YOUR_CLIENT_SECRET');
// Send SMS notification
notificationapi.send({
type: 'welcome_sms',
to: {
id: 'user123',
number: '+16175551212' // Required for SMS notifications (E.164 format)
},
parameters: {
firstName: 'John',
companyName: 'Acme Corp'
}
});
import asyncio
from notificationapi_python_server_sdk import notificationapi
# Initialize (default US region)
notificationapi.init("YOUR_CLIENT_ID", "YOUR_CLIENT_SECRET")
async def send_sms():
await notificationapi.send({
"type": "welcome_sms",
"to": {
"id": "user123",
"number": "+16175551212" # Required for SMS notifications (E.164 format)
},
"parameters": {
"firstName": "John",
"companyName": "Acme Corp"
}
})
# Run the async function
asyncio.run(send_sms())
use NotificationAPI\NotificationAPI;
// Initialize
$notificationapi = new NotificationAPI('YOUR_CLIENT_ID', 'YOUR_CLIENT_SECRET');
// Send SMS notification
$notificationapi->send([
"type" => "welcome_sms",
"to" => [
"id" => "user123",
"number" => "+16175551212" // Required for SMS notifications (E.164 format)
],
"parameters" => [
"firstName" => "John",
"companyName" => "Acme Corp"
]
]);
package main
import (
notificationapi "github.com/notificationapi-com/notificationapi-go-server-sdk"
)
func main() {
// Initialize
notificationapi.Init("YOUR_CLIENT_ID", "YOUR_CLIENT_SECRET", "https://api.notificationapi.com")
// Prepare parameters
parameters := make(map[string]interface{})
parameters["firstName"] = "John"
parameters["companyName"] = "Acme Corp"
// Send SMS notification
notificationapi.Send(
notificationapi.SendRequest{
Type: "welcome_sms",
To: notificationapi.User{
Id: "user123",
Number: "+16175551212", // Required for SMS notifications (E.164 format)
},
Parameters: parameters,
},
)
}
using NotificationApi.Server;
using NotificationApi.Server.Models;
// Initialize
var notificationApi = new NotificationApiServer("YOUR_CLIENT_ID", "YOUR_CLIENT_SECRET");
// Create user
var user = new NotificationUser("user123")
{
TelephoneNumber = "+16175551212" // Required for SMS notifications (E.164 format)
};
// Create parameters
var parameters = new Dictionary<string, object>
{
{ "firstName", "John" },
{ "companyName", "Acme Corp" }
};
// Send SMS notification
await notificationApi.Send(new SendNotificationData("welcome_sms", user)
{
Type = "welcome_sms",
To = user,
Parameters = parameters
});
import com.notificationapi.NotificationApi;
import com.notificationapi.model.NotificationRequest;
import com.notificationapi.model.User;
import java.util.HashMap;
import java.util.Map;
// Initialize
NotificationApi api = new NotificationApi("YOUR_CLIENT_ID", "YOUR_CLIENT_SECRET");
// Create user
User user = new User("user123")
.setNumber("+16175551212"); // Required for SMS notifications (E.164 format)
// Create parameters
Map<String, Object> parameters = new HashMap<>();
parameters.put("firstName", "John");
parameters.put("companyName", "Acme Corp");
// Send SMS notification
NotificationRequest request = new NotificationRequest("welcome_sms", user)
.setType("welcome_sms")
.setTo(user)
.setParameters(parameters);
String response = api.send(request);
# Initialize
notificationapi = NotificationAPI.new("YOUR_CLIENT_ID", "YOUR_CLIENT_SECRET")
# Send SMS notification
notificationapi.send({
type: 'welcome_sms',
to: {
id: 'user123',
number: '+16175551212' # Required for SMS notifications (E.164 format)
},
parameters: {
firstName: 'John',
companyName: 'Acme Corp'
}
})
Get your CLIENT_ID and CLIENT_SECRET from your Environment Settings.
Phone Number Formatting
Proper phone number formatting is crucial for SMS delivery. Always use the international E.164 format with a plus sign and country code.
E.164 Format (Required)
Use the E.164 format for all phone numbers:
// ✅ Correct E.164 format examples
notificationapi.send({
type: 'order_update',
to: {
id: 'user456',
number: '+16175551212' // US number
},
parameters: {
orderNumber: 'ORD-123',
status: 'shipped'
}
});
// More E.164 examples
const phoneNumbers = [
'+16175551212', // United States
'+447911123456', // United Kingdom
'+33123456789', // France
'+81901234567', // Japan
'+5511987654321', // Brazil
'+4917612345678', // Germany
'+61412345678' // Australia
];
Always use E.164 format (+[country code][phone number]) for reliable SMS delivery worldwide.
SMS Personalization with Parameters
Parameters allow you to inject dynamic content into your SMS messages:
Example SMS Use Case
// Order confirmation SMS
notificationapi.send({
type: 'order_confirmation',
to: {
id: 'customer789',
number: '+16175551212'
},
parameters: {
firstName: 'Sarah',
orderNumber: 'ORD-456',
total: '$89.99',
estimatedDelivery: 'March 15',
trackingUrl: 'https://track.example.com/ABC123'
}
});
Using Parameters in SMS Templates
In your SMS template designer, reference parameters using double curly braces:
Hi {{firstName}}! Your order {{orderNumber}} has been confirmed.
Total: {{total}}.
Expected delivery: {{estimatedDelivery}}.
Track: {{trackingUrl}}
SMS messages are limited to 800 ASCII characters. Design concise templates that convey essential information clearly.
SMS Best Practices
1. Message Length and Content
Character Limits:
- SMS limit: 800 ASCII characters maximum
- Recommended: Keep messages under 160 characters for single SMS segments
- Long messages: Automatically split into multiple segments
- Avoid spam: Don’t send excessive messages
2. Compliance and Consent
- Opt-in required: Ensure users have consented to SMS notifications
- Opt-out mechanism: Include unsubscribe instructions when required
- Regulatory compliance: Follow local regulations (TCPA in US, GDPR in EU)
- Record keeping: Maintain consent records
- Avoid spam: Don’t send excessive messages
Sender Phone Numbers
Free Accounts
- Shared number: +16505501770
- Suitable for: Testing and low-volume use
Enterprise Accounts
- Dedicated numbers: Your own phone number
- Available types:
- Local numbers (any area code)
- Toll-free numbers
- Short codes (for high-volume sending)
You don’t need a third-party service like Twilio. NotificationAPI manages all telecom infrastructure, including regulatory compliance and delivery monitoring.
SMS Responses and Two-Way Communication
NotificationAPI supports receiving and processing SMS replies:
Setting Up SMS Responses
SMS responses are an enterprise feature that requires a dedicated phone number.
- Webhook configuration: Contact support to set up response webhooks
- Response handling: Process incoming SMS replies in your application
- Auto-responses: Set up automated replies for common responses
Tracking and Analytics
NotificationAPI automatically tracks SMS metrics:
- Delivery status: Successfully delivered messages
- Failed deliveries: Numbers that couldn’t receive messages
View all analytics in your dashboard under Logs and Insights.
Need more help?
If you need help, reach out through our live chat or Slack community.