SendMessage

From CDYNE Wiki
Jump to navigation Jump to search

Send regular SMS or multimedia MMS message - to a single recipient or multiple recipients. Each MMS message must be no larger than 1MB in size.

SendMessage Request

Parameter Name Data Type Sample Input Required
Attachments: Add attachments to message. Can be a URL or MediaID. String https://i.pinimg.com/736x/01/5.jpg OR 17772 FALSE
(When sending SMS message or Body parameter has a value for MMS message.)
Body: Message content String This is a sample message. FALSE
(When sending MMS message and Attachment parameter has a value.)
TRUE
(When sending SMS message.)
Subject: Subject line content of message. String CDYNE test FALSE
LicenseKey: Required to authenticate users invoking this Web Service.
Trial Key
Production Key
GUID f01d89fd-5155-5455-5585-e84ab8de8591 TRUE
From: DID/short code used to send message. String 15559080983 FALSE
To: Recipient number. String 15551234567 TRUE
Concatenate: Flag to indicate if concatenation headers should be added to messages that were broken into fragments. Boolean false FALSE
IsUnicode: Flag to indicate if message should be sent using Unicode encoding. Boolean false FALSE
PostbackUrl: Flag to indicate if message should be sent using Unicode encoding. String http://www.cdyne.com/postback.aspx FALSE
ReferenceID: Unique ID that can be set. String 123 FALSE
ScheduleDateTime: UTC date/time when message will send. DateTime 1999-05-31T11:20:00 FALSE
UseMMS: Flag when message includes multimedia content. Boolean true TRUE

SendMessage Response

Parameter Name Data Type Sample Output
Attachments: MediaID of attachment sent in message. String 12486
From: DID/short code used to send message. String 15559080983
MessageID: Unique ID set to outgoing message. GUID 1627aea5-8e0a-4371-9022-9b504344e724
MessageStatus: Status of outgoing message. String Ready
(Complete list of return codes.)
Sent Time: UTC date and time message sent. DateTime 1999-05-31T11:20:00
To: Recipient number. String 15551234567

JSON Request

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

{
	"Attachments": ["https://i.pinimg.com/736x/01/59/40/01594057534c60f94af3165f26d85629--monkey-humor-toddler-christmas.jpg"],
        "Body":"",
        "Subject":"",
        "LicenseKey": "f01d89fd-5155-5455-5585-e84ab8de8591",
        "From" : "15551234567",
	"To": ["15551234568"],
        "Concatenate":false, 
        "IsUnicode":false, 
	"PostBackUrl":"",
	"ReferenceID":"",
        "ScheduledDateTime":"\/Date(1239018869048)\/",
	"UseMMS": true
}

Ruby

 1 require 'uri'
 2 require 'net/http'
 3 
 4 url = URI("http://messaging.cdyne.com/Messaging.svc/SendMessage")
 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         "Attachments": ["https://i.pinimg.com/736x/01/59/40/01594057534c60f94af3165f26d85629--monkey-humor-toddler-christmas.jpg"],
14         "Body":"",
15         "Subject":"",
16         "LicenseKey": "f01d89fd-5155-5455-5585-e84ab8de8591",
17         "From" : "15551234567",
18 	"To": ["15551234568"],
19         "Concatenate":false, 
20         "IsUnicode":false, 
21 	"PostBackUrl":"",
22 	"ReferenceID":"",
23         "ScheduledDateTime":"\/Date(1239018869048)\/",
24 	"UseMMS": true
25 }'
26 
27 response = http.request(request)
28 
29 puts response.read_body
30 gets response.read_body

C#

 1 /*http://messaging.cdyne.com/Messaging.svc?wsdl was added as Service Reference and given the name WSDL*/
 2 
 3 using System;
 4 using System.Collections.Generic;
 5 using System.Linq;
 6 using System.Text;
 7 using System.Threading.Tasks;
 8 using SendMessage.WSDL;
 9 
10 namespace SendMessage
11 {
12     class Program
13     {
14         static void Main(string[] args)
15         {
16             MessagingClient client = new MessagingClient("mms2wsHttpBinding");
17             OutgoingMessageRequest req = new OutgoingMessageRequest();
18 
19             req.Attachments = new string[] {@"https://i.pinimg.com/736x/01/59/40/01594057534c60f94af3165f26d85629--monkey-humor-toddler-christmas.jpg"};
20             req.Body = "";
21             req.Subject = "";
22             req.LicenseKey = new Guid("f01d89fd-5155-5455-5585-e84ab8de8591");
23             req.From = "15559080983";
24             req.To = new string[] {"15551234567"};
25             req.Concatenate = false;
26             req.IsUnicode = false;
27             req.PostbackUrl = "";
28             req.ReferenceID = "";
29             req.ScheduledDateTime = new DateTime(2017, 10, 09, 14, 15, 0).ToUniversalTime();
30             req.UseMMS = true;
31 
32 
33             OutgoingMessageResponse[] resp = client.SendMessage(req);
34 
35             foreach (var item in resp)
36             {
37                 Console.WriteLine("MessageID: " + item.MessageID + Environment.NewLine +
38                                   "Message Status: " + item.MessageStatus + Environment.NewLine +
39                                   "To: " + item.To + Environment.NewLine +
40                                   "From: " + item.From + Environment.NewLine +
41                                   "UTC Time Sent: " + item.SentTime + Environment.NewLine +
42                                   "Attachments: " + item.Attachments);
43             }
44           
45             Console.ReadLine();
46         }
47     }
48 }

VB.Net

 1 'http://messaging.cdyne.com/Messaging.svc?wsdl was added as Service Reference and given the name WSDL
 2 
 3 Imports SendMessage.WSDL
 4 
 5 Module Module1
 6 
 7     Sub Main()
 8 
 9         Dim client As WSDL.MessagingClient = New MessagingClient("mms2wsHttpBinding")
10 
11         Dim req As WSDL.OutgoingMessageRequest = New WSDL.OutgoingMessageRequest()
12 
13         req.Attachments = New String() {"https://i.pinimg.com/736x/01/59/40/01594057534c60f94af3165f26d85629--monkey-humor-toddler-christmas.jpg"}
14         req.Body = ""
15         req.Subject = "Monkey"
16         req.LicenseKey = New Guid("f01d89fd-5155-5455-5585-e84ab8de8591")
17         req.From = "15559080983"
18         req.To = New String() {"15551234567"}
19         req.Concatenate = False
20         req.IsUnicode = False
21         req.PostbackUrl = "http://cdyne.com/postback.aspx"
22         req.ReferenceID = ""
23         req.ScheduledDateTime = New DateTime(2017, 10, 9, 14, 15, 0).ToUniversalTime()
24         req.UseMMS = True
25 
26         Dim resp As OutgoingMessageResponse() = client.SendMessage(req)
27 
28         For Each item In resp
29 
30             Console.WriteLine("MessageID: " + Convert.ToString(item.MessageID) + Environment.NewLine +
31                                   "Message Status: " + Convert.ToString(item.MessageStatus) + Environment.NewLine +
32                                   "To: " + item.To + Environment.NewLine +
33                                   "From: " + item.From + Environment.NewLine +
34                                   "UTC Time Sent: " + Convert.ToString(item.SentTime) + Environment.NewLine +
35                                   "Attachments: " + item.Attachments)
36         Next
37 
38         Console.ReadLine()
39 
40     End Sub
41 
42 End Module

PHP with cURL

 1 <?php
 2 
 3 $json='{
 4 	"Attachments":["https://i.pinimg.com/736x/01/59/40/01594057534c60f94af3165f26d85629--monkey-humor-toddler-christmas.jpg"],
 5 	"Body":"",
 6 	"Concatenate":false, 
 7 	"From":"15559080983",
 8 	"IsUnicode":false, 
 9 	"LicenseKey":"f01d89fd-5155-5455-5585-e84ab8de8591",
10 	"PostbackUrl":"http://cdyne.com/postback.aspx",
11 	"ReferenceID":"",
12 	"ScheduledDateTime":"\/Date(1239018869048)\/",
13 	"Subject":"",
14 	"To":["15553096094"],
15 	"UseMMS":true	
16 }';
17 
18 $url='http://messaging.cdyne.com/Messaging.svc/SendMessage';
19 $cURL = curl_init();
20  
21 curl_setopt($cURL,CURLOPT_URL,$url);
22 curl_setopt($cURL,CURLOPT_POST,true);
23 curl_setopt($cURL,CURLOPT_POSTFIELDS,$json);
24 curl_setopt($cURL,CURLOPT_RETURNTRANSFER, true);  
25 curl_setopt($cURL, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Accept: application/json'));
26 //If you desire your results in xml format, use the following line for your httpheaders and comment out the httpheaders code line above.
27 //curl_setopt($cURL, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); 
28 $result = curl_exec($cURL);
29 
30 curl_close($cURL);
31 
32 $array = json_decode($result, true);
33 //print_r($json);
34 //print_r("\n\n\n\n");
35 
36 print_r($array);
37 
38 ?>


VBScript

 1 Dim cXML
 2 cXML = "<OutgoingMessageRequest xmlns=""http://sms2.cdyne.com"">" & _
 3   "<Attachments>" & _
 4     "<string xmlns=""http://schemas.microsoft.com/2003/10/Serialization/Arrays"">https://i.pinimg.com/736x/01/59/40/01594057534c60f94af3165f26d85629--monkey-humor-toddler-christmas.jpg</string>" & _
 5   "</Attachments>" & _
 6   "<Body></Body>" & _
 7   "<Concatenate>false</Concatenate>" & _
 8   "<From>15559080983</From>" & _
 9   "<IsUnicode>false</IsUnicode>" & _
10   "<LicenseKey>f01d89fd-5155-5455-5585-e84ab8de8591</LicenseKey>" & _
11   "<PostbackUrl></PostbackUrl>" & _
12   "<ReferenceID></ReferenceID>" & _
13   "<ScheduledDateTime>1999-05-31T11:20:00</ScheduledDateTime>" & _
14   "<Subject></Subject>" & _
15   "<To>" & _
16     "<string xmlns=""http://schemas.microsoft.com/2003/10/Serialization/Arrays"">15553096094</string>" & _
17   "</To>" & _
18   "<UseMMS>true</UseMMS>" & _
19 "</OutgoingMessageRequest>"
20 
21 Dim oXMLHTTP
22 Set oXMLHTTP = CreateObject("Microsoft.XMLHTTP")
23 Set oDoc = CreateObject("MSXML2.DOMDocument")
24 Call oXMLHttp.Open("POST", "http://messaging.cdyne.com/Messaging.svc/SendMessage", False)
25 Call oXMLHttp.setRequestHeader("Content-Type", "text/xml")        
26 Call oXMLHttp.send(cXML)
27 
28 MsgBox oXMLHTTP.responseText 
29 
30 Const ForReading = 1, ForWriting = 2, ForAppending = 8
31 Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
32 Dim fso, MyFile, FileName, TextLine
33 Set fso = CreateObject("Scripting.FileSystemObject")
34 FileName = "c:\Users\Desktop\MMS.txt"
35 Set MyFile = fso.OpenTextFile(FileName, ForWriting, True)
36 MyFile.WriteLine oXMLHttp.responseText
37 MyFile.Close
38 Set MyFile = fso.OpenTextFile(FileName, ForReading)
39 Do While MyFile.AtEndOfStream <> True
40 TextLine = MyFile.ReadLine
41 Loop
42 MyFile.Close
43 
44 set request = nothing


JAVA

 1 import java.io.BufferedReader;
 2 import java.io.InputStreamReader;
 3 import java.io.PrintWriter;
 4 import java.net.HttpURLConnection;
 5 import java.net.URL;
 6 
 7 public final class SendMessage {
 8 
 9     public static void main(String[] args) throws Exception {
10         String responseContent = "";
11         String response = "";
12 
13         URL url = new URL("http://messaging.cdyne.com/Messaging.svc/SendMessage");
14         HttpURLConnection connection = (HttpURLConnection) url.openConnection();
15 
16         StringBuilder sb = new StringBuilder("<OutgoingMessageRequest xmlns=\"http://sms2.cdyne.com\">");
17         sb.append("<Attachments>");
18         sb.append("<string xmlns=\"http://schemas.microsoft.com/2003/10/Serialization/Arrays\">https://i.pinimg.com/736x/01/59/40/01594057534c60f94af3165f26d85629--monkey-humor-toddler-christmas.jpg</string>");
19         sb.append("</Attachments>");
20         sb.append("<Body></Body>");
21         sb.append("<Concatenate>false</Concatenate>");
22         sb.append("<From>15559080983</From>");
23         sb.append("<IsUnicode>false</IsUnicode>");
24         sb.append("<LicenseKey>f01d89fd-5155-5455-5585-e84ab8de8591</LicenseKey>");
25         sb.append("<PostBackUrl></PostBackUrl>");
26         sb.append("<ReferenceID></ReferenceID>");
27         sb.append("<ScheduledDateTime>2013-01-15T20:53:00.608Z</ScheduledDateTime>");
28         sb.append("<Subject>Testing Java</Subject>");
29         sb.append("<To>");
30         sb.append("<string xmlns=\"http://schemas.microsoft.com/2003/10/Serialization/Arrays\">15553096094</string>");
31         sb.append("</To>");
32         sb.append("<UseMMS>true</UseMMS>");
33         sb.append("</OutgoingMessageRequest>");
34 
35         connection.setRequestProperty("Content-Length", String.valueOf(sb.toString().length()));
36         connection.setRequestProperty("Content-Type", "text/xml");
37         connection.setRequestProperty("Connection", "Close");
38         connection.setRequestProperty("SoapAction", "");
39         connection.setRequestMethod("POST");
40         connection.setDoInput(true);
41         connection.setDoOutput(true);
42 
43         PrintWriter pw = new PrintWriter(connection.getOutputStream());
44         pw.write(sb.toString());
45         pw.flush();
46         connection.connect();
47 
48         System.out.println(sb.toString());
49         BufferedReader br;
50 
51         if (connection.getResponseCode() == 200) {
52             br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
53         } else {
54             br = new BufferedReader(new InputStreamReader(connection.getErrorStream()));
55         }
56 
57         while ((responseContent = br.readLine()) != null) {
58             response += responseContent;
59         }
60         System.out.println(response);
61     }
62 }