Send a Message

This API enables you to send messages via Plivo’s SMS service.

API Endpoint

POST https://api.plivo.com/v1/Account/{auth_id}/Message/

Arguments

srcConditionalstring

Set this parameter to the sender ID you wish to use. This could a phone number, shortcode or alphanumeric string.

All characters other than A-Z, a-z, 0-9 are stripped off automatically as part of the sanitization process.

Sanitized phone numbers must begin with the international country code (ex: 14152828726), and should be <= 14 characters in length.

Sanitized alphanumeric sender ids should be <= 11 characters in length. Support for Alphanumeric sender IDs is disabled by default. Learn more about alphanumeric sender ID whitelisting here.

Note that a Plivo phone number is required for sending messages to the U.S. or Canada. You can buy a Plivo number from the Buy Numbers tab on your Plivo dashboard or via the Numbers API.

powerpack_uuidConditionalstring

Set this to the UUID of the SMS Powerpack you wish to use for this SMS. The src request parameter should not be included when sending messages using Powerpack.

dstRequiredstring

Set this parameter to the phone number to which the message is to be delivered.

The following characters are stripped off automatically as part of the sanitization process: /, -, ., +, (, ) and white spaces.

Sanitized phone numbers must begin with the international country code (ex: 14152828726), and should be <= 14 characters in length.

To send messages to multiple numbers, separate your destination phone numbers with the delimiter <. (e.g. 14156667777<14157778888<14158889999).

textRequiredstring

Set this parameter to the content of the text message.

Messages containing only GSM03.38 7 bit characters have a maximum limit of 1600 characters. Messages longer than 160 characters are split into multiple message units, each unit consisting of 153 characters.

Messages containing one or more UCS-2 16 bit unicode characters have a maximum limit of 737 characters. Messages longer than 70 characters are split into multiple message units, each unit consisting of 67 characters.

Multi-unit messages are automatically stitched back together and delivered as a single message in countries where mobile networks support long message concatenation.

type string

Plivo presently only supports sms messages. This parameter defaults to sms, and should be left as is for now.

url string

Set this parameter to the fully qualified URL to which status update callbacks for the message should be sent. Read more about the message attributes passed to this callback url here.

method string

The HTTP method to be used when calling the url defined above. Defaults to POST when not specified. Note that only GET and POST are presently supported.

log boolean

If set to false, the text content of this message will not be logged on Plivo infrastructure, and the dst value will be masked (e.g., 141XXXXX528). This parameter defaults to true when not specified.

trackable boolean

Set this paramater to true for messages that have a trackable user action, for example, entering a 2FA verification code. Setting this parameter to true implies that you intend to update Plivo upon successful delivery of the message using the Conversion Feedback API. Read our guide on Providing Conversion Feedback for trackable SMS messages for details. This parameter defaults to false when no specified.

Returns

Returns a JSON response containing the API request ID and Message UUID(s).

Response

HTTP Status Code: 202

{
	"message": "message(s) queued",
	"message_uuid": ["db3ce55a-7f1d-11e1-8ea7-1231380bc196"],
	"api_id": "db342550-7f1d-11e1-8ea7-1231380bc196"
}

Example Request

1
2
3
4
5
6
7
8
import plivo

client = plivo.RestClient()
response = client.messages.create(
    src='from_number',
    dst='to_number',
    text='Test Message', )
print(response)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#
# Example for Message Create
#
require 'rubygems'
require 'plivo'

include Plivo
include Plivo::Exceptions

api = RestClient.new("YOUR_AUTH_ID", "YOUR_AUTH_TOKEN")

begin
  response = api.messages.create(
    '14153336666',
    ['14156667777', 123_123_123_123],
    'Test Message',
    { 'url' => 'http://example.com/api/confirmsms/' }
  )
  puts response
rescue PlivoRESTError => e
  puts 'Exception: ' + e.message
end
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// Example for Message create

var plivo = require('plivo');

(function main() {
    'use strict';
    
    // As the auth_id and auth_token are unspecified, Plivo will fetch them from the PLIVO_AUTH_ID and PLIVO_AUTH_TOKEN environment variables.
    var client = new plivo.Client();
    client.messages.create(
        "14153336666", // src
        "14156667777", // dst
        "Test Message", // text
    ).then(function (response) {
        console.log(response);
    }, function (err) {
        console.error(err);
    });
})();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?php
/**
 * Example for Message create
 */
require 'vendor/autoload.php';
use Plivo\RestClient;

$client = new RestClient("YOUR_AUTH_ID", "YOUR_AUTH_TOKEN");

try {
    $response = $client->messages->create(
        '14153336666',
        '14156667777',
        'Test Message'
    );
    print_r($response);
}
catch (PlivoRestException $ex) {
    print_r(ex);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package com.plivo.api.samples.message;

import java.io.IOException;
import java.util.Collections;

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;

/**
* Example for Message create
*/
class MessageCreate {
    public static void main(String [] args) {
        Plivo.init();
        try {
            MessageCreateResponse response = Message.creator("14153336666", Collections.singletonList("14156667777"), "Test Message")
                .create();

            System.out.println(response);
        } catch (PlivoRestException | IOException e) {
            e.printStackTrace();
        }
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/**
 * Example for Message Create
 */
using System;
using System.Collections.Generic;
using Plivo;
using Plivo.Exception;

namespace PlivoExamples
{
    internal class Program
    {
        public static void Main(string[] args)
        {
            var api = new PlivoApi("YOUR_AUTH_ID", "YOUR_AUTH_TOKEN");
            try
            {
                var response = api.Message.Create(
                    src:"14153336666",
                    dst:new List<String>{"14156667777"},
                    text:"Test Message"

                );
                Console.WriteLine(response);
            }
            catch (PlivoRestException e)
            {
                Console.WriteLine("Exception: " + e.Message);
            }
        }
    }
}
1
2
3
4
curl -i --user AUTH_ID:AUTH_TOKEN \
    -H "Content-Type: application/json" \
    -d '{"src": "1111111111","dst": "2222222222", "text": "Hi, text from Plivo"}' \
    https://api.plivo.com/v1/Account/{auth_id}/Message/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// Example for Message create
package main

import "fmt"
import "github.com/plivo/plivo-go"
 
func main() {
	client, err := plivo.NewClient("", "", &plivo.ClientOptions{})
	if err != nil {
		panic(err)
	}
	response, err := client.Messages.Create(
		plivo.MessageCreateParams{
			Src: "14153336666",
			Dst: "14156667777",
			Text: "Test Message",
		},
	)
	if err != nil {
		panic(err)
	}
	fmt.Printf("Response: %#v\n", response)
}