Get Details of all Messages

Once the Message API request is successful, your SMS will be put into a queue to be sent to its destination. Plivo has a throughput of 1 SMS per second. That is, Plivo will send 1 SMS every second for each 'src' (source) number in the API request.

To get the details of all Messages, make an HTTP GET request to the Message API.

GET https://api.plivo.com/v1/Account/{auth_id}/Message/
Note: Long SMS messages are automatically split and concatenated into a seamless user experience. When checking Message Logs and Delivery Reports for long SMS messages that are split, look for the ParentMessageUUID, which is the same in all split messages and identical to the UUID of the first message in the split sequence of messages.
Advanced Hack: See the Message API page for full details of the API.

Prerequisites

  1. Sign up for a free Plivo trial account.
  2. Check out our Helper Libraries page and install the right helper based on the programming language you want to use.

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.

Code

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

auth_id = "Your AUTH_ID"
auth_token = "Your AUTH_TOKEN"
p = plivo.RestAPI(auth_id, auth_token)

# Get Details of all Messages
response = p.get_messages()

# Prints the complete response
print str(response)

# Filtering the records
params = {
    'limit': '2', # The number of results per page
    'offset': '0', # The number of items by which the results should be offset
    'message_state': "delivered", # The state of the message to be filtered
    'message_direction': "inbound" # The direction of the message to be fltered
}

response = p.get_messages(params)
# Prints the complete response
print str(response)
 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
require 'rubygems'
require 'plivo'
include Plivo

AUTH_ID = "Your AUTH_ID"
AUTH_TOKEN = "Your AUTH_TOKEN"
p = RestAPI.new(AUTH_ID, AUTH_TOKEN)

response = p.get_messages()

# Prints the details of all messages
puts response

# Filtering the records
params = {
    'limit' => '2', # The number of results per page
    'offset' => '0', # The number of items by which the results should be offset
    'message_state' => "delivered", # The state of the message to be filtered
    'message_direction' => "inbound" # The direction of the message to be fltered
}

response = p.get_messages(params)

# Prints the details of all messages
puts response
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
var plivo = require('plivo');
var p = plivo.RestAPI({
    authId: 'Your AUTH_ID',
    authToken: 'Your AUTH_TOKEN'
});

var params = {};
p.get_messages(params, function (status, response) {
    console.log('Status: ', status);
    console.log('API Response:\n', response);
});

// Filtering the records
var params1 = {
    'limit': '2', // The number of results per page
    'offset': '0', // The number of items by which the results should be offset
    'message_state': "delivered", // The state of the message to be filtered
    'message_direction': "inbound" // The direction of the message to be fltered
};
p.get_messages(params1, function (status, response) {
    console.log('Status: ', status);
    console.log('API Response:\n', response);
});
 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
<?php
    require 'vendor/autoload.php';
    use Plivo\RestAPI;
    $auth_id = "Your AUTH_ID";
    $auth_token = "Your AUTH_TOKEN";
    $p = new RestAPI($auth_id, $auth_token);

    // Fetch the details
    $response = $p->get_messages();

    // Print the response
    print_r ($response['response']);

    // Filter the response
    $params = array(
        'limit' => '2', // The number of results per page
        'offset' => '0', // The number of items by which the results should be offset
        'message_direction ' => 'inbound', // The state of the message to be filtered
        'message_state' => 'delivered' // The direction of the message to be fltered
    );

    // Fetch the details
    $response = $p->get_messages($params);

    // Print the response
    print_r ($response['response']);
?>
 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
package com.plivo.test;

import java.util.LinkedHashMap;
import com.plivo.helper.api.client.*;
import com.plivo.helper.api.response.message.MessageResponse;
import com.plivo.helper.exception.PlivoException;

public class GetAllDetails {
    public static void main(String[] args) {
        String authId = "Your AUTH_ID";
        String authToken = "Your AUTH_TOKEN";
        RestAPI api = new RestAPI(authId, authToken, "v1");
        try {
            // Get details off all the messages
            MessageFactory msg = api.getMessages();
            // Print the complete response
            System.out.println(msg);
        } catch (PlivoException e) {
            System.out.println(e.getLocalizedMessage());
        }

        // Filtering the records
        LinkedHashMap<String, String> parameters = new LinkedHashMap<String, String>();
        parameters.put("limit", "2"); // The number of results per page
        parameters.put("offset", "0"); // The number of items by which the results should be offset
        parameters.put("message_state", "sent"); // The state of the message to be filtered
        parameters.put("message_direction", "outbound"); // The direction of the message to be fltered

        try {
            MessageFactory msg = api.getMessages(parameters);
            // Print the complete response
            System.out.println(msg);
        } catch (PlivoException e) {
            System.out.println(e.getLocalizedMessage());
        }
    }
}
 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
using System;
using System.Collections.Generic;
using System.Reflection;
using RestSharp;
using Plivo.API;

namespace GetAllDetails
{
    class Program
    {
        static void Main(string[] args)
        {
            RestAPI plivo = new RestAPI("Your AUTH_ID", "Your AUTH_TOKEN");
            IRestResponse<MessageList> resp = plivo.get_messages();

            //Prints the message details
            Console.Write(resp.Content);

            // Filter the response
            IRestResponse<MessageList> response = plivo.get_messages(new Dictionary<string, string>()
            {
                { "limit", "2" }, // Number of results per page
                { "offset", "0" }, // The number of items by which the results should be offset
                { "message_state", "delivered" }, // The state of the message to be filtered
                { "message_direction", "inbound"} // The direction of the message to be filtered
            });

            // Print the response
            Console.WriteLine(response.Content);

            Console.ReadLine();
        }
    }
}
1
2
curl -i --user AUTH_ID:AUTH_TOKEN \
    https://api.plivo.com/v1/Account/{auth_id}/Message/

Sample Response

# Without Filter

(202,
    {
    u'meta': {
       u'previous': None, 
       u'total_count': 247, 
       u'offset': 0, 
       u'limit': 3, 
       u'next': u'/v1/Account/XXXXXXXXXXXXXXX/Message/?limit=20&offset=0'
   }, 
   u'objects': [
       {
           u'message_state': u'sent', 
           u'total_amount': u'0.00650', 
           u'to_number': u'2222222222', 
           u'total_rate': u'0.00650', 
           u'message_direction': u'outbound', 
           u'from_number': u'1111111111', 
           u'message_uuid': u'1aead330-8ff9-11e4-9bd8-22000afa12b9', 
           u'message_time': u'2014-12-30 11:54:38+04:00', 
           u'units': 1, 
           u'message_type': u'sms', 
           u'resource_uri': u'/v1/Account/XXXXXXXXXXXXXXX/Message/1aead330-8ff9-11e4-9bd8-22000afa12b9/'
       }, 
       {
           u'message_state': u'delivered', 
           u'total_amount': u'0.00000', 
           u'to_number': u'1111111111', 
           u'total_rate': u'0.00000', 
           u'message_direction': u'inbound', 
           u'from_number': u'2222222222', 
           u'message_uuid': u'15fbd64e-8ff9-11e4-b1a4-22000ac693b1', 
           u'message_time': u'2014-12-30 11:54:30+04:00', 
           u'units': 1, 
           u'message_type': u'sms', 
           u'resource_uri': u'/v1/Account/XXXXXXXXXXXXXXX/Message/15fbd64e-8ff9-11e4-b1a4-22000ac693b1/'
       }
   ], 
       u'api_id': u'625944ba-9259-11e4-96e3-22000abcb9af'
   }
)

# With Filter

(200, {
      u'meta': {
              u'previous': None,
              u'total_count': 215,
              u'offset': 0,
              u'limit': 10,
              u'next': u'/v1/Account/XXXXXXXXXXXXXXX/Message/?limit=2&offset=0'
      },
      u'objects': [
              {
                      u'message_state': u'delivered',
                      u'total_amount': u'0.00650',
                      u'to_number': u'2222222222',
                      u'total_rate': u'0.00650',
                      u'message_direction': u'inbound',
                      u'from_number': u'1111111111',
                      u'message_uuid': u'2d55d550-8a73-11e4-9bd8-22000afa12b9',
                      u'message_time': u'2014-12-23 12:43:21+05:30',
                      u'units': 1,
                      u'message_type': u'sms',
                      u'resource_uri': u'/v1/Account/XXXXXXXXXXXXXXX/Message/2d55d550-8a73-11e4-9bd8-22000afa12b9/'
              },
              {
                      u'message_state': u'delivered',
                      u'total_amount': u'0.00650',
                      u'to_number': u'2222222222',
                      u'total_rate': u'0.00650',
                      u'message_direction': u'inbound',
                      u'from_number': u'1111111111',
                      u'message_uuid': u'2d5617e0-8a73-11e4-89de-22000ae885b8',
                      u'message_time': u'2014-12-23 12:43:21+05:30',
                      u'units': 1,
                      u'message_type': u'sms',
                      u'resource_uri': u'/v1/Account/XXXXXXXXXXXXXXX/Message/2d5617e0-8a73-11e4-89de-22000ae885b8/'
              }
      ]
)

Next Step

Learn how to get details of a single SMS message.

  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 a Single Message
  9. Handling SMS Delivery Reports
  10. Forward SMS to Email