<

Getting started with Messages

In this guide, we’ll see how to use Plivo APIs to send SMS messages from your web application. Let’s have a look at some prerequisites before we dive into the code.

Prerequisites

  • Plivo Auth Id and Auth Token: You will find your Plivo Auth Id and Auth Token on the home screen of your Plivo management console. Click here to sign-up for a Plivo account if you haven’t already!
  • Plivo Server-side SDK: The code in this tutorial uses Plivo’s Python Server-side SDK. To get started with the SDK in the language of your choice, visit the Server-side SDKs page.
  • Plivo Phone Number: You must have a valid Plivo phone number to send messages to the US and Canada. You can purchase numbers from the Numbers section of your Plivo Management Console. It is also possible to purchase numbers using the Numbers API.

Sending Messages Using Plivo REST API

To send an SMS, we’ll need to make an HTTP POST request to the Message API. We shall pass the source address (src), destination number (dst) and message text (text) in the request payload.

The sample code below uses Plivo’s Server-side SDK for Python.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import plivo


def main():
    client = plivo.Client('AUTH_ID', 'AUTH_TOKEN')
    try:
        response = client.messages.create(
            src='11111111111',
            dst='22222222222',
            text='Hello, world!',
        )
        print(response.__dict__)
    except plivo.exceptions.PlivoRestError as e:
        print(e)


if __name__ == '__main__':
    main()

Don’t forget to replace the Auth Id and Auth Token placeholders in the Plivo client initialization statement with your actual Plivo Auth Id and Auth Token.

Next Steps