SMS API

ReadIncomingMessages

This method reads incoming messages. You can retrieve all incoming messages or only unread messages.

Endpoint

POST:
https://messaging.esendex.us/Messaging.svc/ReadIncomingMessages

Syntax

ReadIncomingMessages(Request)

Request Parameters

Parameter NameDescriptionData TypeRequiredSample Value
EndDateUTC date/time of newest messages to read. Specified as milliseconds from the epoch of 1970-01-01T00:00:00Z.DateTimeFalse\/Date(1682439497785)\/
IncomingMessageIDUnique ID of the incoming message.GUIDFalse1627aea5-8e0a-4371-9022-9b504344e724
LicenseKeyYour license key.GUIDTrue00000000-0000-0000-0000-000000000000
OutgoingMessageIDUnique ID of the outgoing message.GUIDFalse1627aea5-8e0a-4371-9022-9b504344e724
PageNumberNumber of the page to retrieve.IntFalse1
PageSizeNumber of incoming messages per page.IntFalse20
ReferenceIDUnique ID that you assigned to the sent message.StringFalse123
StartDateUTC date/time of oldest messages to read. Specified as milliseconds from the epoch of 1970-01-01T00:00:00Z.DateTimeFalse\/Date(1682439497785)\/
UnreadMessagesOnlyWhether to retrieve all incoming messages or only incoming messages that are unread.BooleanFalsefalse

Response

Returns: Array of IncomingMessageResponse objects

Code Samples

You can use any programming language you want with our API, as long as it can make a REST or SOAP call. Here are examples for some of the most common platforms.

C#

// https://messaging.esendex.us/Messaging.svc?wsdl was added as a Service Reference and given the name WSDL

using WSDL;

var client = new MessagingClient(MessagingClient.EndpointConfiguration.mms2wsHttpBindingSecure);

var criteria = new IncomingMessageCriteria
{
    LicenseKey = YOUR_LICENSE_KEY
};

var messages = await client.ReadIncomingMessagesAsync(criteria);

foreach (var m in messages)
{
    Console.WriteLine(
        "Incoming Message ID: " + m.IncomingMessageID + Environment.NewLine +
        "Outgoing Message ID: " + m.OutgoingMessageID + Environment.NewLine +
        "To: " + m.To + Environment.NewLine +
        "From: " + m.From + Environment.NewLine +
        "UTC Time Received: " + m.ReceivedDate + Environment.NewLine +
        "Message Subject: " + m.Subject + Environment.NewLine +
        "Message Text: " + m.Payload);

    if (m.Attachments is not null)
    {
        foreach (var attachment in m.Attachments)
        {
            Console.WriteLine("Attachment: " + attachment);
        }
    }

    Console.WriteLine(Environment.NewLine);
}

Java

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.HttpURLConnection;
import java.net.URL;

public final class ReadIncomingMessages {
    public static void main(String[] args) throws Exception {
        String responseContent = "";
        String response = "";

        URL url = new URL("https://messaging.esendex.us/Messaging.svc/ReadIncomingMessages");
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();

        StringBuilder sb = new StringBuilder("<IncomingMessageCriteria xmlns=\"https://messaging.esendex.us\">");
        sb.append("<EndDate>2017-10-31T11:20:00</EndDate>");
        sb.append("<LicenseKey>00000000-0000-0000-0000-000000000000</LicenseKey>");
        sb.append("<StartDate>2017-10-01T11:20:00</StartDate>");
        sb.append("<UnreadMessagesOnly>false</UnreadMessagesOnly>");
        sb.append("</IncomingMessageCriteria>");

        connection.setRequestProperty("Content-Length", String.valueOf(sb.toString().length()));
        connection.setRequestProperty("Content-Type", "text/xml");
        connection.setRequestProperty("Connection", "Close");
        connection.setRequestProperty("SoapAction", "");
        connection.setRequestMethod("POST");
        connection.setDoInput(true);
        connection.setDoOutput(true);

        PrintWriter pw = new PrintWriter(connection.getOutputStream());
        pw.write(sb.toString());
        pw.flush();
        connection.connect();

        System.out.println(sb.toString());
        BufferedReader br;

        if (connection.getResponseCode() == 200) {
            br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
        } else {
            br = new BufferedReader(new InputStreamReader(connection.getErrorStream()));
        }

        while ((responseContent = br.readLine()) != null) {
            response += responseContent;
        }
        System.out.println(response);
    }
}

JavaScript

const url = 'https://messaging.esendex.us/Messaging.svc/ReadIncomingMessages';
const response = await fetch(url, {
    headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json'
    },
    body: JSON.stringify({
        'LicenseKey': '00000000-0000-0000-0000-000000000000'
    }),
    method: 'POST'
});
const message = await response.json();

console.log(message);

JSON POST Request

{
	"EndDate": "\/Date(928164000000-0400)\/",
	"IncomingMessageID": "1627aea5-8e0a-4371-9022-9b504344e724",
	"LicenseKey": "1627aea5-8e0a-4371-9022-9b504344e724",
	"OutgoingMessageID": "1627aea5-8e0a-4371-9022-9b504344e724",
	"PageNumber": 2147483647,
	"PageSize": 2147483647,
	"ReferenceID": "String content",
	"StartDate": "\/Date(928164000000-0400)\/",
	"UnreadMessagesOnly": true
}

JSON Response

[
    {
        "Attachments": [
            9223372036854775807
        ],
        "From": "String content",
        "IncomingMessageID": "1627aea5-8e0a-4371-9022-9b504344e724",
        "OutgoingMessageID": "1627aea5-8e0a-4371-9022-9b504344e724",
        "Payload": "String content",
        "ReceivedDate": "\/Date(928164000000-0400)\/",
        "Subject": "String content",
        "To": "String content",
        "Udh": [
            81,
            109,
            70,
            122,
            90,
            83,
            65,
            50,
            78,
            67,
            66,
            84,
            100,
            72,
            74,
            108,
            89,
            87,
            48,
            61
        ]
    }
]

PHP with cURL

<?php

$json = '{
  "EndDate":"\/Date(1506973090870+0000)\/",
  "LicenseKey":"00000000-0000-0000-0000-000000000000",
  "StartDate":"\/Date(1506973090870+0000)\/",
  "UnreadMessagesOnly":false
}';

$url = 'https://messaging.esendex.us/Messaging.svc/ReadIncomingMessages';
$cURL = curl_init();

curl_setopt($cURL, CURLOPT_URL, $url);
curl_setopt($cURL, CURLOPT_POST, true);
curl_setopt($cURL, CURLOPT_POSTFIELDS, $json);
curl_setopt($cURL, CURLOPT_RETURNTRANSFER, true);

curl_setopt($cURL, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Accept: application/json'));
// If you desire your results in XML format, use the following line for your HTTP headers and comment out the HTTP headers code line above.
// curl_setopt($cURL, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));

$result = curl_exec($cURL);
curl_close($cURL);
$array = json_decode($result, true);

// print_r($json);
// print_r("\n\n\n\n");
print_r($array);

?>

Python

import httpx

headers = {"Accept": "application/json"}
url = "https://messaging.esendex.us/Messaging.svc/ReadIncomingMessages"
request = {"LicenseKey": "00000000-0000-0000-0000-000000000000"}

with httpx.Client(headers=headers) as client:
    response = client.post(url=url, json=request)

response.raise_for_status()

print(response.json())

Ruby

require 'json'
require 'net/http'

headers = { Accept: 'application/json', 'Content-Type': 'application/json' }
uri = URI('https://messaging.esendex.us/Messaging.svc/ReadIncomingMessages')

data = {
  'LicenseKey': '00000000-0000-0000-0000-000000000000'
}.to_json

response = Net::HTTP.post(uri, data, headers)
raise response.message if response.is_a?(Net::HTTPClientError) || response.is_a?(Net::HTTPServerError)

puts JSON.parse(response.body)

XML POST Request

<IncomingMessageCriteria xmlns="http://sms2.cdyne.com">
  <EndDate>1999-05-31T11:20:00</EndDate>
  <IncomingMessageID>1627aea5-8e0a-4371-9022-9b504344e724</IncomingMessageID>
  <LicenseKey>1627aea5-8e0a-4371-9022-9b504344e724</LicenseKey>
  <OutgoingMessageID>1627aea5-8e0a-4371-9022-9b504344e724</OutgoingMessageID>
  <PageNumber>2147483647</PageNumber>
  <PageSize>2147483647</PageSize>
  <ReferenceID>String content</ReferenceID>
  <StartDate>1999-05-31T11:20:00</StartDate>
  <UnreadMessagesOnly>true</UnreadMessagesOnly>
</IncomingMessageCriteria>

XML Response

<ArrayOfIncomingMessageResponse xmlns="http://sms2.cdyne.com">
  <IncomingMessageResponse>
    <Attachments>
      <long xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays">9223372036854775807</long>
      <long xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays">9223372036854775807</long>
    </Attachments>
    <From>String content</From>
    <IncomingMessageID>1627aea5-8e0a-4371-9022-9b504344e724</IncomingMessageID>
    <OutgoingMessageID>1627aea5-8e0a-4371-9022-9b504344e724</OutgoingMessageID>
    <Payload>String content</Payload>
    <ReceivedDate>1999-05-31T11:20:00</ReceivedDate>
    <Subject>String content</Subject>
    <To>String content</To>
    <Udh>QmFzZSA2NCBTdHJlYW0=</Udh>
  </IncomingMessageResponse>
  <IncomingMessageResponse>
    <Attachments>
      <long xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays">9223372036854775807</long>
      <long xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays">9223372036854775807</long>
    </Attachments>
    <From>String content</From>
    <IncomingMessageID>1627aea5-8e0a-4371-9022-9b504344e724</IncomingMessageID>
    <OutgoingMessageID>1627aea5-8e0a-4371-9022-9b504344e724</OutgoingMessageID>
    <Payload>String content</Payload>
    <ReceivedDate>1999-05-31T11:20:00</ReceivedDate>
    <Subject>String content</Subject>
    <To>String content</To>
    <Udh>QmFzZSA2NCBTdHJlYW0=</Udh>
  </IncomingMessageResponse>
</ArrayOfIncomingMessageResponse>

Let’s start sending, together.