SimpleSMSSend

From CDYNE Wiki
Jump to navigation Jump to search

Send single, immediate text messages from your website or application with the SimpleSMSSend method. SMS Notify! uses DIDs or short codes assigned to your account license key to send MTtext messages and receive MO text messages.

SimpleSMSSend 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!

HTTP Method

HTTP Method: GET (REST)

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

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

SimpleSMSSend 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, <br>
	"ReferenceID":"String content", 
	"SMSError":0, 
	"SMSIncomingMessages":null
	"Sent":true, 
	"SentDateTime":"\/Date(928164000000-0400)\/" 
}

SimpleSMSSend Code Examples

Using as a Service Reference(.NET Framework 3.5+)

Add this service reference to your project: http://sms2.cdyne.com/sms.svc?wsdl

CSharp

1 IsmsClient client = new IsmsClient("sms2wsHttpBinding");
2 SMSResponse resp = client.SimpleSMSsend("17575449510", "Test Simple Message", new Guid("YOUR LICENSE KEY"));  //Single line message request.
3 //SMSResponse resp = client.SimpleSMSsend("17575449510", "SMS Simple Test" + "\n" + "Multi Line Message", new Guid("YOUR LICENSE KEY"));  Multi-line message request.
4 Console.WriteLine(resp.MessageID + " " + resp.SMSError.ToString());
5 Console.ReadLine();
6 client.Close();

VB.NET

Add this service reference to your project: http://sms2.cdyne.com/sms.svc?wsdl

 1 Imports SimpleSMS.WSDL
 2 Module Module1
 3  Sub Main()
 4     Dim client As WSDL.IsmsClient = New WSDL.IsmsClient("sms2wsHttpBinding")
 5     Dim resp As SimpleSMS.WSDL.SMSResponse = client.SimpleSMSsend("17575449510", "Simple SMS", New Guid("YOUR LICENSE KEY"))  'Single-line message request.
 6     'Dim resp As SimpleSMS.WSDL.SMSResponse = client.SimpleSMSsend("17575449510", "Simple" & Environment.NewLine & "SMS", New Guid("YOUR LICENSE KEY")) Multi-line message request.
 7     Console.WriteLine(Convert.ToString(resp.MessageID) & " " & "SMS Error:" & " " & Convert.ToString(resp.SMSError))
 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' => '7891234567',
 7 	'LicenseKey' => '(your license key here)',
 8 	'Message' => 'test'
 9 );
10 
11 // Send the text message
12 $result = $client->SimpleSMSsend($param);
13 
14 // View the response from CDYNE
15 print_r($result);

PHP with cURL

The following example was built using PHP 5.3.2 using cURL

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

VBScript

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

Ruby

Example 1

 1 require 'net/http'
 2 require 'URI'
 3 
 4 puts URI.methods
 5 
 6 url = URI.parse('http://sms2.cdyne.com/sms.svc/SimpleSMSsend?PhoneNumber=YourPhoneNumber&Message=HelloRubyWorld&LicenseKey=YourLicenseKey')
 7 
 8 res = Net::HTTP.get_response(url)
 9 
10 data = res.body
11 
12 puts data

Example 2

 1 require 'net/http'
 2 require 'uri'
 3 
 4 uri = URI("http://sms2.cdyne.com/sms.svc/SimpleSMSsend")
 5 
 6 params = {
 7                 :PhoneNumber => 'YourPhoneNumber', 
 8                 :Message => 'Hello From SMSNotify!', 
 9                 :LicenseKey => 'YourLicenseKey' 
10 }
11 
12 uri.query = URI.encode_www_form(params)
13 
14 res = Net::HTTP.get_response(uri)
15 puts res.body if res.is_a?(Net::HTTPSuccess)

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 SimpleSMSSend{     
14      public static void main(String[] args) { 
15          try{ 
16                URL url = new URL("http://sms2.cdyne.com/sms.svc/SimpleSMSsend?"
17                                   + "PhoneNumber=15551234567"
18                                   + "&Message=JAVA+Test"
19                                   + "&LicenseKey=YOUR LICENSE KEY");
20           try{			
21     InputStream in = url.openStream(); 
22     StreamSource source = new StreamSource(in); 			
23     printResult(source);	
24 }catch(java.io.IOException e){			
25     e.printStackTrace();		
26 }		
27 }catch (MalformedURLException e){		
28     e.printStackTrace();	
29             }     
30     }     
31     private static void printResult(Source source) {        
32             try {            
33             ByteArrayOutputStream bos = new ByteArrayOutputStream();
34             StreamResult sr = new StreamResult(bos);
35             Transformer trans = TransformerFactory.newInstance().newTransformer();
36             Properties oprops = new Properties();
37             oprops.put(OutputKeys.OMIT_XML_DECLARATION, "yes");
38             trans.setOutputProperties(oprops);
39             trans.transform(source, sr);            
40             System.out.println("**** Response ******");            
41             System.out.println(bos.toString());   
42 
43             bos.close();
44             System.out.println();        
45     } catch (Exception e) {            
46             }             
47     }
48 }

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     def simple_sms_send(self, phone_number, message):
61         data = {"PhoneNumber": phone_number,
62                 "LicenseKey": self.__license_key,
63                 "Message": message}
64         return self.__send_request(data, "SimpleSMSSend")
65 
66 
67 license_key = "YOUR LICENSE KEY"
68 sms = session(license_key)
69 
70 # Send a message
71 phone_number = "THE TO PHONE NUMBER"
72 message = "This is a test message from CDYNE"
73 sms.simple_sms_send(phone_number, message)

Perl

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