<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Text Marketer - Email SMS, Bulk SMS Gateway, SMS Marketing Blog &#187; RESTful</title>
	<atom:link href="http://www.textmarketer.co.uk/blog/tag/restful/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.textmarketer.co.uk/blog</link>
	<description>SMS Gateway</description>
	<lastBuildDate>Tue, 07 Feb 2012 09:50:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>RESTful Web Services SMS Gateway API Overview</title>
		<link>http://www.textmarketer.co.uk/blog/2010/03/sms-gateway/restful-web-services-sms-api-overview/</link>
		<comments>http://www.textmarketer.co.uk/blog/2010/03/sms-gateway/restful-web-services-sms-api-overview/#comments</comments>
		<pubDate>Mon, 22 Mar 2010 10:57:26 +0000</pubDate>
		<dc:creator>Jay</dc:creator>
				<category><![CDATA[All SMS Gateway Documentation]]></category>
		<category><![CDATA[Business SMS]]></category>
		<category><![CDATA[Documentation]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[Web to SMS]]></category>
		<category><![CDATA[gateway]]></category>
		<category><![CDATA[integrate]]></category>
		<category><![CDATA[RESTful]]></category>
		<category><![CDATA[sms]]></category>
		<category><![CDATA[sms api]]></category>
		<category><![CDATA[web service]]></category>

		<guid isPermaLink="false">http://87.106.109.73/blog/?p=1107</guid>
		<description><![CDATA[This blog post has been superseded with our website documentation In addition to our simple HTTP SMS Gateway API, explained here, we also provide a &#8216;RESTful&#8217; SMS API to give you access to information about your SMS marketing account (don&#8217;t have one? Create a free account). If you are familiar with REST APIs, &#8230; <a href="http://www.textmarketer.co.uk/blog/2010/03/sms-gateway/restful-web-services-sms-api-overview/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.textmarketer.co.uk/developers/restful-api.htm">This blog post has been superseded with our website documentation</a></p>
<p>In addition to our simple HTTP <a title="SMS Gateway API" href="/blog/2009/05/sms-gateway/text-marketer-apigateway-spec/">SMS Gateway API</a>, explained <a title="SMS Gateway API" href="/blog/2009/05/sms-gateway/text-marketer-apigateway-spec/">here</a>, we also provide a &#8216;RESTful&#8217; SMS API to give you access to information about your <a title="Get an SMS account" href="http://www.textmarketer.co.uk/signUpGoogle/" target="_self">SMS marketing account</a> (don&#8217;t have one? Create a <a title="Free SMS account" href="http://www.textmarketer.co.uk/signUpGoogle/">free account</a>).</p>
<p>If you are familiar with REST APIs, you may wish to jump to our <a title="REST SMS API specification" href="/blog/2010/03/business-sms/rest-sms-api-specification-document/" target="_self">REST API specification document</a>.</p>
<p><strong>WHAT&#8217;S A &#8216;RESTful&#8217; SMS API?</strong></p>
<p>REST is a term used to describe a type of two-way communication via the Internet. It is an architectural style, not a standard, but makes use of well-known web technologies such as <a title="HTTP Protocol" href="http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol" target="_blank">HTTP</a>, <a title="XML Language" href="http://en.wikipedia.org/wiki/Xml" target="_blank">XML</a> and <a title="MIME types" href="http://en.wikipedia.org/wiki/Mime_types" target="_blank">MIME types</a>. For more information about REST APIs, read <a title="REST Web Services" href="http://www.xfront.com/REST-Web-Services.html" target="_blank">this great description of REST</a>.</p>
<p>At its most simple, our <a title="RESTful Web Services" href="http://http://www.xfront.com/REST-Web-Services.html" target="_blank">RESTful</a> SMS API allows you to request (&#8216;GET&#8217;) information. For example, from this &#8216;resource&#8217;</p>
<p><a title="REST SMS API resource example" href="http://www.textmarketer.biz/services/rest/credits" target="_blank"><em></em></a><em><a title="Credits resource" href="http://www.textmarketer.biz/services/rest/credits" target="_blank">http://www.textmarketer.biz/services/rest/credits</a> </em></p>
<p>you can access the number of credits available in your account. The response is an XML document that looks like this:</p>
<pre>&lt;<span class="start-tag">response</span><span class="attribute-name"> processed_date</span>=<span class="attribute-value">"2010-03-19T09:37:26+00:00"</span>&gt;
&lt;<span class="start-tag">credits</span>&gt;37&lt;/<span class="end-tag">credits</span>&gt;
&lt;/<span class="end-tag">response</span>&gt;</pre>
<p>The SMS REST API is that simple!</p>
<p><strong>WHAT ABOUT SECURITY?</strong></p>
<p>Although it&#8217;s not apparent from the example above, the interface does require authentication using your SMS API account username/password. We provide two ways of passing this information to the server.</p>
<p>The first is via <a title="HTTP Basic Auth" href="http://en.wikipedia.org/wiki/Basic_access_authentication" target="_blank">HTTP Basic Authentication</a>, which is demonstrated by the login box that appears if you click on the resource link above. HTTP Basic authentication can of course be handled within your code. However if you prefer a simpler method, you can pass the parameters via the URL as GET arguments, e.g.</p>
<p><em><a>http://www.textmarketer.biz/services/rest/credits?username=myusername&amp;password=mypassword</a></em></p>
<p>It is also recommended that you use encrypted communication with the REST Web Services by accessing resources via the HTTPS protocol (<em><a>https://&#8230; etc.)</a></em>.</p>
<p><strong>HOW DOES THE RESTful API HANDLE ERRORS?</strong></p>
<p>An advantage of using a RESTful API is that the underlying technologies already do a lot of the work for us. All responses via the HTTP protocol include headers that give us some information about the response. The headers in the above example would look like this:</p>
<pre>Date: Fri, 19 Mar 2010 10:11:40 GMT
Server: Apache/2.2.3 (Red Hat)
X-Powered-By: PHP/5.2.11 ZendServer/4.0
Content-Length: 272
Connection: close
Content-Type: application/xml

200 OK</pre>
<p>The MIME type (Content-Type) is set to application/xml which identifies the type of content in the response. It is followed by the response status code &#8217;200&#8242; and the status message &#8216;OK&#8217;. This is a standard response to a successful request.</p>
<p>If we had tried to access a resource which didn&#8217;t exist, e.g.</p>
<p><a title="Bad request" href="http://www.textmarketer.biz/services/rest/anotherResource" target="_blank">http://www.textmarketer.biz/services/rest/anotherResource</a></p>
<p>we would get the following response headers:</p>
<pre>Date: Fri, 19 Mar 2010 10:18:23 GMT
Server: Apache/2.2.3 (Red Hat)
X-Powered-By: PHP/5.2.11 ZendServer/4.0
Content-Length: 549
Connection: close
Content-Type: application/xml

404 Not Found :  (ERR101)</pre>
<p>The status code is 404, which is the HTTP protocol&#8217;s standard code for &#8216;resource not found&#8217;. The status message also contains some additional debugging information (ERR91) which you can ignore.</p>
<p>In addition to the status code, the response body contains XML detailing the error. In this example it might look like this:</p>
<pre>&lt;<span class="start-tag">response</span><span class="attribute-name"> processed_date</span>=<span class="attribute-value">"2010-03-24T14:45:54+00:00"</span>&gt;
&lt;<span class="start-tag">errors</span>&gt;
	&lt;<span class="start-tag">error</span><span class="attribute-name"> code</span>=<span class="attribute-value">"404"</span>&gt;Not Found :  (ERR101)&lt;/<span class="end-tag">error</span>&gt;
&lt;/<span class="end-tag">errors</span>&gt;
&lt;/<span class="end-tag">response</span>&gt;</pre>
<p>Thus, you can check the header status code for an error code, as well  as the response body.</p>
<p><strong>WHAT RESOURCES CAN I ACCESS THROUGH THE REST SMS API?</strong></p>
<p>At the moment, the resource URIs available to you are:</p>
<ul>
<li><a title="Credits resource" href="/blog/2010/03/business-sms/rest-sms-api-specification-document/#credits_resource"><em>http://www.textmarketer.biz/services/rest/credits</em></a> &#8211; to get the credits available on your account / transfer credits between accounts</li>
<li><a title="deliveryReports resource" href="/blog/2010/03/business-sms/rest-sms-api-specification-document/#deliveryReports_resource"><em>http://www.textmarketer.biz/services/rest/deliveryReports</em></a> &#8211; to list your delivery reports</li>
<li><a title="deliveryReport resource" href="/blog/2010/03/business-sms/rest-sms-api-specification-document/#deliveryReport_resource"><em>http://www.textmarketer.biz/services/rest/deliveryReport/</em>a_report_name</a> &#8211; to access the details of a specific report</li>
<li><a title="sms resource" href="/blog/2010/03/business-sms/rest-sms-api-specification-document/#sms_resource"><em>http://www.textmarketer.biz/services/rest/sms</em></a> &#8211; to send an SMS</li>
<li><em><a title="keywords resource" href="/blog/2010/03/business-sms/rest-sms-api-specification-document/#keywords_resource">http://www.textmarketer.biz/services/rest/keywords</a></em> &#8211; to get the availability of a given keyword (see <a href="http://www.textmarketer.co.uk/shortcode_sms.htm" target="_blank">Short Code SMS Service</a>)</li>
</ul>
<p>More will be added in the future.</p>
<p>Here are 2 walk-through examples for using the REST SMS API.</p>
<p><strong>EXAMPLE REQUEST 1 &#8211; GET CREDITS</strong></p>
<p>Make an HTTP GET request like this:</p>
<p><em></em><em><a>http://www.textmarketer.biz/services/rest/credits?username=myAPIusername&amp;password=myAPIpassword</a></em></p>
<p>Obviously, replace &#8216;myAPIusername&#8217; and &#8216;myAPIpassword&#8217; in the URL with the ones you received when you <a title="Sign up for free SMS account" href="http://www.textmarketer.co.uk/signUpGoogle/" target="_blank">signed up</a>.</p>
<p>When you send this request using your favorite programming language, you should receive the following HTTP <em>headers</em> in response:</p>
<pre>Date: Wed, 24 Mar 2010 15:17:28 GMT
Server: Apache/2.2.3 (Red Hat)
X-Powered-By: PHP/5.2.11 ZendServer/4.0
Content-Length: 272
Connection: close
Content-Type: application/xml

200 OK</pre>
<p>Using your programming language, you can easily extract the status code (200 in this case), which indicates success (200) or failure (not 200). The status code of 200 here shows us the request was successful, i.e. the response contains the number of credits in your account.</p>
<p>Thus the HTTP response <em>body</em> that you receive will contain XML similar to this:</p>
<pre>&lt;<span class="start-tag">response</span><span class="attribute-name"> processed_date</span>=<span class="attribute-value">"2010-03-24T15:17:28+00:00"</span>&gt;
&lt;<span class="start-tag">credits</span>&gt;10&lt;/<span class="end-tag">credits</span>&gt;
&lt;/<span class="end-tag">response</span>&gt;</pre>
<p>In your programming language you can parse the XML to extract the value of the credits, in this case 10.</p>
<p>But if, for example, you use an incorrect password, the response headers will look like this:</p>
<pre>Date: Wed, 24 Mar 2010 15:30:10 GMT
Server: Apache/2.2.3 (Red Hat)
X-Powered-By: PHP/5.2.11 ZendServer/4.0
Content-Length: 377
Connection: close
Content-Type: application/xml

403 Forbidden : Your username/password combination did not match an account. (ERR145)</pre>
<p>The 403 status code shows that an error occurred (all codes except 200 indicate an error). And the XML response body will also contain:</p>
<pre>&lt;<span class="start-tag">response</span><span class="attribute-name"> processed_date</span>=<span class="attribute-value">"2010-03-24T15:29:22+00:00"</span>&gt;
&lt;<span class="start-tag">errors</span>&gt;
	&lt;<span class="start-tag">error</span><span class="attribute-name"> code</span>=<span class="attribute-value">"403"</span>&gt;Forbidden : Your username/password combination did not match an account. (ERR145)&lt;/<span class="end-tag">error</span>&gt;
&lt;/<span class="end-tag">errors</span>&gt;
&lt;/<span class="end-tag">response</span>&gt;</pre>
<p><strong>EXAMPLE REQUEST 2 &#8211; SEND SMS</strong></p>
<p>In your programming language, create an HTTP <em>POST</em> request to this URL:</p>
<p><em>http://www.textmarketer.biz/services/rest/sms</em></p>
<p>Since this is a POST request, you cannot pass the username and password via the URL, so you need to use HTTP Digest Authentication, or simply include these parameters along with the other POST parameters you&#8217;ll need:</p>
<ul>
<li>message=&#8217;my message&#8217;</li>
<li>originator=&#8217;me&#8217;</li>
<li>mobile_number=&#8217;447777777777&#8242;</li>
<li>username=&#8217;myAPIusername&#8217; (replace with your own &#8211; or skip this parameter and use HTTP Digest Authentication)</li>
<li>password=&#8217;myAPIpassword&#8217; (replace with your own &#8211; or skip this parameter and use HTTP Digest Authentication)</li>
</ul>
<p>POSTing an HTTP request using the above as POST parameters would send an SMS message of &#8216;my message&#8217; to the mobile number 447777777777 from &#8220;me&#8221;.</p>
<p>NOTE: It will not work to pass these parameters as GET arguments (e.g. by appending them to the URL); this is the principle of a REST API.</p>
<p>Your HTTP POST request should return something similar to the following response headers:</p>
<pre>Date: Wed, 24 Mar 2010 15:17:28 GMT
Server: Apache/2.2.3 (Red Hat)
X-Powered-By: PHP/5.2.11 ZendServer/4.0
Content-Length: 272
Connection: close
Content-Type: application/xml

200 OK</pre>
<p>&#8230;the &#8217;200&#8242; status code showing that your request was successful. The HTTP response body will consist of XML containing the ID of the SMS sent as well as the number of credits used to send it:</p>
<pre>&lt;response processed_date="2010-03-23T10:31:39+00:00"&gt;
	&lt;message_id&gt;4172870907&lt;/message_id&gt;
	&lt;credits_used&gt;1&lt;/credits_used&gt;
&lt;/response&gt;</pre>
<p>If, however, there was a problem with your request parameters, for example you set mobile_number to &#8216;garbage&#8217;, you would get similar response headers to this:</p>
<pre>Date: Wed, 24 Mar 2010 15:30:10 GMT
Server: Apache/2.2.3 (Red Hat)
X-Powered-By: PHP/5.2.11 ZendServer/4.0
Content-Length: 377
Connection: close
Content-Type: application/xml

404 Bad request</pre>
<p>And the response body would contain XML detailing the precise problems with your request, like this:</p>
<pre><span><span style="color: #cc0000;"><span style="color: #000000;">&lt;response processed_date="2010-03-24T14:37:41+00:00"&gt;
&lt;errors&gt;
	&lt;error code="10"&gt;invalid number or not an integer&lt;/error&gt;
	&lt;error code="9"&gt;invalid number or too short&lt;/error&gt;
&lt;/errors&gt;
&lt;/response&gt;
</span></span></span></pre>
<p>See the <a title="sms resource" href="http://www.textmarketer.co.uk/blog/2010/03/business-sms/rest-sms-api-specification-document/#sms_resource">specification of the sms resource</a> for more details of the possible error codes.</p>
<p><strong>TESTING/SANDBOX</strong></p>
<p>A <a title="Sandbox API" href="/blog/2010/03/business-sms/rest-sms-api-specification-document/#sandbox">sandbox service</a> is available for testing your code without changing your account or using any credits.</p>
<p><strong>MORE INFORMATION</strong></p>
<p>For detailed information about our RESTful SMS API, please see our <a title="REST SMS API specification" href="/blog/2010/03/business-sms/rest-sms-api-specification-document/" target="_self">REST  API specification document</a>.</p>
<p>For reference, a list of the DTDs that correspond to the  resources available can be <a title="Web Services DTDs" href="http://www.textmarketer.biz/services/rest/DTD/" target="_blank">found here</a>.</p>
<img src="http://www.textmarketer.co.uk/wordpress/?ak_action=api_record_view&id=1107&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.textmarketer.co.uk/blog/2010/03/sms-gateway/restful-web-services-sms-api-overview/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>REST SMS Gateway API &#8211; Specification Document</title>
		<link>http://www.textmarketer.co.uk/blog/2010/03/business-sms/rest-sms-api-specification-document/</link>
		<comments>http://www.textmarketer.co.uk/blog/2010/03/business-sms/rest-sms-api-specification-document/#comments</comments>
		<pubDate>Mon, 22 Mar 2010 10:57:16 +0000</pubDate>
		<dc:creator>Jay</dc:creator>
				<category><![CDATA[Business SMS]]></category>
		<category><![CDATA[Documentation]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[All SMS Gateway Documentation]]></category>
		<category><![CDATA[RESTful]]></category>
		<category><![CDATA[sms api]]></category>
		<category><![CDATA[specification]]></category>

		<guid isPermaLink="false">http://87.106.109.73/blog/?p=1134</guid>
		<description><![CDATA[This blog post has been superseded with our website documentation For an overview of what REST and our RESTful SMS API is all about you may like to read our RESTful SMS API Overview. If you prefer you can use the simple SMS gateway, rather than our RESTful implementation. To get straight into the details, &#8230; <a href="http://www.textmarketer.co.uk/blog/2010/03/business-sms/rest-sms-api-specification-document/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.textmarketer.co.uk/developers/restful-api.htm">This blog post has been superseded with our website documentation</a></p>
<p>For an overview of what REST and our RESTful SMS API is all about you may like to read our <a title="RESTful SMS API Overview" href="/blog/2010/03/sms-gateway/restful-web-services-sms-api-overview/" target="_self">RESTful SMS API Overview</a>.</p>
<p>If you prefer you can use the <a title="simple sms gateway" href="http://www.textmarketer.co.uk/blog/2009/05/sms-gateway/text-marketer-apigateway-spec/">simple SMS gateway</a>, rather than our RESTful implementation.</p>
<p><strong>To get straight into the details, jump to:</strong></p>
<p><a title="Quick Start SMS API" href="#quickstart" target="_self">Quick Start</a><br />
<a title="Error Codes" href="#error_codes">Error codes</a></p>
<p><a title="Sandbox for testing" href="#sandbox">Sandbox</a></p>
<p>You can preform the following actions using the REST web service:</p>
<ul>
<li>send an SMS (<a title="sms post" href="#sms_resource">sms post</a>)</li>
<li>get the number of credits available (<a title="credits get" href="/blog/2010/06/sms-gateway/rest-sms-gateway-api-credits-resource/#get">credits get</a>)</li>
<li>transfer credits from one account to another (<a title="credits post" href="/blog/2010/06/sms-gateway/rest-sms-gateway-api-credits-resource/#post">credits post</a>)</li>
<li>get a list of delivery reports (<a title="deliveryReports get" href="/blog/2010/06/business-sms/rest-sms-gateway-api-deliveryreports-resource/#get">deliveryReports get</a>)</li>
<li>get the contents of a specific delivery report (<a title="deliveryReport get" href="/blog/2010/06/sms-gateway/rest-sms-gateway-api-deliveryreport-resource/#get">deliveryReport get</a>)</li>
<li>check availability of a given keyword on our ShortCode number (<a title="keywords get" href="/blog/2010/06/sms-gateway/rest-sms-gateway-api-keywords-resource/#get">keywords get</a>)</li>
<li>check the names and IDs of your send groups (<a title="Groups GET" href="/blog/2011/04/sms-gateway/rest-sms-gateway-api-group-resource/">groups get</a>)</li>
<li>add number(s) to a send group (<a title="group post" href="/blog/2011/04/sms-gateway/rest-sms-gateway-api-group-resource/#post">group post</a>)</li>
</ul>
<h2><a title="The Resource Identifier" href="#resource_identifier">Specification of the resources</a></h2>
<ol>
<li><a href="#credits_resource">credits</a></li>
<li><a title="deliveryReports resource" href="#deliveryReports_resource">deliveryReports</a></li>
<li><a title="deliveryReport resource" href="#deliveryReport_resource">deliveryReport</a></li>
<li><a title="sms resource" href="#sms_resource">sms</a></li>
<li><a title="keywords resource" href="#keywords_resource">keywords</a></li>
<li><a title="group resource" href="#group_resource">group</a></li>
<li><a title="groups resource" href="#groups_resource">groups</a></li>
</ol>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>QUICK START</strong><br />
Three things are essentially needed to use the REST SMS API:</p>
<ol>
<li>Ability to make a HTTP request
<ul>
<li>e.g. to https://www.textmarketer.biz/services/rest/credits</li>
</ul>
</li>
<li>Ability to read the HTTP response headers
<ul>
<li>e.g. &#8217;200 OK&#8217;</li>
</ul>
</li>
<li>Ability to parse the XML response
<ul>
<li>e.g. &lt;<span class="start-tag">credits</span>&gt;37&lt;/<span class="end-tag">credits</span>&gt;</li>
</ul>
</li>
</ol>
<p><strong>The Request URI </strong><strong>Explained</strong></p>
<p>You will make the HTTP request to a request URI such as:</p>
<pre>https://www.textmarketer.biz/services/rest/credits</pre>
<p>The base request URI is thus composed of :</p>
<p>&#8216;<em><strong>https://www.textmarketer.biz/services/rest/</strong></em><em>&#8216;</em> + a string that denotes the resource to be accessed, e.g. &#8216;<em>credits</em>&#8216;, &#8216;<em>deliveryReports</em>&#8216;, etc.</p>
<p>You can use http instead of https, but https is recommended.</p>
<p>Note that cAsE matters, i.e. &#8216;<em>deliveryReports</em>&#8216; will work, whereas &#8216;<em>deliveryreports</em>&#8216; (lower case &#8216;r&#8217;) will return an error.</p>
<p>You must obviously identify yourself during the request. If you know how to handle HTTP <a href="http://en.wikipedia.org/wiki/Digest_access_authentication" target="_blank">Digest Authentication</a>, that is the preferred method of authentication.</p>
<p>Otherwise you should attach the following to the end of the resource URI:</p>
<pre>?username=myAPIusername&amp;password=myAPIpassword</pre>
<p>Or, in the case of a POST request, such as for sending an SMS, include the username/password parameters in the POST parameters (e.g. see <a title="sms post" href="#sms_resource">sms post</a>).</p>
<p>In our example, the complete URI that results is:</p>
<pre>https://www.textmarketer.biz/services/rest/credits?username=myAPIusername&amp;password=myAPIpassword</pre>
<p>And this should return XML containing the number of credits available on your account.</p>
<p><strong>The HTTP Response Headers</strong></p>
<p>The only vital part of the response headers that you need is the status code. <em>200</em> means a successful request, all other codes returned will be errors.</p>
<p>If you get an error, the status message may give you some extra information about the error. For more details about the error codes and their meanings, see <a title="Error Codes" href="#error_codes" target="_self">Error Codes</a> below.</p>
<p><strong>The XML response</strong></p>
<p>The structure of the XML response is generally quite simple. The response to our <em>credits</em> request example would look like this:</p>
<pre id="line1">&lt;<span class="start-tag">response</span><span class="attribute-name"> processed_date</span>=<span class="attribute-value">"2010-03-19T14:08:40+00:00"</span>&gt;
&lt;<span class="start-tag">credits</span>&gt;37&lt;/<span class="end-tag">credits</span>&gt;
&lt;/<span class="end-tag">response</span>&gt;</pre>
<p>Your preferred programming language will have a method for parsing the XML response to obtain the value.</p>
<p><strong>Example PHP code</strong></p>
<pre>&lt;?php
/**
 * GET request on the 'credits' resource
 */
$url = 'http://www.textmarketer.biz/services/rest/credits';
$username = 'myAPIusername'; // CHANGE THIS!!!
$password = 'myAPIpassword'; // CHANGE THIS!!!
$url = "$url?username=$username&amp;password=$password";

// we're using the curl library to make the request
$curlHandle = curl_init();
curl_setopt($curlHandle, CURLOPT_URL, $url);
curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true);
$responseBody = curl_exec($curlHandle);
$responseInfo  = curl_getinfo($curlHandle);
curl_close($curlHandle);

// deal with the response
if ($responseInfo['http_code']==200)
{
	$xml_obj = simplexml_load_string($responseBody);
	$credits = (int) $xml_obj-&gt;credits;
	// do something with the result
	echo $credits;

} else {
	// handle the error
	var_dump($responseBody);
}

?&gt;</pre>
<p>See the <a title="REST SMS API Examples" href="http://www.textmarketer.co.uk/blog/2010/03/campaign-articles/dev/rest-sms-api-code-examples/" target="_self">REST API Code Examples</a> for some more example code that you can use.</p>
<p>That&#8217;s the end of the Quick Start. You know to send the request, check the status code is <em>200</em>, and then parse the XML according to its declared structure.</p>
<p style="color: white;">Error codes</p>
<p><strong>ERROR CODES</strong></p>
<p>The HTTP status codes returned by our REST SMS API follow normal HTTP conventions. An example of the HTTP response headers from a request to our REST API:</p>
<pre>Date: Wed, 24 Mar 2010 14:45:54 GMT
Server: Apache/2.2.3 (Red Hat)
X-Powered-By: PHP/5.2.11 ZendServer/4.0
Content-Length: 317
Connection: close
Content-Type: application/xml

404 Not Found :  (ERR101)</pre>
<p>You see the status code, 404 on the last line. Their meaning of the status codes in the context of our REST SMS API are as follows:</p>
<table border="0">
<tbody>
<tr>
<td><strong>Code</strong></td>
<td><strong>Meaning</strong></td>
</tr>
<tr>
<td>200</td>
<td>OK. We were able to successfully execute the requested operation.</td>
</tr>
<tr>
<td>400</td>
<td>Bad request. There was a problem with your request data, see the status message for details.</td>
</tr>
<tr>
<td>403</td>
<td>You do not have sufficient rights to access the specified resource.</td>
</tr>
<tr>
<td>404</td>
<td>The resource specified could not be found.</td>
</tr>
<tr>
<td>405</td>
<td>The specified method (get, post, put or delete) is not allowed for this resource.</td>
</tr>
<tr>
<td>500</td>
<td>An unexpected error occurred.</td>
</tr>
<tr>
<td>501</td>
<td>The method requested has not been implemented.</td>
</tr>
<tr>
<td>503</td>
<td>Service Unavailable. The Web Service is not currently available to serve your request.</td>
</tr>
</tbody>
</table>
<p>This list is not exhaustive, any code from the <a title="HTTP status  codes" href="http://en.wikipedia.org/wiki/List_of_HTTP_status_codes" target="_blank">complete list of HTTP status codes</a> may be returned.</p>
<p>IMPORTANT NOTE: Error 503 may be returned if you exceed a certain number of requests per minute. You will see an error message similar to: &#8220;Your 201 requests exceed the maximum allowed of 100 requests within 15 minute(s). Please try again later&#8221;. This to reduce load on our servers, in order to guarantee a good service to all our users.  <em>There is no restriction on SMS sends.</em></p>
<p>USEFUL NOTE: the HTTP status message may contain more specific information. If you encounter an unexpected error, the &#8216;(ERRnn)&#8217; found in the status message is useful in any reports you send us.</p>
<p>In addition to the status codes, an error will also produce an XML response containing details of the error. In this example the XML response might look like this:</p>
<pre>&lt;<span class="start-tag">response</span><span class="attribute-name"> processed_date</span>=<span class="attribute-value">"2010-03-24T14:45:54+00:00"</span>&gt;
&lt;<span class="start-tag">errors</span>&gt;
	&lt;<span class="start-tag">error</span><span class="attribute-name"> code</span>=<span class="attribute-value">"404"</span>&gt;Not Found :  (ERR101)&lt;/<span class="end-tag">error</span>&gt;
&lt;/<span class="end-tag">errors</span>&gt;
&lt;/<span class="end-tag">response</span>&gt;</pre>
<p>Some resources, such as <a title="sms resource" href="#sms_resource">http://www.textmarketer.biz/services/rest/sms</a>, have additional error codes specific to the resource. These are documented along with the description of the resource.</p>
<p style="color: white;">Resource Identifier</p>
<p><strong>THE RESOURCE IDENTIFIER</strong></p>
<p>The example of a resource identifier used previously was:</p>
<p><span style="font-family: Consolas, Monaco, 'Courier New', Courier, monospace; line-height: 18px; font-size: 12px; white-space: pre;">https://www.textmarketer.biz/services/rest/credits</span></p>
<p>All our REST SMS Web Service resource identifiers take the general form:</p>
<pre>PROTOCOL://RESOURCE_NAMESPACE/RESOURCE_NAME[/RESOURCE_ID]</pre>
<p>where</p>
<pre>PROTOCOL = http|https
RESOURCE_NAMESPACE = www.textmarketer.biz/services/rest
RESOURCE_NAME = credits|deliveryReports|deliveryReport|sms|keywords|etc</pre>
<pre>RESOURCE_ID = an_ID (optional) which specifies a particular resource element, e.g. a specific delivery report</pre>
<p>e.g.</p>
<pre>https://www.textmarketer.biz/services/rest/deliveryReport/GatewayAPI_09-02-10</pre>
<p>will access a delivery report named &#8216;<em>GatewayAPI_09-02-10</em>&#8216;.</p>
<p style="color: white;">Resources</p>
<p><strong>RESOURCES</strong></p>
<p>The currently implemented resources are:</p>
<ol>
<li><a href="#credits_resource">credits</a></li>
<li><a title="deliveryReports resource" href="#deliveryReports_resource">deliveryReports</a></li>
<li><a title="deliveryReport resource" href="#deliveryReport_resource">deliveryReport</a></li>
<li><a title="sms resource" href="#sms_resource">sms</a></li>
<li><a title="keywords resource" href="#keywords_resource">keywords</a></li>
<li><a title="group resource" href="#group_resource">group</a></li>
<li><a title="groups resource" href="#groups_resource">groups</a></li>
</ol>
<p><em><strong>1. credits</strong></em></p>
<pre>http://www.textmarketer.biz/services/rest/credits</pre>
<ul>
<li>GET method -<em> </em>get the number of credits currently available on your account</li>
<li><em><span style="font-style: normal;">POST method</span> </em>- transfer credits between accounts</li>
</ul>
<p>See the <a title="credits resource" href="/blog/2010/06/sms-gateway/rest-sms-gateway-api-credits-resource/" target="_self">full description</a> of this resource for details.</p>
<p><em><strong>2. deliveryReports</strong></em></p>
<pre>http://www.textmarketer.biz/services/rest/deliveryReports</pre>
<ul>
<li>GET method - Gets a list of available delivery report names</li>
</ul>
<p>See the <a title="deliveryReports resource" href="/blog/2010/06/business-sms/rest-sms-gateway-api-deliveryreports-resource/" target="_self">full description</a> of this resource for details.</p>
<p><em><strong>3. deliveryReport</strong></em></p>
<pre>http://www.textmarketer.biz/services/rest/deliveryReport/test-190310</pre>
<ul>
<li>GET method - Gets the contents of a delivery report &#8211; the delivery status of sent messages for a given day/campaign.</li>
</ul>
<p>See the <a title="deliveryReport resource" href="/blog/2010/06/sms-gateway/rest-sms-gateway-api-deliveryreport-resource/" target="_self">full description</a> of this resource for details.</p>
<p>NOTE: An individual delivery report that is accessed using this resource shows the current known status of all messages sent on a given day, or for a particular campaign. The REST API resource <em><a title="deliveryReports resource" href="#deliveryReports_resource" target="_self">deliveryReport</a><strong><a title="deliveryReports resource" href="#deliveryReports_resource" target="_self">s</a> </strong></em>(note the trailing s) gets a list of available delivery report names, including delivery reports for campaigns (see <a title="deliveryReports resource" href="#deliveryReports_resource" target="_self">above</a>).</p>
<p><em><strong>4. sms</strong></em></p>
<pre>http://www.textmarketer.biz/services/rest/sms</pre>
<ul>
<li><strong><em>POST method</em></strong> - Used to send an SMS message.</li>
</ul>
<p>See the <a title="sms resource" href="/blog/2010/06/sms-gateway/rest-sms-gateway-api-sms-resource/" target="_self">full description</a> of this resource for details.</p>
<p><em><strong>5. keywords </strong></em></p>
<pre>http://www.textmarketer.biz/services/rest/keywords/mykeyword</pre>
<ul>
<li><strong><em>GET method</em></strong><strong> </strong>- get the availability of a given keyword (see <a href="http://www.textmarketer.co.uk/shortcode_sms.htm" target="_blank">Short Code SMS Service</a>)</li>
</ul>
<p>See the <a title="keywords resource" href="/blog/2010/06/sms-gateway/rest-sms-gateway-api-keywords-resource/" target="_self">full description</a> of this resource for details.</p>
<p><em><strong>6. group</strong></em></p>
<pre>http://www.textmarketer.biz/services/rest/group</pre>
<ul>
<li><strong><em>POST method</em></strong><strong> </strong>- add number(s) to a send group</li>
</ul>
<p>See the <a title="group resource" href="/blog/2011/04/sms-gateway/rest-sms-gateway-api-group-resource/">full description</a> of this resource for details.</p>
<p><em><strong>7. groups</strong></em></p>
<pre>http://www.textmarketer.biz/services/rest/groups</pre>
<ul>
<li><strong><em>GET method</em></strong><strong> </strong>- list the available send groups</li>
</ul>
<p>See the <a href="http://www.textmarketer.co.uk/blog/2011/04/sms-gateway/rest-sms-gateway-api-group-resource/">full description</a> of this resource for details.</p>
<p style="color: white;">Sandbox</p>
<p><strong>TESTING/SANDBOX</strong></p>
<p>A sandbox service is available to allow you to test your integration code without using any credits or executing any function that would modify the data in your account. The service is available at</p>
<p><a title="Sandbox" href="http://sandbox.textmarketer.biz/services/rest">http://sandbox.textmarketer.biz/services/rest</a></p>
<p>i.e. only the hostname changes from <em>www.textmarketer.biz</em> to <em>sandbox.textmarketer.biz</em> within the resource URI.</p>
<p>The sandbox will do the same validation of your request as the live REST API and return the appropriate errors, but will not perform any action that modifies your account data or your credits. Nor will it actually send any SMS messages, so no delivery report will be generated.</p>
<p>NOTE: Accesses to the sandbox is limited to a certain number of requests per minute &#8211; to reduce load on our servers &#8211; in order to guarantee a good service to all our users. Therefore you may prefer to use the Sandbox only to check that individual requests work correctly, rather than testing bulk SMS sends. There is no restriction on SMS sends on the live system.</p>
<img src="http://www.textmarketer.co.uk/wordpress/?ak_action=api_record_view&id=1134&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.textmarketer.co.uk/blog/2010/03/business-sms/rest-sms-api-specification-document/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>REST SMS API Code Examples</title>
		<link>http://www.textmarketer.co.uk/blog/2010/03/dev/rest-sms-api-code-examples/</link>
		<comments>http://www.textmarketer.co.uk/blog/2010/03/dev/rest-sms-api-code-examples/#comments</comments>
		<pubDate>Mon, 22 Mar 2010 10:56:58 +0000</pubDate>
		<dc:creator>Jay</dc:creator>
				<category><![CDATA[All SMS Gateway Documentation]]></category>
		<category><![CDATA[Development Blog]]></category>
		<category><![CDATA[PHP Classes]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php5]]></category>
		<category><![CDATA[RESTful]]></category>
		<category><![CDATA[sms api]]></category>
		<category><![CDATA[support]]></category>

		<guid isPermaLink="false">http://87.106.109.73/blog/?p=1157</guid>
		<description><![CDATA[This blog post has been superseded with our website documentation In our REST API specification document we saw, in general terms, how to make a request to our REST SMS API and how to deal with the response. Here we provide you with some more concrete examples that you can copy &#38; paste! &#8230; <a href="http://www.textmarketer.co.uk/blog/2010/03/dev/rest-sms-api-code-examples/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.textmarketer.co.uk/developers/restful-api.htm">This blog post has been superseded with our website documentation</a></p>
<p>In our <a title="REST SMS API specification" href="/blog/2010/03/business-sms/rest-sms-api-specification-document/" target="_self">REST API specification document</a> we saw, in general terms, how to make a request to our REST SMS API and how to deal with the response. Here we provide you with some more concrete examples that you can copy &amp; paste!</p>
<p>NOTE: You will want to add additional error checking to the examples below.</p>
<p>In each of the languages used here we create a request, send it, receive the response, and parse its contents.</p>
<p><strong>PHP</strong></p>
<p>Example for getting the number of credits:</p>
<pre>$url = 'http://www.textmarketer.biz/services/rest/credits';
$username = 'myAPIusername'; // CHANGE THIS!!!
$password = 'myAPIpassword'; // CHANGE THIS!!!
$url = "$url?username=$username&amp;password=$password";

// we're using the curl library to make the request
$curlHandle = curl_init();
curl_setopt($curlHandle, CURLOPT_URL, $url);
curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true);
$responseBody = curl_exec($curlHandle);
$responseInfo  = curl_getinfo($curlHandle);
curl_close($curlHandle);

// deal with the response
if ($responseInfo['http_code']==200)
{
	$xml_obj = simplexml_load_string($responseBody);
	$credits = (int) $xml_obj-&gt;credits;
	// do something with the result
	echo $credits;

} else {
	// handle the error
	var_dump($responseBody);
}</pre>
<p>Example for getting the list of delivery reports:</p>
<pre>$url = 'http://www.textmarketer.biz/services/rest/deliveryReports';
$username = 'myAPIusername'; // CHANGE THIS!!!
$password = 'myAPIpassword'; // CHANGE THIS!!!
$url = "$url?username=$username&amp;password=$password";

// we're using the curl library to make the request
$curlHandle = curl_init();
curl_setopt($curlHandle, CURLOPT_URL, $url);
curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true);
$responseBody = curl_exec($curlHandle);
$responseInfo  = curl_getinfo($curlHandle);
curl_close($curlHandle);

// deal with the response
if ($responseInfo['http_code']==200)
{
	$xml_obj = simplexml_load_string($responseBody);
	$atts = $xml_obj-&gt;reports-&gt;attributes();
	$num_reports = (int) $atts-&gt;quantity;

	if ($num_reports &gt; 0)
	{
		echo "$num_reports reports\n";
		$reports = array();
		foreach ($xml_obj-&gt;reports-&gt;report as $xml_report)
		{
			$atts = $xml_report-&gt;attributes();
			$name = (string) $atts-&gt;name;
			$updated = (string) $atts-&gt;last_updated;
			$reports[] = array('name'=&gt;$name, 'modified'=&gt;$updated);
		}
		// do something with the report details
		var_dump($reports);
	} else {
		echo 'No reports available';
	}
} else {
	// handle the error
	var_dump($responseBody);
}</pre>
<p>Example for getting the details of a particular delivery report:</p>
<pre>// TODO the URL will change according to the delivery report to retrieve...
$url = 'http://www.textmarketer.biz/services/rest/deliveryReport/GatewayAPI_09-02-10';
$username = 'myAPIusername'; // CHANGE THIS!!!
$password = 'myAPIpassword'; // CHANGE THIS!!!
$url = "$url?username=$username&amp;password=$password";

// we're using the curl library to make the request
$curlHandle = curl_init();
curl_setopt($curlHandle, CURLOPT_URL, $url);
curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true);
$responseBody = curl_exec($curlHandle);
$responseInfo  = curl_getinfo($curlHandle);
curl_close($curlHandle);

// deal with the response
if ($responseInfo['http_code']==200)
{
	$xml_obj = simplexml_load_string($responseBody);

	$reportRows = array();
	foreach ($xml_obj-&gt;report-&gt;reportrow as $xml_reportRow)
	{
		$atts = $xml_reportRow-&gt;attributes();
		$mobile = (string) $atts-&gt;mobile_number;
		$updated = (string) $atts-&gt;last_updated;
		$msgID = (int) $atts-&gt;message_id;
		$status = (string) $atts-&gt;status;
		$reports[] = array('mobile'=&gt;$mobile, 'modified'=&gt;$updated, 'messageID'=&gt;$msgID, 'status'=&gt;$status);
	}
	// do something with the report details
	var_dump($reports);

} else {
	// handle the error
	var_dump($responseBody);
}</pre>
<p>Example for sending an SMS:</p>
<pre>$url = 'http://www.textmarketer.biz/services/rest/sms';
$username = 'myAPIusername'; // CHANGE THIS!!!
$password = 'myAPIpassword'; // CHANGE THIS!!!

$data = array('message'=&gt;'hello','mobile_number'=&gt;'447777777777', 'originator'=&gt;'me',
	'username'=&gt;$username, 'password'=&gt;$password);
$data = http_build_query($data, '', '&amp;');
// we're using the curl library to make the request
$curlHandle = curl_init();
curl_setopt($curlHandle, CURLOPT_URL, $url);
curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curlHandle, CURLOPT_POSTFIELDS, $data);
curl_setopt($curlHandle, CURLOPT_POST, 1);
$responseBody = curl_exec($curlHandle);
$responseInfo  = curl_getinfo($curlHandle);
curl_close($curlHandle);

// deal with the response
if ($responseInfo['http_code']==200)
{
	$xml_obj = simplexml_load_string($responseBody);
	// do something with the result
	echo "Message ID: $xml_obj-&gt;message_id\n";
	echo "Credits used: $xml_obj-&gt;credits_used\n";

	var_dump($responseBody);

} else {
	// handle the error
	var_dump($responseInfo);
	var_dump($responseBody);
}</pre>
<p>Example for transferring credits:</p>
<pre>
<div>&lt;?php</div>
<div>/**</div>
<div> * POST request on the 'credits' resource (credit transfer)</div>
<div> */</div>
<div>$url = '<a href="http://www.textmarketer.biz/services/rest/credits" target="_blank">http://www.textmarketer.biz/services/rest/credits</a>';</div>
<div>// for testing:</div>
<div>//$url = '<a href="http://sandbox.textmarketer.biz/services/rest/credits" target="_blank">http://sandbox.textmarketer.biz/services/rest/credits</a>';</div>
<div>$username = 'myAPIusername'; // CHANGE THIS!!! - the username of the account you're transferring FROM</div>
<div>$password = 'myAPIpassword'; // CHANGE THIS!!!</div>
<div>$targetAccountNumber = 0; // CHANGE THIS!!</div>
<div></div>
<div>$data = array('quantity'=&gt;'1','target'=&gt;$targetAccountNumber,</div>
<div><span>	</span>'username'=&gt;$username, 'password'=&gt;$password);</div>
<div>$data = http_build_query($data, '', '&amp;');</div>
<div>// we're using the curl library to make the request</div>
<div>$curlHandle = curl_init();</div>
<div>curl_setopt($curlHandle, CURLOPT_URL, $url);</div>
<div>curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true);</div>
<div>curl_setopt($curlHandle, CURLOPT_POSTFIELDS, $data);</div>
<div>curl_setopt($curlHandle, CURLOPT_POST, 1);</div>
<div>$responseBody = curl_exec($curlHandle);</div>
<div>$responseInfo  = curl_getinfo($curlHandle);</div>
<div>curl_close($curlHandle);</div>
<div></div>
<div>// deal with the response</div>
<div>if ($responseInfo['http_code']==200)</div>
<div>{</div>
<div> // success - you may want to read in the return data here to see how many credits were  left on each account</div>
<div></div>
<div>} else {</div>
<div><span>	</span>// handle the error here</div>
<div><span>	</span>// var_dump($responseInfo);</div>
<div><span>	</span>// var_dump($responseBody);</div>
<div>}</div>

?&gt;</pre>
<p>For more details on creating <a title="REST requests in PHP" href="http://www.gen-x-design.com/archives/making-restful-requests-in-php/" target="_blank">REST requests in PHP, see here</a>.</p>
<img src="http://www.textmarketer.co.uk/wordpress/?ak_action=api_record_view&id=1157&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.textmarketer.co.uk/blog/2010/03/dev/rest-sms-api-code-examples/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

