SMS API
Vonage's SMS API enables you to send and receive text messages to and from users worldwide, using our REST APIs.
- Programmatically send and receive high volumes of SMS globally.
- Send SMS with low latency and high delivery rates.
- Receive SMS using local numbers.
- Scale your applications with familiar web technologies.
- Pay only for what you use, nothing more.
- Auto-redact feature to protect privacy.
Contents
This topic contains the following information:
- Getting Started - Information on how to get started quickly
- Troubleshooting - Message object status field and error code information
- Concepts - Introductory concepts
- Guides - Learn how to use the SMS API
- Code Snippets - Code snippets to help with specific tasks
- Use Cases - Use cases with code examples
- Reference - REST API documentation
Getting Started
Important 10 DLC guidelines for US customers
10 DLC stands for 10 Digit Long Code. Major US carriers have announced their requirements for a new standard for application-to-person (A2P) messaging in the USA, which applies to all messaging over 10 digit geographic phone numbers, also know as 10 DLC. This new standard provides many benefits including supporting higher messaging speeds and better deliverability.
Customers using the Vonage SMS API to send traffic from a +1 Country Code 10 Digit Long Code into US networks will need to register a brand and campaign in order to get approval for sending messages.
Note: US numbers can no longer be shared across brands which include both geographic numbers and US Shared Short Codes.
Vonage customers using US shared short codes: T-Mobile and AT&T’s new code of conduct prohibits the use of shared originators, therefore, Shared Short codes will no longer be an acceptable format for A2P messaging.
- Vonage customers using a Shared Short Code must migrate SMS traffic to either a 10 DLC, Toll Free SMS Number, or Dedicated Short Code.
- Vonage customers using our Shared Short Code API must migrate to either our SMS API or Verify API.
- Customers using Dedicated Short Codes are not affected by these changes within the scope of 10 DLC.
- Message Throughput varies by carrier.
To learn more about 10 DLC including important dates and carrier-specific information, see the knowledge base.
If you have decided moving to 10 DLC is right for your campaigns, you must:
2. Apply for brand vetting unless your entity is listed on the Russel 3000 index
4. Link a number to a campaign
Register a brand
- Navigate to Vonage API dashboard > Brands and campaigns.
- Click Register a new brand.
- Fill in all required fields on the Register a new brand form.
- Click Review details. A confirmation dialog box opens.
- Review your brand details.
- Click Register and pay.
Note: You will not be able to change your brand details after registering.
Your brand information is displayed in the Brand list on the Brands and campaigns page where you can monitor the status of its registration and view more details.
Apply for brand vetting
- Navigate to Vonage API dashboard > Brands and campaigns.
- Select the Brand for which you wish to apply for vetting.
- Select the External vetting tab.
- Click the Apply for vetting button. The External brand vetting dialog box opens.
- Select the appropriate options in the drop-down menus.
- Click the Apply for external vetting button. An External brand vetting confirmation message is displayed.
- Click the Close button.
Register a campaign
- Navigate to Vonage API dashboard > Brands and campaigns.
- Click Register a new campaign. The Create a new campaign page is displayed.
- Under Step 2 Use case, select the check box associated with the use case that best describes this campaign. The use case describes the specific purpose of the campaign; for instance, marketing or account notifications you wish to send to customers.
- Click Done.
- Under Step 3 Carrier qualification, you can determine whether or not your use case has been approved for sending SMS traffic. Qualification is done by 10DLC enabled carriers. If your use case was rejected, or if your throughput is insufficient, you can appeal through Brand Vetting which is done through a 3rd party.
- Click Done.
- Under Step 4 Campaign details:
- In the Selected brand field, identify the brand associated with this campaign.
- From the Vertical drop-down menu, select the vertical associated with your brand.
- In the Campaign description field, type a brief description of this campaign.
- Click Done.
- Under Step 5 Sample messages, type up to five examples of messages that will be sent for this campaign.
- Click Done.
- Under Step 6 Campaign and content attributes, select the attributes that apply to this campaign. For instance, select Subscriber opt-out if messages sent for this campaign provide customers the opportunity to opt-out. Select all attributes that apply.
- Click Review and pay. A confirmation dialog box opens summarizing your campaign details. Any charges to your account are indicated above the campaign details. You will not be able to change the campaign details after registering.
- Click Register and pay. The campaign is displayed in the Campaigns list on the Brands and campaigns page.
Link a number to a campaign
- Navigate to Vonage API dashboard > Brands and campaigns.
- Select an existing brand.
- Select the Campaigns tab.
- Select an existing campaign in the list.
- Select the Numbers tab.
- Search one of your existing numbers or buy a new number.
- Click the Link button corresponding to the number you wish to link to the campaign. A Link number to campaign dialog box opens on which you can select a check box to make your number HIPPA compliant. Note that if you want your number to be HIPPA compliant, you must first reach out to your Account Manager.
- Click the Link button. After you request to link a number to a campaign, the process will take a few minutes to complete. During this time, you will see a Pending status in the State column on the number you are linking.
Send an SMS
This example shows you how to send an SMS to your chosen number.
First, sign up for a Vonage account if you don't already have one, and make a note of your API key and secret on the dashboard getting started page.
Replace the following placeholder values in the sample code:
Key | Description |
---|---|
VONAGE_API_KEY |
Your Vonage API key. |
VONAGE_API_SECRET |
Your Vonage API secret. |
Write the code
Add the following to send-sms.sh
:
curl -X "POST" "https://rest.nexmo.com/sms/json" \
-d "from=$VONAGE_BRAND_NAME" \
-d "text=A text message sent using the Vonage SMS API" \
-d "to=$TO_NUMBER" \
-d "api_key=$VONAGE_API_KEY" \
-d "api_secret=$VONAGE_API_SECRET"
Run your code
Save this file to your machine and run it:
sh send-sms.sh
Prerequisites
npm install @vonage/server-sdk
Create a file named send.js
and add the following code:
const Vonage = require('@vonage/server-sdk')
const vonage = new Vonage({
apiKey: VONAGE_API_KEY,
apiSecret: VONAGE_API_SECRET
})
Write the code
Add the following to send.js
:
const from = VONAGE_BRAND_NAME
const to = TO_NUMBER
const text = 'A text message sent using the Vonage SMS API'
vonage.message.sendSms(from, to, text, (err, responseData) => {
if (err) {
console.log(err);
} else {
if(responseData.messages[0]['status'] === "0") {
console.log("Message sent successfully.");
} else {
console.log(`Message failed with error: ${responseData.messages[0]['error-text']}`);
}
}
})
Run your code
Save this file to your machine and run it:
node send.js
Prerequisites
Add the following to `build.gradle`:
compile 'com.vonage:client:6.2.0'
Create a class named SendMessage
and add the following code to the main
method:
VonageClient client = VonageClient.builder().apiKey(VONAGE_API_KEY).apiSecret(VONAGE_API_SECRET).build();
Write the code
Add the following to the main
method of the SendMessage
class:
TextMessage message = new TextMessage(VONAGE_BRAND_NAME,
TO_NUMBER,
"A text message sent using the Vonage SMS API"
);
SmsSubmissionResponse response = client.getSmsClient().submitMessage(message);
if (response.getMessages().get(0).getStatus() == MessageStatus.OK) {
System.out.println("Message sent successfully.");
} else {
System.out.println("Message failed with error: " + response.getMessages().get(0).getErrorText());
}
Run your code
We can use the application
plugin for Gradle to simplify the running of our application.
Update your build.gradle
with the following:
apply plugin: 'application'
mainClassName = project.hasProperty('main') ? project.getProperty('main') : ''
Run the following gradle
command to execute your application, replacing com.vonage.quickstart.sms
with the package containing SendMessage
:
gradle run -Pmain=com.vonage.quickstart.sms.SendMessage
Prerequisites
Install-Package Vonage
Create a file named SendSms.cs
and add the following code:
using Vonage;
using Vonage.Request;
Add the following to SendSms.cs
:
vonageApiKey,
vonageApiSecret
);
var vonageClient = new VonageClient(credentials);
Write the code
Add the following to SendSms.cs
:
{
To = toNumber,
From = vonageBrandName,
Text = "A text message sent using the Vonage SMS API"
});
Console.WriteLine(response.Messages[0].To);
Prerequisites
composer require vonage/client
Create a file named send-sms.php
and add the following code:
$basic = new \Vonage\Client\Credentials\Basic(VONAGE_API_KEY, VONAGE_API_SECRET);
$client = new \Vonage\Client($basic);
Write the code
Add the following to send-sms.php
:
$response = $client->sms()->send(
new \Vonage\SMS\Message\SMS(TO_NUMBER, BRAND_NAME, 'A text message sent using the Nexmo SMS API')
);
$message = $response->current();
if ($message->getStatus() == 0) {
echo "The message was sent successfully\n";
} else {
echo "The message failed with status: " . $message->getStatus() . "\n";
}
Run your code
Save this file to your machine and run it:
php send-sms.php
Prerequisites
pip install vonage
Create a file named send-an-sms.py
and add the following code:
client = vonage.Client(key=VONAGE_API_KEY, secret=VONAGE_API_SECRET)
Write the code
Add the following to send-an-sms.py
:
{
"from": VONAGE_BRAND_NAME,
"to": TO_NUMBER,
"text": "A text message sent using the Nexmo SMS API",
}
)
if responseData["messages"][0]["status"] == "0":
print("Message sent successfully.")
else:
print(f"Message failed with error: {responseData['messages'][0]['error-text']}")
Run your code
Save this file to your machine and run it:
python send-an-sms.py
Prerequisites
gem install vonage
Create a file named send.rb
and add the following code:
client = Vonage::Client.new(
api_key: VONAGE_API_KEY,
api_secret: VONAGE_API_SECRET
)
Write the code
Add the following to send.rb
:
client.sms.send(
from: VONAGE_BRAND_NAME,
to: TO_NUMBER,
text: 'A text message sent using the Vonage SMS API'
)
Run your code
Save this file to your machine and run it:
ruby send.rb
Troubleshooting
If you have problems when making API calls be sure to check the returned status field for specific error codes.
Concepts
Before using the Vonage SMS API, familiarize yourself with the following:
Number format - The SMS API requires phone numbers in E.164 format.
Authentication - The SMS API authenticates using your account API key and secret.
Webhooks - The SMS API makes HTTP requests to your application web server so that you can act upon them. For example: inbound SMS and delivery receipts.
Guides
- Sender identity: How to change where your SMS appears to come from.
- Concatenation and encoding: Determining whether the byte length of a message results in it being sent as multiple SMS.
- Country specific features: How different countries' SMS sending rules can affect your campaign.
- Delivery receipts: How to request a delivery receipt (DLR) from the carrier.
- Inbound SMS: How to receive SMS on your Vonage virtual numbers.
- Troubleshooting: What to do if your SMS delivery fails.
- SMPP access: Using SMPP instead of REST to access the SMS API.
Code Snippets
Use Cases
- Mobile app invites
- Private SMS communication
- Receiving Concatenated SMS
- SMS Customer Support
- Two-way SMS for customer engagement