Send Multiple (Bulk) SMS

An unique feature of Plivo’s REST APIs is that you can send bulk (multiple) SMS using a single API request. To send bulk SMS, make an HTTP POST request to the Message API similar to sending a single outbound SMS, with the additional step of adding multiple dst destination numbers by separating each phone number with the "<" character.

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

Getting Started

  1. Sign up for a free Plivo trial account.
  2. Check out our server-side SDKs page and install the right helper based on the programming language you want to use.
  3. Buy a Plivo phone number (optional).
    Note: A phone number is required only for sending SMS to US and Canadian phone numbers. However, country-specific carrier conditions may still apply. You can buy a US or Canadian phone number through the Buy Numbers tab on your Plivo account UI.
  4. Use a web hosting service to host your web application. There are many inexpensive cloud hosting providers that you can use for just a few dollars a month. Follow the instructions of your hosting provider to host your web application.
    Note: If you are using a Plivo Trial account for this example, you can only send sms to phone numbers that have been verified with Plivo. Phone numbers can be verified at the Sandbox Numbers page.

Implementation

  1. Copy the relevant code below into a text file and save it.
  2. Replace Your AUTH_ID and Your AUTH_TOKEN with the AUTH ID and AUTH TOKEN found on your Plivo dashboard.
  3. Add your src (source) phone number. This will show up as your Sender ID. Be sure that all phone numbers include country code, area code, and phone number without spaces or dashes (e.g., 14153336666).
    Note: You can send SMS text messages to any country using the Message API and set any `src` number except for US and Canadian numbers. In order to send text messages to phones in the US or Canada, you will need to purchase a US or Canadian phone number from Plivo and use it as the `src` number. You can buy a Plivo number from the Buy Numbers tab on your Plivo account dashboard.
  4. Add your dst (destination) phone numbers. These are the phone numbers you wish to send SMS text messages to. To send messages in bulk, separate your destination phone numbers with the delimiter "<" (e.g., 14156667777<14157778888<14158889999).
    Note: If you are using a trial account, your destination number needs to be verified with Plivo. Phone numbers can be verified at the [Sandbox Numbers](https://console.plivo.com/sandbox-numbers/) page.
  5. Edit the text field with your SMS text message.
    Note: text messages that are longer than 160 characters are concatenated and billed separately as individual text messages.
  6. Make the HTTP POST request to Plivo. If successful, Plivo will queue your SMS deliver it to your recipients at a base rate of 1 message per second.
    Note: delivery is handled separately for each message.
    Advanced Hack: Check out our full Message API docs to see all the parameters and functionalities you can use.

Code

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
# -*- coding: utf-8 -*-
import plivo

client = plivo.RestClient("AUTH_ID","AUTH_TOKEN")
response = client.messages.create(
    dst='17652348329<17652348362',
    text='Hello, this is a sample text',
    url='http://foo.com/sms_status/',
    method='POST',
    log=False,
    type_='sms',
    trackable=True,
    powerpack_uuid='2dca8f70-1387-4cbd-b97f-796717a5784b'
    #Incase of no powerpack, replace powerpack_uuid with --> src:"13644444296"
    )
print(response)

#prints only the message_uuid
print(response.message_uuid)

# Sample Response:
# {
#     u'api_id': u'840ada66-c00c-11e9-b157-0242ac110004',
#     u'message': u'message(s) queued',
#     u'message_uuid': [u'84118b7c-c00c-11e9-b157-0242ac110004',u'841331d4-c00c-11e9-b157-0242ac110004']
# }

# ===============================================================
#Prints only the message_uuid
# [u'84118b7c-c00c-11e9-b157-0242ac110004', u'841331d4-c00c-11e9-b157-0242ac110004']
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
33
34
35
36
37
38
39
40
41
require "rubygems"
require "plivo"

include Plivo
include Plivo::Exceptions

api = RestClient.new("AUTH_ID", "AUTH_TOKEN")

begin
  response = api.messages.create(
    nil, #Incase if no pwerpack, 'nil' to be replaced with -->"13644444296" as source number and remove the powerpack_uuid.
    ["17652348329", "17652348362"], #dst
    "Hello, this is a sample text", #text
    { url: "http://foo.com/sms_status/",
      method: "POST",
      log: false,
      trackable: true,
      type: "sms" },
    "2dca8f70-1387-4cbd-b97f-796717a5784b", #powerpack_uuid
  )

  puts response

  #Prints only the message_uuid
  puts response.message_uuid
rescue PlivoRESTError => e
  puts "Exception: " + e.message
end

# Sample Response:
# {
#   "api_id"=>"5cb43d36-c00c-11e9-8db4-0242ac110005",
#   "message"=>"message(s) queued",
#   "message_uuid"=>["5cba03b0-c00c-11e9-8db4-0242ac110005", "5cbb7eac-c00c-11e9-8db4-0242ac110005"],
#   "id"=>["5cba03b0-c00c-11e9-8db4-0242ac110005", "5cbb7eac-c00c-11e9-8db4-0242ac110005"]
# }

# ===============================================================
# prints only the message_uuid
# 5cba03b0-c00c-11e9-8db4-0242ac110005
# 5cbb7eac-c00c-11e9-8db4-0242ac110005
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
33
34
35
36
37
38
39
var plivo = require('plivo');

(function main() {
    'use strict';
    var client = new plivo.Client("AUTH_ID","AUTH_TOKEN");
    client.messages.create(
         null, //Incase if no pwerpack, 'nil' to be replaced with -->"13644444296" as source number and remove the powerpack_uuid.
        "17652348362<17652348329", // dst
        "Hello, this is a sample text from Plivo", // text
        {
            method: "GET",
            url:"http://foo.com/sms_status/",
            log: "true",
            type: "sms"
        },
        "2dca8f70-1387-4cbd-b97f-796717a5784b" //powerpack_uuid

    ).then(function (response) {
        console.log(response);

        // Prints only the messageUuid
        console.log(response.messageUuid);
    }, function (err) {
        console.error(err);
    });
})();

// Sample response:
// PlivoGenericResponse
// {
//     id:[ 'dc102b30-c00c-11e9-b157-0242ac110004','dc0eaf12-c00c-11e9-b157-0242ac110004' ],
//     apiId: 'dc0749ac-c00c-11e9-b157-0242ac110004',
//     message: 'message(s) queued',
//     messageUuid:[ 'dc102b30-c00c-11e9-b157-0242ac110004','dc0eaf12-c00c-11e9-b157-0242ac110004' ]
// }

// ===============================================================
// Prints only the messageUuid
// [ 'dc102b30-c00c-11e9-b157-0242ac110004','dc0eaf12-c00c-11e9-b157-0242ac110004' ]
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php

require 'vendor/autoload.php';
use Plivo\RestClient;
use Plivo\Exceptions\PlivoRestException;
$client = new RestClient("AUTH_ID", "AUTH_TOKEN");

try {
    $response = $client->messages->create(
        null, #Incase if no pwerpack, 'nil' to be replaced with -->"13644444296" as source number and remove the powerpack_uuid.
        ['17652348329<17652348362'], #dst
        'Hello, this is a sample text', #text
        ["url"=>"http://foo.com/sms_status/", "method"=>"POST", "type"=>"sms","log"=> "true","log"=> "true"],
        '2dca8f70-1387-4cbd-b97f-796717a5784b' #powerpack_uuid
    );
    print_r($response);

    // Prints only the message_uuid
    print_r($response->getmessageUuid(0));

}
catch (PlivoRestException $ex) {
    print_r($ex);
}

// Sample Response:
// Plivo\Resources\Message\MessageCreateResponse Object
// (
//     [messageUuid] => Array
//         (
//             [0] => b188f2a2-c00c-11e9-b306-0242ac110004
//             [1] => b18aeaee-c00c-11e9-b306-0242ac110004
//         )

//     [_message] => message(s) queued
//     [apiId] => b1828692-c00c-11e9-b306-0242ac110004
//     [statusCode] => 202
// )

// ===============================================================
// Print only the message_uuid
// Array
// (
//     [0] => b188f2a2-c00c-11e9-b306-0242ac110004
//     [1] => b18aeaee-c00c-11e9-b306-0242ac110004
// )
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import java.io.IOException;
import java.net.URL;
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;
import com.plivo.api.models.message.MessageType;

/**
 * Example for Message create
 */
class Sendsms
{
    public static void main(String [] args)
    {
        Plivo.init("AUTH_ID","AUTH_TOKEN");
        try
        {
            MessageCreateResponse response = Message.creator(Collections.singletonList("17652348362<17652348329"),
                    "Hello, this is test message","2dca8f70-1387-4cbd-b97f-796717a5784b")
            //Incase of no powerpack, replace the above with below;
            //MessageCreateResponse response = Message.creator("13644444296",Collections.singletonList("17652348362"),
            //"Hello, this is test message")
                    .url(new URL("http://foo.com/sms_status/") )
                    .method("GET")
                    .type(MessageType.SMS)
                    .log(true)
                    .trackable(false)
                    .create();

            System.out.println(response);

            // Prints only the messageUuid
            System.out.println(response.getMessageUuid());
        }

        catch (PlivoRestException | IOException e)
        {
            e.printStackTrace();
        }
    }
}


//Sample Response:
//INFO: {
//        "api_id": "5db0792a-c002-11e9-b157-0242ac110004",
//        "message": "message(s) queued",
//        "message_uuid": ["156014dc-c00c-11e9-86d6-0242ac110006",
//        "155e67ea-c00c-11e9-86d6-0242ac110006"]
//      }

// ===============================================================
//Prints only the message_uuid:
//[156014dc-c00c-11e9-86d6-0242ac110006, 155e67ea-c00c-11e9-86d6-0242ac110006]
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
33
34
35
36
37
38
39
40
41
42
43
44
package main

import "fmt"
import "github.com/plivo/plivo-go"

func main() {
	client, err := plivo.NewClient("AUTH_ID", "AUTH_TOKEN", &plivo.ClientOptions{})
	if err != nil {
		panic(err)
	}
	response, err := client.Messages.Create(
		plivo.MessageCreateParams{
			Dst:           "17652348329<17652348362",
			Text:          "Hello, this is a sample text",
			Type:          "sms",
			URL:           "http://foo.com/sms_status/",
			Method:        "POST",
			Trackable:     true,
			Log:           "false",
			PowerpackUUID: "2dca8f70-1387-4cbd-b97f-796717a5784b",
			// Incase of no powerpack, replace powerpack_uuid with --> Src:"13644444296"
		},
	)
	if err != nil {
		panic(err)
	}
	fmt.Printf("Response: %#v\n", response)

	// Prints only the message_uuid
	fmt.Printf("Response: %#v\n", response.MessageUUID)
}

// Sample Response:
// Response: &plivo.MessageCreateResponseBody
// {
// Message:"message(s) queued",
// ApiID:"203f5560-c00d-11e9-86d6-0242ac110006",
// MessageUUID:[]string{"204703f0-c00d-11e9-86d6-0242ac110006", "20489346-c00d-11e9-86d6-0242ac110006"},
// Error:""
// }

// ===============================================================
//Prints only the message_uuid:
// Response: []string{"204703f0-c00d-11e9-86d6-0242ac110006", "20489346-c00d-11e9-86d6-0242ac110006"}
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/**
 * 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("AUTH_ID", "AUTH_TOKEN");
            try
            {
                var response = api.Message.Create(
                    // src:"13644444296",
                    dst:new List<String>{"17652348373<17652348329"},
                    text:"Hello, this is sample text",
                    url:"http://foo.com/sms_status/",
                    method:"GET",
                    log:false,
                    trackable:true,
                    type:"sms",
                    powerpack_uuid:"2dca8f70-1387-4cbd-b97f-796717a5784b"
                );
                Console.WriteLine(response);

                // Prints only the messageuuid
                Console.WriteLine(response.MessageUuid[0]);
            }
            catch (PlivoRestException e)
            {
                Console.WriteLine("Exception: " + e.Message);
            }
        }
    }
}

// Sample Response:
// Api Id: 82692274-c00e-11e9-954f-0242ac110006
// Message: message(s) queued
// StatusCode: 202
// Message Uuid: 82737b34-c00e-11e9-954f-0242ac110006,8272313e-c00e-11e9-954f-0242ac110006Username:
// Alias:

// ===============================================================
// Prints only the messageuuid
// 82737b34-c00e-11e9-954f-0242ac110006,8272313e-c00e-11e9-954f-0242ac110006
1
2
3
4
curl -i --user AUTH_ID:AUTH_TOKEN \
    -H "Content-Type: application/json" \
    -d '{"src": "1111111111","dst": "2222222222<3333333333", "text": "Hi, text from Plivo"}' \
    https://api.plivo.com/v1/Account/{auth_id}/Message/

Next Step

Learn how to customize your SMS sender ID with alphanumeric characters.

  1. Send a Single SMS
  2. Send a Long SMS
  3. Send Multiple (Bulk) SMS
  4. Send an SMS with Alphanumeric Sender ID
  5. Receive an SMS
  6. Reply to an Incoming SMS
  7. Forward an Incoming SMS
  8. Get Details of all Messages
  9. Get Details of a Single Message
  10. Handling SMS Delivery Reports
  11. Forward SMS to Email