ReadIncomingMessages

From CDYNE Wiki
Jump to navigation Jump to search

Read incoming messages - you can view new or all incoming messages.

ReadIncomingMessages Request

Parameter Name Data Type Sample Input Required
EndDate: UTC date and time of most recent incoming message. DateTime 1999-05-31T11:20:00 FALSE
IncomingMessageID: Unique ID assigned to incoming message. GUID 1627aea5-8e0a-4371-9022-9b504344e724 FALSE
LicenseKey: License key used to receive incoming message
Trial Key
Production Key
GUID f01d89fd-5155-5455-5585-e84ab8de8591 TRUE
OutgoingMessageID: Unique ID of outgoing message. GUID 1627aea5-8e0a-4371-9022-9b504344e724 FALSE
PageNumber: Number of page where incoming message is located. Int 0 FALSE
PageSize: Number of incoming messages shown on page. Int 0 FALSE
ReferenceID: Unique ID that can be set. String 123 FALSE
StartDate: UTC date and time of earliest incoming message received. DateTime 1999-05-31T11:20:00 FALSE
UnreadMessagesOnly: You can choose to view all incoming messages or only incoming messages that are unread. Boolean false FALSE

ReadIncomingMessages Response

Parameter Name Data Type Sample Output
Attachment: MediaID of attachment sent in message. String 12486
From: DID/short code used to send message. String 15559080983
IncomingMessageID: Unique ID assigned to incoming message. GUID 1627aea5-8e0a-4371-9022-9b504344e724
OutgoingMessageID: Unique ID assigned to outgoing message. GUID 1627aea5-8e0a-4371-9022-9b504344e724
Payload: Incoming message content. String Thank you for your message
ReceivedDate: UTC date and time incoming message was received. DateTime 1999-05-31T11:20:00
Subject: Subject of incoming message. String Reply

| To: Recipient number. | String | 15551234567 |-

| Udh: Header that shows number of concatenated messages in correct order. | Int | 81,109,70,122,90,83,65,50,78,67,66,84,100 |- |}

JSON Request

The following is an example POST request using http://messaging.cdyne.com/Messaging.svc/ReadIncomingMessages

{
	"EndDate":"\/Date(1506973090870+0000)\/",
	"LicenseKey":"f01d89fd-5155-5455-5585-e84ab8de8591",
        "PageNumber": 0,
        "PageSize": 0,
        "ReferenceID": "",
	"StartDate":"\/Date(1506973090870+0000)\/",
	"UnreadMessagesOnly":false
}

Ruby

 1 require 'uri'
 2 require 'net/http'
 3 
 4 url = URI("http://messaging.cdyne.com/Messaging.svc/ReadIncomingMessages")
 5 
 6 http = Net::HTTP.new(url.host, url.port)
 7 
 8 request = Net::HTTP::Post.new(url)
 9 
10 request["content-type"] = 'application/json'
11 
12 request.body = '{
13 "EndDate":"\/Date(1506973090870+0000)\/",
14 "LicenseKey":"f01d89fd-5155-5455-5585-e84ab8de8591",
15 "PageNumber": 0,
16 "PageSize": 0,
17 "ReferenceID": "",
18 "StartDate": "\/Date(1506973090870+0000)\/",
19 "UnreadMessagesOnly": false}'
20 
21 response = http.request(request)
22 
23 puts response.read_body
24 gets response.read_body

C#

<code type=

 1 >
 2 
 3 /*http://messaging.cdyne.com/Messaging.svc?wsdl was added as Service Reference and given the name WSDL*/
 4 
 5 using System;
 6 using System.Collections.Generic;
 7 using System.Linq;
 8 using System.Text;
 9 using System.Threading.Tasks;
10 using ReadIncomingMessages.WSDL;
11 
12 namespace ReadIncomingMessages
13 {
14     class Program
15     {
16         static void Main(string[] args)
17         {
18             MessagingClient client = new MessagingClient("mms2wsHttpBinding");
19             IncomingMessageCriteria incoming = new IncomingMessageCriteria();
20 
21             incoming.EndDate = new DateTime(2017, 10, 06, 17, 00, 0).ToUniversalTime();
22             incoming.IncomingMessageID = new Guid();
23             incoming.LicenseKey = new Guid("f01d89fd-5155-5455-5585-e84ab8de8591");
24             incoming.OutgoingMessageID = new Guid();
25             incoming.PageNumber = 0;
26             incoming.PageSize = 0;
27             incoming.ReferenceID = "";
28             incoming.StartDate = new DateTime(1990, 10, 01, 14, 15, 0).ToUniversalTime();
29             incoming.UnreadMessagesOnly = false;
30 
31             IncomingMessageResponse[] resp = client.ReadIncomingMessages(incoming);
32 
33             if (resp.Length > 0)
34             {
35                 foreach (var item in resp)
36                 {
37                     Console.WriteLine("Incoming MessageID: " + item.IncomingMessageID + Environment.NewLine +
38                                  "Outgoing MessageID: " + item.OutgoingMessageID + Environment.NewLine +
39                                  "To: " + item.To + Environment.NewLine +
40                                  "From: " + item.From + Environment.NewLine +
41                                  "UTC Time Received: " + item.ReceivedDate + Environment.NewLine +
42                                  "Message Subject: " + item.Subject + Environment.NewLine +
43                                  "Message Text: " + item.Payload);
44 
45                     if (item.Attachments != null)
46                     {
47                         foreach (var media in item.Attachments)
48                         {
49                             Console.WriteLine("Attachments: " + media);
50                         }
51                     }
52 
53                     else Console.WriteLine("Attachments: No media.");
54 
55                     Console.WriteLine("UDH Info: " + item.Udh);
56                 }
57             }
58              
59              Console.ReadLine();
60         }
61     }
62 }

VB.Net

<code type=

 1 >
 2 
 3 'http://messaging.cdyne.com/Messaging.svc?wsdl was added as Service Reference and given the name WSDL
 4 
 5 Imports ReadIncomingMessages.WSDL
 6 
 7 Module Module1
 8 
 9     Sub Main()
10 
11         Dim client As WSDL.MessagingClient = New MessagingClient("mms2wsHttpBinding")
12 
13         Dim req As New WSDL.IncomingMessageCriteria()
14 
15         req.EndDate = New DateTime(2017, 10, 6, 17, 0, 0).ToUniversalTime()
16         req.IncomingMessageID = New Guid()
17         req.LicenseKey = New Guid("f01d89fd-5155-5455-5585-e84ab8de8591")
18         req.OutgoingMessageID = New Guid()
19         req.PageNumber = 0
20         req.PageSize = 0
21         req.ReferenceID = ""
22         req.StartDate = New DateTime(1990, 10, 1, 14, 15, 0).ToUniversalTime()
23         req.UnreadMessagesOnly = False
24 
25         Dim resp As IncomingMessageResponse() = client.ReadIncomingMessages(req)
26 
27         If resp.Length > 0 Then
28 
29             For Each item In resp
30 
31                 Console.WriteLine("Incoming MessageID: " + Convert.ToString(item.IncomingMessageID) + Environment.NewLine +
32                                  "Outgoing MessageID: " + Convert.ToString(item.OutgoingMessageID) + Environment.NewLine +
33                                  "To: " + item.To + Environment.NewLine +
34                                  "From: " + item.From + Environment.NewLine +
35                                  "UTC Time Received: " + Convert.ToString(item.ReceivedDate) + Environment.NewLine +
36                                  "Message Subject: " + item.Subject + Environment.NewLine +
37                                  "Message Text: " + item.Payload + Environment.NewLine +
38                                 "UDH Info: " + Convert.ToString(item.Udh))
39 
40                 If item.Attachments IsNot Nothing Then
41 
42                     For Each attach In item.Attachments
43 
44                         Console.WriteLine("Attachments: " + Convert.ToString(attach))
45 
46                     Next
47 
48                     Console.WriteLine()
49 
50                 Else Console.WriteLine("Attachments: No media.")
51 
52                     Console.WriteLine()
53 
54                 End If
55 
56             Next
57 
58         End If
59 
60         Console.ReadLine()
61 
62     End Sub
63 
64 End Module

PHP with cURL

<code type=

 1 >
 2 <?php
 3 
 4 $json='{
 5 	"EndDate":"\/Date(1506973090870+0000)\/",
 6 	"LicenseKey":"f01d89fd-5155-5455-5585-e84ab8de8591",
 7 	"StartDate":"\/Date(1506973090870+0000)\/",
 8 	"UnreadMessagesOnly":false
 9 }';
10 
11 $url='http://messaging.cdyne.com/Messaging.svc/ReadIncomingMessages';
12 $cURL = curl_init();
13  
14 curl_setopt($cURL,CURLOPT_URL,$url);
15 curl_setopt($cURL,CURLOPT_POST,true);
16 curl_setopt($cURL,CURLOPT_POSTFIELDS,$json);
17 curl_setopt($cURL,CURLOPT_RETURNTRANSFER, true);  
18 curl_setopt($cURL, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Accept: application/json'));
19 //If you desire your results in xml format, use the following line for your httpheaders and comment out the httpheaders code line above.
20 //curl_setopt($cURL, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); 
21 $result = curl_exec($cURL);
22 
23 curl_close($cURL);
24 
25 $array = json_decode($result, true);
26 //print_r($json);
27 //print_r("\n\n\n\n");
28 
29 print_r($array);
30 
31 ?>

VBScript

<code type=

 1 >
 2 
 3 Dim cXML
 4 cXML = "<IncomingMessageCriteria xmlns=""http://sms2.cdyne.com"">" & _
 5   "<EndDate>2017-10-31T11:20:00</EndDate>" & _
 6   "<LicenseKey>f01d89fd-5155-5455-5585-e84ab8de8591</LicenseKey>" & _
 7   "<StartDate>2017-10-01T11:20:00</StartDate>" & _
 8   "<UnreadMessagesOnly>false</UnreadMessagesOnly>" & _
 9   "</IncomingMessageCriteria>"
10 
11 Dim oXMLHTTP
12 Set oXMLHTTP = CreateObject("Microsoft.XMLHTTP")
13 Set oDoc = CreateObject("MSXML2.DOMDocument")
14 Call oXMLHttp.Open("POST", "http://messaging.cdyne.com/Messaging.svc/ReadIncomingMessages", False)
15 Call oXMLHttp.setRequestHeader("Content-Type", "text/xml")        
16 Call oXMLHttp.send(cXML)
17 
18 MsgBox oXMLHTTP.responseText 
19 
20 Const ForReading = 1, ForWriting = 2, ForAppending = 8
21 Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
22 Dim fso, MyFile, FileName, TextLine
23 Set fso = CreateObject("Scripting.FileSystemObject")
24 FileName = "c:\Users\Desktop\MMS.txt"
25 Set MyFile = fso.OpenTextFile(FileName, ForWriting, True)
26 MyFile.WriteLine oXMLHttp.responseText
27 MyFile.Close
28 Set MyFile = fso.OpenTextFile(FileName, ForReading)
29 Do While MyFile.AtEndOfStream <> True
30 TextLine = MyFile.ReadLine
31 Loop
32 MyFile.Close
33 
34 set request = nothing

JAVA

<code type=

 1 >
 2 
 3 import java.io.BufferedReader;
 4 import java.io.InputStreamReader;
 5 import java.io.PrintWriter;
 6 import java.net.HttpURLConnection;
 7 import java.net.URL;
 8 
 9 public final class ReadIncomingMessages {
10 
11     public static void main(String[] args) throws Exception {
12         String responseContent = "";
13         String response = "";
14 
15         URL url = new URL("http://messaging.cdyne.com/Messaging.svc/ReadIncomingMessages");
16         HttpURLConnection connection = (HttpURLConnection) url.openConnection();
17 
18         StringBuilder sb = new StringBuilder("<IncomingMessageCriteria xmlns=\"http://sms2.cdyne.com\">");
19         sb.append("<EndDate>2017-10-31T11:20:00</EndDate>");
20         sb.append("<LicenseKey>f01d89fd-5155-5455-5585-e84ab8de8591</LicenseKey>");
21         sb.append("<StartDate>2017-10-01T11:20:00</StartDate>");
22         sb.append("<UnreadMessagesOnly>false</UnreadMessagesOnly>");
23         sb.append("</IncomingMessageCriteria>");
24 
25         connection.setRequestProperty("Content-Length", String.valueOf(sb.toString().length()));
26         connection.setRequestProperty("Content-Type", "text/xml");
27         connection.setRequestProperty("Connection", "Close");
28         connection.setRequestProperty("SoapAction", "");
29         connection.setRequestMethod("POST");
30         connection.setDoInput(true);
31         connection.setDoOutput(true);
32 
33         PrintWriter pw = new PrintWriter(connection.getOutputStream());
34         pw.write(sb.toString());
35         pw.flush();
36         connection.connect();
37 
38         System.out.println(sb.toString());
39         BufferedReader br;
40 
41         if (connection.getResponseCode() == 200) {
42             br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
43         } else {
44             br = new BufferedReader(new InputStreamReader(connection.getErrorStream()));
45         }
46 
47         while ((responseContent = br.readLine()) != null) {
48             response += responseContent;
49         }
50         System.out.println(response);
51     }
52 }