SimpleSMSSendWithPostback

From CDYNE Wiki
Jump to navigation Jump to search

Send single, immediate text messages from your website or application utilizing the PostBackURL feature. CDYNE SMS Notify! API will automatically post information to a URL you specify when text messages are sent or received via DIDs and short codes.

SimpleSMSSendWithPostback Request

Parameter Name Data Type Sample Input
Phone Number: Input phone number to send SMS text to. String 17575449510
LicenseKey: Required to authenticate users invoking this Web Service.

Trial Key. Production Key.

Guid F01d89fd-5155-5455-5585-e84ab8de8591
Message: Message to send to phone number String This is a sample message from SMS Notify!
StatusPostBackURL: Input to receive posts to your server when SMS

has been sent, and when response is received.

String Server URL

HTTP Method

HTTP Method: GET

Url: http://sms2.cdyne.com/sms.svc/SimpleSMSsendWithPostback?PhoneNumber={PHONENUMBER}&Message={MESSAGE}&LicenseKey={LICENSEKEY}&StatusPostBackURL={STATUSPOSTBACKURL}

Url: https://sms2.cdyne.com/sms.svc/SimpleSMSsendWithPostback?PhoneNumber={PHONENUMBER}&Message={MESSAGE}&LicenseKey={LICENSEKEY}&StatusPostBackURL={STATUSPOSTBACKURL}

SimpleSMSSendWithPostback Response


Parameter Name Data Type Sample Output
Cancelled: Returns true or false if the SMS message has been cancelled. Boolean False
MessageID: Returns unique Guid ID for every SMS message sent. Guid B01d89fd-5155-5455-5585-e84ab8de8591
Queued: Returns true or false if the SMS message has been queued. Boolean True
ReferenceID: A unique ID that can be set using the AdvancedSMSSend method. String
SMSError: Returns a string indicating if there was an error sending the SMS message.
  • NoError
  • STOPfromPhoneNumber
  • LicenseKeyInvalid
  • PhoneNumberInvalid
  • MessageInvalid
  • ScheduledDateTimeIsNotUTC
  • InvalidAssignedDID
  • NotFound (Occurs for Invalid MessageID)
  • InternalError
  • ContactCdyneAccountSuspended
String NoError
SMSIncomingMessages: Returns null when part of a Send response. Null Null
Sent: Returns true or false if the SMS message has been sent to the carrier. Boolean False
SentDateTime: Returns the UTC Date and Time of when the message was sent. Datetime 0001-01-01T00:00:00

XML Response

The following is an example response Xml body:


  <SMSResponse xmlns="http://sms2.cdyne.com">
    <Cancelled>true</Cancelled>
    <MessageID>1627aea5-8e0a-4371-9022-9b504344e724</MessageID>
    <Queued>true</Queued>
    <ReferenceID>String content</ReferenceID>
    <SMSError>NoError</SMSError>
    <SMSIncomingMessages i:nil="true" />
    <Sent>true</Sent>
    <SentDateTime>1999-05-31T11:20:00</SentDateTime>
  </SMSResponse>

Json Response

The following is an example response Json body:


{
	"Cancelled":true,
	"MessageID":"1627aea5-8e0a-4371-9022-9b504344e724",
	"Queued":true,
	"ReferenceID":"String content",
	"SMSError":0,
	"SMSIncomingMessages":null,
	"Sent":true,
	"SentDateTime":"\/Date(928164000000-0400)\/"
}

SimpleSMSSendWithPostback Code Examples

C#

1 smsClient client = new IsmsClient("sms2wsHttpBinding");
2 SMSResponse resp = client.SimpleSMSsendWithPostback("7575449510", "Simple Message", new Guid("YOUR LICENSE KEY"), "http://www.cdyne.com/postback.asmx");  //Single line message request.
3 //SMSResponse resp = client.SimpleSMSsendWithPostback("7575449510", "Simple" + "\n" + "Test", new Guid("YOUR LICENSE KEY"), "http://www.cdyne.com/postback.asmx");  Multi-line message request.
4 Console.WriteLine(resp.MessageID + " " + resp.SMSError.ToString());
5 Console.ReadLine();
6 client.Close();

VB.NET

 1 Imports SimpleSMSSendWithPostBack.WSDL
 2 Module Module1
 3  Sub Main()
 4  Dim client As WSDL.IsmsClient = New WSDL.IsmsClient("sms2wsHttpBinding")
 5  Dim resp As SimplePostBack.WSDL.SMSResponse = client.SimpleSMSsendWithPostback("7575449510", "CDYNE Simple SMS Test with PostBack", New Guid("YOUR LICENSE KEY"), "http://www.cdyne.com/postback.asmx")  'Single line message request.
 6  'Dim resp As SimplePostBack.WSDL.SMSResponse = client.SimpleSMSsendWithPostback("7575449510", "CDYNE Simple SMS Test" & Environment.NewLine & "with PostBack", New Guid("YOUR LICENSE KEY"), "http://www.cdyne.com/postback.asmx")  Multi-line message request.
 7  Console.WriteLine(resp.MessageID)
 8  Console.ReadLine()
 9  client.Close()
10  End Sub
11 End Module

PHP

The following example was built using PHP 5.3.2. Your setup may differ, so please assure that your PHP 5.x version supports the SOAPClient class.

 1 // Create a new soap client based on the SMS Notify! WCF service
 2 $client = new SoapClient('http://sms2.cdyne.com/sms.svc?wsdl');
 3  
 4 // Specify required info to send a text message
 5 $param = array(
 6 	'PhoneNumber' => '5555555555',
 7 	'LicenseKey' => '(LicensKey)',
 8 	'Message' => 'test',
 9 	'StatusPostBackURL' => '(PostBackURL)'
10 );
11  
12 // Send the text message
13 $result = $client->SimpleSMSsendWithPostback($param);
14  
15 // View the response from CDYNE
16 print_r($result);

PHP with cURL

The following example was built using PHP 5.3.2 with cURL

 1 $url='http://sms2.cdyne.com/sms.svc/SimpleSMSsendWithPostback?PhoneNumber=(To Phone Number)&Message=(Message)&LicenseKey=(License Key)&StatusPostBackURL=(Your Postback Url)';
 2 
 3 $cURL = curl_init();
 4 
 5 curl_setopt($cURL,CURLOPT_URL,$url);
 6 curl_setopt($cURL,CURLOPT_HTTPGET,true);
 7 
 8 curl_setopt($cURL, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Accept: application/json'));
 9 
10 $result = curl_exec($cURL);
11 
12 curl_close($cURL);
13 
14 print_r($result);

VBScript

1 Set oXMLHTTP = CreateObject("Microsoft.XMLHTTP")
2 Set oDoc = CreateObject("MSXML2.DOMDocument")
3 Call oXMLHttp.Open("GET", "http://sms2.cdyne.com/sms.svc/SimpleSMSSendWithPostBack?PhoneNumber=7575449510&Message=Simple Test Message&LicenseKey=YOUR LICENSE KEY&StatusPostBackURL=http://www.cdyne.com/postbacksms.aspx", False)
4 Call oXMLHttp.setRequestHeader("Content-Type", "text/xml")
5 Call oXMLHttp.send
6 MsgBox oXMLHTTP.responseText

Ruby

1 require 'net/http'
2 require 'URI' 
3 puts URI.methods 
4 url = URI.parse('http://sms2.cdyne.com/sms.svc/SimpleSMSSendWithPostBack?PhoneNumber=7575449510&Message=HelloRubyWorld&LicenseKey= YOUR LICENSE KEY &StatusPostBackURL=http://www.cdyne.com/postbacksms.asmx')
5 res = Net::HTTP.get_response(url) 
6 data = res.body 
7 puts data
8 gets data

JAVA

 1 import java.io.ByteArrayOutputStream;
 2 import java.io.InputStream;
 3 import java.net.MalformedURLException;
 4 import java.net.URL; 
 5 import java.util.Properties;
 6 import javax.xml.transform.OutputKeys;
 7 import javax.xml.transform.Source;
 8 import javax.xml.transform.Transformer;
 9 import javax.xml.transform.TransformerFactory;
10 import javax.xml.transform.stream.StreamResult;
11 import javax.xml.transform.stream.StreamSource;
12 
13 public final class SimpleSMSSendWithPostBack{     
14 	public static void main(String[] args) { 	
15 
16            try{		
17             URL url = new URL("http://sms2.cdyne.com/sms.svc/SimpleSMSsendWithPostBack?"
18                                + "PhoneNumber=15551234567"
19                                + "&Message=JAVA+Test"
20                                + "&StatusPostBackURL=http://www.yourpostbackurl.com"
21                                + "&LicenseKey=YOUR LICENSE KEY");		
22     try{			
23     InputStream in = url.openStream(); 
24     StreamSource source = new StreamSource(in); 			
25     printResult(source);	
26 }catch(java.io.IOException e){			
27     e.printStackTrace();		
28 }		
29 }catch (MalformedURLException e){		
30     e.printStackTrace();	
31             }     
32     }     
33     private static void printResult(Source source) {        
34             try {            
35             ByteArrayOutputStream bos = new ByteArrayOutputStream();
36             StreamResult sr = new StreamResult(bos);
37             Transformer trans = TransformerFactory.newInstance().newTransformer();
38             Properties oprops = new Properties();
39             oprops.put(OutputKeys.OMIT_XML_DECLARATION, "yes");
40             trans.setOutputProperties(oprops);
41             trans.transform(source, sr);            
42             System.out.println("**** Response ******");            
43             System.out.println(bos.toString());   
44 
45             bos.close();
46             System.out.println();        
47     } catch (Exception e) {            
48             }      
49     }
50 }

Python

 1 import socket, httplib, urllib, urllib2
 2 import xml.etree.ElementTree as etree
 3 import json
 4 import time
 5 
 6 
 7 class session:
 8     def __init__(self, license_key):
 9         self.__license_key = license_key
10         self.__sms_action_url = "http://sms2.cdyne.com/sms.svc"
11         self.__max_retries = 1
12 
13 
14     def __xml_to_dictionary(self, xml):
15         boolean_keys = ["Queued", "SMSIncomingMessages", "Sent", "Cancelled"]
16         if type(xml) != etree.Element:
17             root = etree.XML(xml)
18         else:
19             root = xml
20         dictionary = {}
21         if root is not None:
22             for element in root.getchildren():
23                 element_name = element.tag.split("}")[1]
24                 element_value = element.text
25                 if element_name in boolean_keys:
26                     if element_value == "true":
27                         element_value = True
28                     else:
29                         element_value = False
30                 dictionary[element_name] = element_value
31         return dictionary
32 
33 
34     def __get_request(self, request):
35         """
36         Return contents of a given request
37         """
38         for i in range(0, self.__max_retries):
39             try:
40                 return urllib2.urlopen(request).read()
41             except urllib2.URLError:
42                 time.sleep(3)
43             except httplib.BadStatusLine or httplib.InvalidURL:
44                 time.sleep(3)
45             except socket.error or socket.timeout:
46                 time.sleep(3)
47             except:
48                 import traceback
49                 traceback.print_exc()
50         raise NameError("Failed to grab URL: %s", request)
51 
52 
53     def __send_request(self, data, function):
54         request_url = self.__sms_action_url + "/%s" % function
55         request_url += "?%s" % urllib.urlencode(data)
56         response = self.__get_request(request_url)
57         return self.__xml_to_dictionary(response)
58      
59 
60     # SMS Sending Functions
61     def simple_sms_send_with_postback(self, phone_number, message, postback_url):
62         data = {"PhoneNumber": phone_number,
63                 "LicenseKey": self.__license_key,
64                 "Message": message,
65                 "StatusPostBackURL": postback_url}
66         return self.__send_request(data, "SimpleSMSSendWithPostback")
67 
68 
69 
70 license_key = "YOUR LICENSE KEY" 
71 sms = session(license_key)
72 
73 
74 # Send a message
75 phone_number = "TO PHONE NUMBER"
76 message = "This is a test message"
77 postback_url = "POSTBACK URL"
78 sms.simple_sms_send_with_postback(phone_number, message, postback_url)

Perl

http://search.cpan.org/~revmischa/Net-SMS-CDYNE-0.04/lib/Net/SMS/CDYNE.pm