Device Type: desktop

How to get started with Vonage SMS API

Vonage's SMS API enables you to send and receive text messages to and from users worldwide, using our REST APIs. We offer SDKs for all your favorite platforms and programming languages Android, iOS, JavaScript, Ruby, .NET, PHP, Node.js, Python and Java.

illustration of code coming out of a phone

Over five billion people send text messages a year: so chances are you are familiar with texting. However, you may not be familiar with the technology behind a text message. In this tutorial, you will learn about technologies like SMS that power text messages. Then, you will learn how to send a text message programmatically.

What is a text message?

A text message is an electronic message. Initially, a text message referred to SMS, which stands for short message service. SMS is a service for sending short messages over wireless networks using standardized communication protocols. Neil Papworth sent the first SMS message on December 3, 1992, when he wrote Merry Christmas to his co-worker Richard Jarvis.

Since then, texting has evolved. For example, people now often share images, audio, and other types of multimedia. This change led to the development of MMS, which stands for multimedia messaging service. As you may have guessed, MMS lets you send text messages with different types of multimedia, such as images. 

Despite the advent of MMS, SMS messages remain popular, with over two trillion sent every year. 

One advantage of SMS messages is they are cheaper to send. Another advantage is not all customers can receive MMS messages.

Now that you are familiar with the technologies behind text messages let's dive into sending one with just a few lines of code.   

Prerequisites

To follow this tutorial, you need to create a Vonage account.

How to send a text message

Sending a text message programmatically is simple. 

You can write code to use Vonage's SMS API to send a text message in less than five minutes. 

Ready to give it a try? 

First, open up your command line and set the following environment variables:

  
    export VONAGE_BRAND_NAME
    export TO_NUMBER
    export VONAGE_API_KEY
    export VONAGE_API_SECRET
  

Replace VONAGE_BRAND_NAME with your Vonage virtual number, VTO_NUMBER with the number you want to send an SMS message to, VONAGE_API_KEY with your Vonage API key, and VONAGE_API_SECRET with your Vonage API secret.



Next, create an sms.sh file like this:

  
    vim sms.sh
  

Add the following code to your file, type esc, :x, and press enter to save and quit.

  
    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"
  

Finally, type the following command to send an SMS message:

  
    sh sms.sh
  

If you are testing this code by sending an SMS message to yourself, you should receive a text message shortly. 

You can send a different message by replacing A text message sent using the Vonage SMS API in your code with a different message. 

Final thoughts

Nice work!

You now know how to send an SMS message programmatically!

In this tutorial, you learned how to send an SMS message with CURL. That's not your only option, though! At Vonage, we have SDKs for several different programming languages, including JavaScript, Java, .NET, PHP, Python, and Ruby. You can learn more about using our SDKs here

If you have any questions about using the Vonage SMS API, you can reach out to our developer relations team on Slack or Twitter

Thanks for reading!

 

Send your first SMS free

Sign up to get your API credentials to start sending SMS now.
Stylized illustration of a mobile phone displaying computer code