- Node
- Ruby
- Python
- PHP
- .NET
- Java
- Go
Overview
This guide shows how to send an SMS notification using Plivo’s APIs and the Node.js SDK.Prerequisites
- A Plivo account — sign up for free if you don’t have one.
- An SMS-enabled Plivo phone number to send messages to the US and Canada. You can rent a number from the Plivo console.
- Node.js and the Plivo Node.js SDK installed. See our Node.js setup guide.
Create and run the application
Create a file namedsend_sms.js and paste this code into it. This script sends a notification using the messages.create function.Replace the <auth_id>, <auth_token>, <sender_id>, and <destination_number> placeholders with your actual values.Copy
Ask AI
const plivo = require('plivo');
async function sendSmsNotification() {
const client = new plivo.Client("<auth_id>", "<auth_token>");
try {
const response = await client.messages.create({
src: "<sender_id>",
dst: "<destination_number>",
text: "Appointment reminder: 12:00 noon tomorrow. Please reply to this message if you need to make a change"
});
console.log("Message sent successfully:", response);
} catch (error) {
console.error("Error sending message:", error);
}
}
sendSmsNotification();
Test
Save the file and run it from your terminal.Copy
Ask AI
node send_sms.js
Overview
This guide shows how to send an SMS notification using Plivo’s APIs and the Ruby SDK.Prerequisites
- A Plivo account — sign up for free if you don’t have one.
- An SMS-enabled Plivo phone number to send messages to the US and Canada. You can rent a number from the Plivo console.
- Ruby and the Plivo Ruby SDK installed. See our Ruby setup guide.
Create and run the application
Create a file namedsend_sms.rb and paste this code into it. This script sends a notification using the messages.create function.Replace the <auth_id>, <auth_token>, <sender_id>, and <destination_number> placeholders with your actual values.Copy
Ask AI
require "plivo"
include Plivo
begin
api = RestClient.new("<auth_id>", "<auth_token>")
response = api.messages.create(
src: "<sender_id>",
dst: "<destination_number>",
text: "Appointment reminder: 12:00 noon tomorrow. Please reply to this message if you need to make a change",
)
puts response
rescue PlivoRESTError => e
puts "Error: " + e.message
end
Test
Save the file and run it from your terminal.Copy
Ask AI
ruby send_sms.rb
Overview
This guide shows how to send an SMS notification using Plivo’s APIs and the Python SDK.Prerequisites
- A Plivo account — sign up for free if you don’t have one.
- An SMS-enabled Plivo phone number to send messages to the US and Canada. You can rent a number from the Plivo console.
- Python and the Plivo Python SDK installed. See our Python setup guide.
Create and run the application
Create a file namedsend_sms.py and paste this code into it. This script sends a notification using the messages.create function.Replace the <auth_id>, <auth_token>, <sender_id>, and <destination_number> placeholders with your actual values.Copy
Ask AI
import plivo
from plivo.exceptions import PlivoRestError
try:
client = plivo.RestClient('<auth_id>', '<auth_token>')
response = client.messages.create(
src='<sender_id>',
dst='<destination_number>',
text='Appointment reminder: 12:00 noon tomorrow. Please reply to this message if you need to make a change',
)
print(response)
except PlivoRestError as e:
print(e)
Test
Save the file and run it from your terminal.Copy
Ask AI
python send_sms.py
Overview
This guide shows how to send an SMS notification using Plivo’s APIs and the PHP SDK.Prerequisites
- A Plivo account — sign up for free if you don’t have one.
- An SMS-enabled Plivo phone number to send messages to the US and Canada. You can rent a number from the Plivo console.
- PHP and the Plivo PHP SDK installed. See our PHP setup guide.
Create and run the application
Create a file namedSendSMS.php and paste this code into it. This script sends a notification using the messages->create function.Replace the <auth_id>, <auth_token>, <sender_id>, and <destination_number> placeholders with your actual values.Copy
Ask AI
<?php
require 'vendor/autoload.php';
use Plivo\RestClient;
use Plivo\Exceptions\PlivoRestException;
try {
$client = new RestClient("<auth_id>", "<auth_token>");
$response = $client->messages->create(
[
"src" => "<sender_id>",
"dst" => "<destination_number>",
"text" => "Appointment reminder: 12:00 noon tomorrow. Please reply to this message if you need to make a change",
]
);
print_r($response);
} catch (PlivoRestException $e) {
echo "Error: " . $e->getMessage();
}
?>
Test
Save the file and run it from your terminal.Copy
Ask AI
php SendSMS.php
Overview
This guide shows how to send an SMS notification using Plivo’s APIs and the .NET SDK.Prerequisites
- A Plivo account — sign up for free if you don’t have one.
- An SMS enabled Plivo phone number to send messages to the US and Canada. You can rent a number from the Plivo console.
- .NET and the Plivo .NET SDK installed. See our .NET setup guide.
Create and run the application
In yourProgram.cs file, paste this code. This script sends a notification using the api.Message.Create function.Replace the <auth_id>, <auth_token>, <sender_id>, and <destination_number> placeholders with your actual values.Copy
Ask AI
using System;
using Plivo;
namespace PlivoExamples
{
class Program
{
static void Main(string[] args)
{
var api = new PlivoApi("<auth_id>", "<auth_token>");
try
{
var response = api.Message.Create(
src: "<sender_id>",
dst: new List<string> { "<destination_number>" },
text: "Appointment reminder: 12:00 noon tomorrow. Please reply to this message if you need to make a change"
);
Console.WriteLine(response);
}
catch (Plivo.PlivoRestException e)
{
Console.WriteLine("Error: " + e.Message);
}
}
}
}
Test
Save the file and run it. Your application will send the SMS notification to your destination phone.Overview
This guide shows how to send an SMS notification using Plivo’s APIs and the Java SDK.Prerequisites
- A Plivo account — sign up for free if you don’t have one.
- An SMS-enabled Plivo phone number to send messages to the US and Canada. You can rent a number from the Plivo console.
- Java and the Plivo Java SDK installed. See our Java setup guide.
Create and run the application
Create a Java class namedSendSMS and paste this code into it. This script sends a notification using the Message.creator function.Replace the <auth_id>, <auth_token>, <sender_id>, and <destination_number> placeholders with your actual values.Copy
Ask AI
import com.plivo.api.Plivo;
import com.plivo.api.exceptions.PlivoRestException;
import com.plivo.api.models.message.Message;
import com.plivo.api.models.message.MessageCreateResponse;
import java.io.IOException;
class SendSMS {
public static void main(String [] args) {
Plivo.init("<auth_id>", "<auth_token>");
try {
MessageCreateResponse response = Message.creator(
"<sender_id>",
"<destination_number>",
"Appointment reminder: 12:00 noon tomorrow. Please reply to this message if you need to make a change"
).create();
System.out.println(response);
} catch (PlivoRestException | IOException e) {
e.printStackTrace();
}
}
}
Test
Save the file, compile, and run it. You should receive the SMS notification on your destination phone.Overview
This guide shows how to send an SMS notification using Plivo’s APIs and the Go SDK.Prerequisites
- A Plivo account — sign up for free if you don’t have one.
- An SMS-enabled Plivo phone number to send messages to the US and Canada. You can rent a number from the Plivo console.
- Go and the Plivo Go SDK installed. See our Go setup guide.
Create and run the application
Create a file namedSendSMS.go and paste this code into it. This script sends a notification using the client.Messages.Create function.Replace the <auth_id>, <auth_token>, <sender_id>, and <destination_number> placeholders with your actual values.Copy
Ask AI
package main
import (
"fmt"
"[github.com/plivo/plivo-go/v7](https://github.com/plivo/plivo-go/v7)"
)
func main() {
client, err := plivo.NewClient("<auth_id>", "<auth_token>", &plivo.ClientOptions{})
if err != nil {
panic(err)
}
response, err := client.Messages.Create(
plivo.MessageCreateParams{
Src: "<sender_id>",
Dst: "<destination_number>",
Text: "Appointment reminder: 12:00 noon tomorrow. Please reply to this message if you need to make a change",
},
)
if err != nil {
panic(err)
}
fmt.Printf("Response: %#v\n", response)
}
Test
Save the file and run it from your terminal.Copy
Ask AI
go run SendSMS.go