SimpleSMSSendWithPostback

From CDYNE Wiki
Jump to: navigation, 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.

Contents

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#

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

VB.NET

Imports SimpleSMSSendWithPostBack.WSDL
Module Module1
Sub Main()
Dim client As WSDL.IsmsClient = New WSDL.IsmsClient("sms2wsHttpBinding")
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.
'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.
Console.WriteLine(resp.MessageID)
Console.ReadLine()
client.Close()
End Sub
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.

 
 
// Create a new soap client based on the SMS Notify! WCF service
$client = new SoapClient('http://sms2.cdyne.com/sms.svc?wsdl');
 
// Specify required info to send a text message
$param = array(
	'PhoneNumber' => '5555555555',
	'LicenseKey' => '(LicensKey)',
	'Message' => 'test',
	'StatusPostBackURL' => '(PostBackURL)'
);
 
// Send the text message
$result = $client->SimpleSMSsendWithPostback($param);
 
// View the response from CDYNE
print_r($result);
 
 

PHP with cURL

The following example was built using PHP 5.3.2 with cURL

 
 
$url='http://sms2.cdyne.com/sms.svc/SimpleSMSsendWithPostback?PhoneNumber=(To Phone Number)&Message=(Message)&LicenseKey=(License Key)&StatusPostBackURL=(Your Postback Url)';
 
$cURL = curl_init();
 
curl_setopt($cURL,CURLOPT_URL,$url);
curl_setopt($cURL,CURLOPT_HTTPGET,true);
 
curl_setopt($cURL, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Accept: application/json'));
 
$result = curl_exec($cURL);
 
curl_close($cURL);
 
print_r($result);
 
 

VBScript

Set oXMLHTTP = CreateObject("Microsoft.XMLHTTP")
Set oDoc = CreateObject("MSXML2.DOMDocument")
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)
Call oXMLHttp.setRequestHeader("Content-Type", "text/xml")
Call oXMLHttp.send
MsgBox oXMLHTTP.responseText

Ruby

require 'net/http'
require 'URI'
puts URI.methods
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')
res = Net::HTTP.get_response(url)
data = res.body
puts data
gets data

JAVA

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Properties;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
 
public final class SimpleSMSSendWithPostBack{
public static void main(String[] args) {
 
try{
URL url = new URL("http://sms2.cdyne.com/sms.svc/SimpleSMSsendWithPostBack?"
+ "PhoneNumber=15551234567"
+ "&Message=JAVA+Test"
+ "&StatusPostBackURL=http://www.yourpostbackurl.com"
+ "&LicenseKey=YOUR LICENSE KEY");
try{
InputStream in = url.openStream();
StreamSource source = new StreamSource(in);
printResult(source);
}catch(java.io.IOException e){
e.printStackTrace();
}
}catch (MalformedURLException e){
e.printStackTrace();
}
}
private static void printResult(Source source) {
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
StreamResult sr = new StreamResult(bos);
Transformer trans = TransformerFactory.newInstance().newTransformer();
Properties oprops = new Properties();
oprops.put(OutputKeys.OMIT_XML_DECLARATION, "yes");
trans.setOutputProperties(oprops);
trans.transform(source, sr);
System.out.println("**** Response ******");
System.out.println(bos.toString());
 
bos.close();
System.out.println();
} catch (Exception e) {
}
}
}

Python

import socket, httplib, urllib, urllib2
import xml.etree.ElementTree as etree
import json
import time
 
 
class session:
def __init__(self, license_key):
self.__license_key = license_key
self.__sms_action_url = "http://sms2.cdyne.com/sms.svc"
self.__max_retries = 1
 
 
def __xml_to_dictionary(self, xml):
boolean_keys = ["Queued", "SMSIncomingMessages", "Sent", "Cancelled"]
if type(xml) != etree.Element:
root = etree.XML(xml)
else:
root = xml
dictionary = {}
if root is not None:
for element in root.getchildren():
element_name = element.tag.split("}")[1]
element_value = element.text
if element_name in boolean_keys:
if element_value == "true":
element_value = True
else:
element_value = False
dictionary[element_name] = element_value
return dictionary
 
 
def __get_request(self, request):
"""
Return contents of a given request
"""

for i in range(0, self.__max_retries):
try:
return urllib2.urlopen(request).read()
except urllib2.URLError:
time.sleep(3)
except httplib.BadStatusLine or httplib.InvalidURL:
time.sleep(3)
except socket.error or socket.timeout:
time.sleep(3)
except:
import traceback
traceback.print_exc()
raise NameError("Failed to grab URL: %s", request)
 
 
def __send_request(self, data, function):
request_url = self.__sms_action_url + "/%s" % function
request_url += "?%s" % urllib.urlencode(data)
response = self.__get_request(request_url)
return self.__xml_to_dictionary(response)
 
 
# SMS Sending Functions
def simple_sms_send_with_postback(self, phone_number, message, postback_url):
data = {"PhoneNumber": phone_number,
"LicenseKey": self.__license_key,
"Message": message,
"StatusPostBackURL": postback_url}
return self.__send_request(data, "SimpleSMSSendWithPostback")
 
 
 
license_key = "YOUR LICENSE KEY"
sms = session(license_key)
 
 
# Send a message
phone_number = "TO PHONE NUMBER"
message = "This is a test message"
postback_url = "POSTBACK URL"
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

Personal tools
Namespaces

Variants
Actions
Navigation
Tools

Trial Key