Send an SMS

In this code snippet you will see how to send an SMS using the Messages API.

For a step-by-step guide to this topic, you can read our tutorial Sending SMS messages with the Messages API.

Note: To include a new line in the message, see the documentation for Concatenation and Encoding

Delivery receipts

The webhook used for the delivery receipt will depend on the type of authentication used:

Authentication type used Webhook used for delivery receipt
Basic Auth account-level webhook is used for delivery receipt.
JWT Auth application-level webhook is used for delivery receipt / status.

Reception of delivery receipts depends on availability of network support.

Example

Find the description for all variables used in each code snippet below:

KeyDescription
VONAGE_APPLICATION_ID

The Vonage Application ID.

VONAGE_PRIVATE_KEY

Private key for the Vonage Application.

MESSAGES_TO_NUMBER

The number you are sending the to in E.164 format. For example 447700900000.

SMS_SENDER_ID

The alphanumeric string that represents the name or number of the organization sending the message.

NOTE: Don't use a leading + or 00 when entering a phone number, start with the country code, for example 447700900000.

Prerequisites

If you do not have an application you can create one. Make sure you also configure your webhooks.

Write the code

Add the following to send-sms.sh:

View full source

Run your code

Save this file to your machine and run it:

bash send-sms.sh

Try it out

When you run the code a message is sent to the destination number.