π¬ Send SMS
Send SMS with NotificationAPI without using Twilio or other third parties. Setup is quick and simple: hereβs how.
Install the SDK:
npm install 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 dependencies to your pom.xml file:
<dependencies>
<dependency>
<groupId>com.notificationapi</groupId>
<artifactId>notificationapi-java-server-sdk</artifactId>
<version>0.3.0</version>
</dependency>
<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>
</dependencies> Add the NotificationAPI class to your application - see the full Ruby implementation.
Now, send an SMS notification from your backend:
TIP
Replace YOUR_CLIENT_ID and YOUR_CLIENT_SECRET with the values from the
code sample in your NotificationAPI dashboard. These values can also be found
in the Environments section of the dashboard.
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 (direct content)
notificationapi.send({
type: 'welcome_sms',
to: {
id: 'user123',
number: '+16175551212' // Replace using format [+][country code][area code][local number]
},
sms: {
message: 'Welcome to Acme Corp! Thanks for joining.'
}
}); 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" # Replace using format [+][country code][area code][local number]
},)
"sms": {
"message": "Welcome to Acme Corp! Thanks for joining."
}
})
# Run the async function
asyncio.run(send_sms()) use NotificationAPI\NotificationAPI;
// Initialize
$notificationapi = new NotificationAPI('YOUR_CLIENT_ID', 'YOUR_CLIENT_SECRET');
// Send SMS notification (direct content)
$notificationapi->send([
"type" => "welcome_sms",
"to" => [
"id" => "user123",
"number" => "+16175551212" // Replace using format [+][country code][area code][local number]
],
"sms" => [
"message" => "Welcome to Acme Corp! Thanks for joining."
]
]); 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")
// Send SMS notification (direct content)
notificationapi.Send(
notificationapi.SendRequest{
Type: "welcome_sms",
To: notificationapi.User{
Id: "user123",
Number: "+16175551212", // Replace using format [+][country code][area code][local number]
},
Sms: map[string]interface{}{
"message": "Welcome to Acme Corp! Thanks for joining.",
},
},
)
} 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" // Replace using format [+][country code][area code][local number]
};
// Send SMS notification (direct content)
await notificationApi.Send(new SendNotificationData("welcome_sms", user)
{
Type = "welcome_sms",
To = user,
Sms = new Dictionary<string, object>
{
{ "message", "Welcome to Acme Corp! Thanks for joining." }
}
}); package com.example;
import com.notificationapi.NotificationApi;
import com.notificationapi.model.*;
public class Example {
public static void main(String[] args) {
NotificationApi api = new NotificationApi(
"YOUR_CLIENT_ID",
"YOUR_CLIENT_SECRET"
);
// Create user
User user = new User("user123")
.setEmail("user@example.com")
.setNumber("+16175551212"); // Replace using format [+][country code][area code][local number]
// Create and send notification request
NotificationRequest request = new NotificationRequest("welcome_sms", user)
.setSms(new SmsOptions()
.setMessage("Welcome to Acme Corp! Thanks for joining.")
);
System.out.println("Sending notification request...");
String response = api.send(request);
System.out.println("Response: " + response);
}
} # Initialize
notificationapi = NotificationAPI.new("YOUR_CLIENT_ID", "YOUR_CLIENT_SECRET")
# Send SMS notification (direct content)
notificationapi.send({
type: 'welcome_sms',
to: {
id: 'user123',
number: '+16175551212' # Replace using format [+][country code][area code][local number]
},
sms: {
message: 'Welcome to Acme Corp! Thanks for joining.'
}
}) Youβre All Set!
π Congrats! Youβre now sending SMS notifications!
For more advanced features like sender numbers, A2P 10DLC registration, and SMS best practices, check out our SMS Channel documentation.