C# Code Samples

Sending SMS Messages

Sends SMS text messages via the short code 25827 (212121 In Canada) to a single phone number or an array of phone numbers.

Code Samples

C# - XML
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
using System;
using System.Net;
using System.IO;
using System.Text;
using System.Xml;

namespace RESTex1
{
    class Program
    {
        static void Main(string[] args)
        {
            bool isSuccesResponse = true;
            string ret = string.Empty;
            WebRequest w = WebRequest.Create("https://app.clubtexting.com/sending/messages?format=xml");
            w.Method = "POST";
            w.ContentType = "application/x-www-form-urlencoded";
            using (Stream writeStream = w.GetRequestStream())
            {
                byte[] bytes = Encoding.UTF8.GetBytes("User=winnie&Password=the-pooh&PhoneNumbers[]=2123456785&PhoneNumbers[]=2123456786&PhoneNumbers[]=2123456787&PhoneNumbers[]=2123456788&Subject=From Winnie&Message=I am a Bear of Very Little Brain, and long words bother me&StampToSend=1305582245&MessageTypeID=1");
                writeStream.Write(bytes, 0, bytes.Length);
            }
            try
            {
                using (HttpWebResponse r = (HttpWebResponse)w.GetResponse())
                {
                    ret = GetResponseString(r);
                }
            }
            catch (System.Net.WebException ex)
            {
                if (ex.Status == WebExceptionStatus.ProtocolError)
                {
                    ret = GetResponseString(ex.Response);
                    isSuccesResponse = false;
                }
            }
            XmlDocument response = new XmlDocument();
            response.LoadXml(ret);
            System.Console.Out.WriteLine("Status: "+response.SelectSingleNode("Response/Status").InnerText);
            System.Console.Out.WriteLine("Code: " + response.SelectSingleNode("Response/Code").InnerText);
            if (isSuccesResponse)
            {
                System.Console.Out.WriteLine("Message ID: " + response.SelectSingleNode("Response/Entry/ID").InnerText);
                System.Console.Out.WriteLine("Subject: " + response.SelectSingleNode("Response/Entry/Subject").InnerText);
                System.Console.Out.WriteLine("Message: " + response.SelectSingleNode("Response/Entry/Message").InnerText);
                System.Console.Out.WriteLine("Message Type ID: " + response.SelectSingleNode("Response/Entry/MessageTypeID").InnerText);
                System.Console.Out.WriteLine("Total Recipients: " + response.SelectSingleNode("Response/Entry/RecipientsCount").InnerText);
                System.Console.Out.WriteLine("Credits Charged: " + response.SelectSingleNode("Response/Entry/Credits").InnerText);
                System.Console.Out.WriteLine("Time To Send: " + response.SelectSingleNode("Response/Entry/StampToSend").InnerText);
                System.Console.Out.WriteLine("Phone Numbers: " + ImplodeList(response.SelectNodes("Response/Entry/PhoneNumbers/*")));
                System.Console.Out.WriteLine("Locally Opted Out Numbers: " + ImplodeList(response.SelectNodes("Response/Entry/LocalOptOuts/*")));
                System.Console.Out.WriteLine("Globally Opted Out Numbers: " + ImplodeList(response.SelectNodes("Response/Entry/GlobalOptOuts/*")));
            }
            else
            {
                System.Console.Out.WriteLine("Errors: " + ImplodeList(response.SelectNodes("Response/Errors/*")));
            }
        }

        static string ImplodeList(XmlNodeList list)
        {
            string ret = "";
            foreach (XmlNode node in list)
            {
                ret += ", " + node.InnerText;
            }
            return ret.Length > 2 ? ret.Substring(2) : ret;
        }

        static string GetResponseString(WebResponse response)
        {
            using (Stream responseStream = response.GetResponseStream())
            {
                using (StreamReader readStream = new StreamReader(responseStream, Encoding.UTF8))
                {
                    return readStream.ReadToEnd();
                }
            }
        }
    }
}
C# - JSON
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
using System;
using System.Net;
using System.IO;
using System.Text;
using Newtonsoft.Json.Linq;

namespace RESTex1J
{
    class Program
    {
        static void Main(string[] args)
        {
            bool isSuccesResponse = true;
            string ret = string.Empty;
            WebRequest w = WebRequest.Create("https://app.clubtexting.com/sending/messages?format=json");
            w.Method = "POST";
            w.ContentType = "application/x-www-form-urlencoded";
            using (Stream writeStream = w.GetRequestStream())
            {
                byte[] bytes = Encoding.UTF8.GetBytes("User=winnie&Password=the-pooh&PhoneNumbers[]=2123456785&PhoneNumbers[]=2123456786&PhoneNumbers[]=2123456787&PhoneNumbers[]=2123456788&Subject=From Winnie&Message=I am a Bear of Very Little Brain, and long words bother me&StampToSend=1305582245&MessageTypeID=1");
                writeStream.Write(bytes, 0, bytes.Length);
            }
            try
            {
                using (HttpWebResponse r = (HttpWebResponse)w.GetResponse())
                {
                    ret = GetResponseString(r);
                }
            }
            catch (System.Net.WebException ex)
            {
                isSuccesResponse = false;
                if (ex.Status == WebExceptionStatus.ProtocolError)
                {
                    ret = GetResponseString(ex.Response);
                }
            }
            // use free Json.NET library (http://json.codeplex.com/) for JSON handling
            JObject response = JObject.Parse(ret);

            System.Console.Out.WriteLine("Status: " + response.SelectToken("Response.Status"));
            System.Console.Out.WriteLine("Code: " + response.SelectToken("Response.Code"));
            if (isSuccesResponse)
            {
                System.Console.Out.WriteLine("Message ID: " + response.SelectToken("Response.Entry.ID"));
                System.Console.Out.WriteLine("Subject: " + response.SelectToken("Response.Entry.Subject"));
                System.Console.Out.WriteLine("Message: " + response.SelectToken("Response.Entry.Message"));
                System.Console.Out.WriteLine("Message Type ID: " + response.SelectToken("Response.Entry.MessageTypeID"));
                System.Console.Out.WriteLine("Total Recipients: " + response.SelectToken("Response.Entry.RecipientsCount"));
                System.Console.Out.WriteLine("Credits Charged: " + response.SelectToken("Response.Entry.Credits"));
                System.Console.Out.WriteLine("Time To Send: " + response.SelectToken("Response.Entry.StampToSend"));
                System.Console.Out.WriteLine("Phone Numbers: " + response.SelectToken("Response.Entry.PhoneNumbers"));
                System.Console.Out.WriteLine("Locally Opted Out Numbers: " + response.SelectToken("Response.Entry.LocalOptOuts"));
                System.Console.Out.WriteLine("Globally Opted Out Numbers: " + response.SelectToken("Response.Entry.GlobalOptOuts"));
            }
            else
            {
                System.Console.Out.WriteLine("Errors: " + response.SelectToken("Response.Errors"));
            }
        }

        static string GetResponseString(WebResponse response)
        {
            using (Stream responseStream = response.GetResponseStream())
            {
                using (StreamReader readStream = new StreamReader(responseStream, Encoding.UTF8))
                {
                    return readStream.ReadToEnd();
                }
            }
        }
    }
}




Inbox & Folders

When working with the Inbox and Folder you can perform nine actions: Post (Add New Folder), Put (Update A Folder/Move A Message Between Folders), Delete (Delete A Message/Folder), Get (Get Inbox Message/Folder By ID), Index (Get All Messages/All Folders). The code samples below use shared libraries.

You can download them, along with the code samples here: CsharpLib.zip.

Code Samples - Inbox Messages

C# - XML
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SmsTexting;

namespace SmsTextingApiExamples
{
    class IncomingMessages
    {
        static void Main(string[] args)
        {
            var sms = new SmsTextingRestClient("demouser", "password", SmsTextingRestClient.XML);
            System.Console.Out.WriteLine("XML encoding.");

            var incomingMessages = sms.GetIncomingMessages(null, null, null, null, null, null);
            System.Console.Out.WriteLine("Get incomingMessages:");
            incomingMessages.ForEach(t => System.Console.Out.WriteLine(t));

            sms.MoveIncomingMessages(incomingMessages.Select(m => m.ID).ToList(), "77");
            System.Console.Out.WriteLine("IncomingMessages Move.");

            var msg = incomingMessages.First();

            sms.MoveIncomingMessage(msg.ID, "77");
            System.Console.Out.WriteLine("IncomingMessage Move.");


            var incomingMessage = sms.GetIncomingMessage(msg.ID);
            System.Console.Out.WriteLine("IncomingMessage get: " + incomingMessage);


            sms.DeleteIncomingMessage(incomingMessage.ID);
            System.Console.Out.WriteLine("IncomingMessage delete.");
            try
            {
                sms.DeleteIncomingMessage(incomingMessage.ID);
            }
            catch (Exception e)
            {
                System.Console.Out.WriteLine("Get Exception after delete not existent incomingMessage: " + e.Message);
            }

            
        }
    }
}
C# - JSON
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SmsTexting;

namespace SmsTextingApiExamples
{
    class IncomingMessages
    {
        static void Main(string[] args)
        {
            var sms = new SmsTextingRestClient("demouser", "password", SmsTextingRestClient.JSON);
            System.Console.Out.WriteLine("JSON encoding.");

            incomingMessages = sms.GetIncomingMessages(null, null, null, null, null, null);
            System.Console.Out.WriteLine("Get incomingMessages:");
            incomingMessages.ForEach(t => System.Console.Out.WriteLine(t));

            sms.MoveIncomingMessages(incomingMessages.Select(m => m.ID).ToList(), "77");
            System.Console.Out.WriteLine("IncomingMessages Move.");



            msg = incomingMessages.First();

            sms.MoveIncomingMessage(msg.ID, "77");
            System.Console.Out.WriteLine("IncomingMessage Move.");


            incomingMessage = sms.GetIncomingMessage(msg.ID);
            System.Console.Out.WriteLine("IncomingMessage get: " + incomingMessage);


            sms.DeleteIncomingMessage(incomingMessage.ID);
            System.Console.Out.WriteLine("IncomingMessage delete.");
            try
            {
                sms.DeleteIncomingMessage(incomingMessage.ID);
            }
            catch (Exception e)
            {
                System.Console.Out.WriteLine("Get Exception after delete not existent incomingMessage: " + e.Message);
            }
            
        }
    }
}


Code Samples - Inbox Folders

C# - XML
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SmsTexting;

namespace SmsTextingApiExamples
{
    class InboxFolders
    {
        static void Main(string[] args)
        {
            var sms = new SmsTextingRestClient("demouser", "password", SmsTextingRestClient.XML);
            System.Console.Out.WriteLine("XML encoding.");

            var inboxFolders = sms.GetInboxFolders();
            System.Console.Out.WriteLine("Get inboxFolders:");
            inboxFolders.ForEach(t => System.Console.Out.WriteLine(t));


            var inboxFolder = new InboxFolder("Customers");
            inboxFolder = sms.CreateInboxFolder(inboxFolder);
            System.Console.Out.WriteLine("InboxFolder create: " + inboxFolder);

            var inboxFolderId = inboxFolder.ID;

            inboxFolder = sms.GetInboxFolder(inboxFolderId);
            System.Console.Out.WriteLine("InboxFolder get: " + inboxFolder);

            inboxFolder.Name = "Customers2";
            inboxFolder.ID = inboxFolderId;
            sms.UpdateInboxFolder(inboxFolder);
            System.Console.Out.WriteLine("InboxFolder update. ");

            inboxFolder = sms.GetInboxFolder(inboxFolderId);
            System.Console.Out.WriteLine("InboxFolder get: " + inboxFolder);

            sms.DeleteInboxFolder(inboxFolderId);
            System.Console.Out.WriteLine("InboxFolder delete.");
            try
            {
                sms.DeleteInboxFolder(inboxFolderId);
            }
            catch (Exception e)
            {
                System.Console.Out.WriteLine("Get Exception after delete not existent inboxFolder: " + e.Message);
            }

        }
    }
}
C# - JSON
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SmsTexting;

namespace SmsTextingApiExamples
{
    class InboxFolders
    {
        static void Main(string[] args)
        {
            var sms = new SmsTextingRestClient("demouser", "password", SmsTextingRestClient.JSON);
            System.Console.Out.WriteLine("JSON encoding.");

            inboxFolders = sms.GetInboxFolders();
            System.Console.Out.WriteLine("Get inboxFolders:");
            inboxFolders.ForEach(t => System.Console.Out.WriteLine(t));


            inboxFolder = new InboxFolder("Customers");
            inboxFolder = sms.CreateInboxFolder(inboxFolder);
            System.Console.Out.WriteLine("InboxFolder create: " + inboxFolder);

            inboxFolderId = inboxFolder.ID;

            inboxFolder = sms.GetInboxFolder(inboxFolderId);
            System.Console.Out.WriteLine("InboxFolder get: " + inboxFolder);

            inboxFolder.Name = "Customers2";
            inboxFolder.ID = inboxFolderId;
            sms.UpdateInboxFolder(inboxFolder);
            System.Console.Out.WriteLine("InboxFolder update. ");

            inboxFolder = sms.GetInboxFolder(inboxFolderId);
            System.Console.Out.WriteLine("InboxFolder get: " + inboxFolder);

            sms.DeleteInboxFolder(inboxFolderId);
            System.Console.Out.WriteLine("InboxFolder delete.");
            try
            {
                sms.DeleteInboxFolder(inboxFolderId);
            }
            catch (Exception e)
            {
                System.Console.Out.WriteLine("Get Exception after delete not existent inboxFolder: " + e.Message);
            }

        }
    }
}




Check Keyword Availability

Check whether a Keyword is available to rent on Club Texting's short code. Please note, we will check availability for the country your account is set to.

Code Samples

C# - XML
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
using System;
using System.Net;
using System.IO;
using System.Text;
using System.Xml;

namespace RESTex2
{
    class Program
    {
        static void Main(string[] args)
        {
            bool isSuccesResponse = true;
            string ret = string.Empty;
            WebRequest w = WebRequest.Create("https://app.clubtexting.com/keywords/new?format=xml&Keyword=honey&User=winnie&Password=the-pooh");
            try
            {
                using (HttpWebResponse r = (HttpWebResponse)w.GetResponse())
                {
                    ret = GetResponseString(r);
                }
            }
            catch (System.Net.WebException ex)
            {
                isSuccesResponse = false;
                if (ex.Status == WebExceptionStatus.ProtocolError)
                {
                    ret = GetResponseString(ex.Response);
                }
            }
            XmlDocument response = new XmlDocument();
            response.LoadXml(ret);
            System.Console.Out.WriteLine("Status: " + response.SelectSingleNode("Response/Status").InnerText);
            System.Console.Out.WriteLine("Code: " + response.SelectSingleNode("Response/Code").InnerText);
            if (isSuccesResponse)
            {
                System.Console.Out.WriteLine("Keyword: " + response.SelectSingleNode("Response/Entry/Keyword").InnerText);
                System.Console.Out.WriteLine("Availability: " + response.SelectSingleNode("Response/Entry/Available").InnerText);
            }
            else
            {
                System.Console.Out.WriteLine("Errors: " + ImplodeList(response.SelectNodes("Response/Errors/*")));
            }
        }

        static string ImplodeList(XmlNodeList list)
        {
            string ret = "";
            foreach (XmlNode node in list)
            {
                ret += ", " + node.InnerText;
            }
            return ret.Length > 2 ? ret.Substring(2) : ret;
        }

        static string GetResponseString(WebResponse response)
        {
            using (Stream responseStream = response.GetResponseStream())
            {
                using (StreamReader readStream = new StreamReader(responseStream, Encoding.UTF8))
                {
                    return readStream.ReadToEnd();
                }
            }
        }
    }
}
C# - JSON
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
using System;
using System.Net;
using System.IO;
using System.Text;
using Newtonsoft.Json.Linq;

namespace RESTex2J
{
    class Program
    {
        static void Main(string[] args)
        {
            bool isSuccesResponse = true;
            string ret = string.Empty;
            WebRequest w = WebRequest.Create("https://app.clubtexting.com/keywords/new?format=json&Keyword=honey&User=winnie&Password=the-pooh");
            try
            {
                using (HttpWebResponse r = (HttpWebResponse)w.GetResponse())
                {
                    ret = GetResponseString(r);
                }
            }
            catch (System.Net.WebException ex)
            {
                isSuccesResponse = false;
                if (ex.Status == WebExceptionStatus.ProtocolError)
                {
                    ret = GetResponseString(ex.Response);
                }
            }
            // use free Json.NET library (http://json.codeplex.com/) for JSON handling
            JObject response = JObject.Parse(ret);
            System.Console.Out.WriteLine("Status: " + response.SelectToken("Response.Status"));
            System.Console.Out.WriteLine("Code: " + response.SelectToken("Response.Code"));
            if (isSuccesResponse)
            {
                System.Console.Out.WriteLine("Keyword: " + response.SelectToken("Response.Entry.Keyword"));
                System.Console.Out.WriteLine("Availability: " + response.SelectToken("Response.Entry.Available"));
            }
            else
            {
                System.Console.Out.WriteLine("Errors: " + response.SelectToken("Response.Errors"));
            }
        }

        static string GetResponseString(WebResponse response)
        {
            using (Stream responseStream = response.GetResponseStream())
            {
                using (StreamReader readStream = new StreamReader(responseStream, Encoding.UTF8))
                {
                    return readStream.ReadToEnd();
                }
            }
        }
    }
}




Rent Keyword

Rents a Keyword for use on Club Texting's short code in the country your account is set to send messages to. You may rent a Keyword using a credit card you have stored in your Club Texting account, or you may pass credit card details when you call the API.

Code Samples - Stored Card

C# - XML
using System;
using System.Net;
using System.IO;
using System.Text;
using System.Xml;

namespace RESTex3_saved
{
    class Program
    {
        static void Main(string[] args)
        {
            bool isSuccesResponse = true;
            string ret = string.Empty;
            WebRequest w = WebRequest.Create("https://app.clubtexting.com/keywords?format=xml");
            w.Method = "POST";
            w.ContentType = "application/x-www-form-urlencoded";
            using (Stream writeStream = w.GetRequestStream())
            {
                byte[] bytes = Encoding.UTF8.GetBytes("User=demouser&Password=password&Keyword=honey222&StoredCreditCard=1111");
                writeStream.Write(bytes, 0, bytes.Length);
            }
            try
            {
                using (HttpWebResponse r = (HttpWebResponse)w.GetResponse())
                {
                    ret = GetResponseString(r);
                }
            }
            catch (System.Net.WebException ex)
            {
                isSuccesResponse = false;
                if (ex.Status == WebExceptionStatus.ProtocolError)
                {
                    ret = GetResponseString(ex.Response);
                }
            }
            XmlDocument response = new XmlDocument();
            response.LoadXml(ret);
            System.Console.Out.WriteLine("Status: " + response.SelectSingleNode("Response/Status").InnerText);
            System.Console.Out.WriteLine("Code: " + response.SelectSingleNode("Response/Code").InnerText);
            if (isSuccesResponse)
            {
                System.Console.Out.WriteLine("Keyword ID: " + response.SelectSingleNode("Response/Entry/ID").InnerText);
                System.Console.Out.WriteLine("Keyword: " + response.SelectSingleNode("Response/Entry/Keyword").InnerText);
                System.Console.Out.WriteLine("Is double opt-in enabled: " + response.SelectSingleNode("Response/Entry/EnableDoubleOptIn").InnerText);
                System.Console.Out.WriteLine("Confirm message: " + response.SelectSingleNode("Response/Entry/ConfirmMessage").InnerText);
                System.Console.Out.WriteLine("Join message: " + response.SelectSingleNode("Response/Entry/JoinMessage").InnerText);
                System.Console.Out.WriteLine("Forward email: " + response.SelectSingleNode("Response/Entry/ForwardEmail").InnerText);
                System.Console.Out.WriteLine("Forward url: " + response.SelectSingleNode("Response/Entry/ForwardUrl").InnerText);
                System.Console.Out.WriteLine("Groups: " + ImplodeList(response.SelectNodes("Response/Entry/ContactGroupIDs/*")));
            }
            else
            {
                System.Console.Out.WriteLine("Errors: " + ImplodeList(response.SelectNodes("Response/Errors/*")));
            }
        }

        static string ImplodeList(XmlNodeList list)
        {
            string ret = "";
            foreach (XmlNode node in list)
            {
                ret += ", " + node.InnerText;
            }
            return ret.Length > 2 ? ret.Substring(2) : ret;
        }

        static string GetResponseString(WebResponse response)
        {
            using (Stream responseStream = response.GetResponseStream())
            {
                using (StreamReader readStream = new StreamReader(responseStream, Encoding.UTF8))
                {
                    return readStream.ReadToEnd();
                }
            }
        }
    }
}
C# - JSON
using System;
using System.Net;
using System.IO;
using System.Text;
using Newtonsoft.Json.Linq;

namespace RESTex3J_saved
{
    class Program
    {
        static void Main(string[] args)
        {
            bool isSuccesResponse = true;
            string ret = string.Empty;
            WebRequest w = WebRequest.Create("https://app.clubtexting.com/keywords?format=json");
            w.Method = "POST";
            w.ContentType = "application/x-www-form-urlencoded";
            using (Stream writeStream = w.GetRequestStream())
            {
                byte[] bytes = Encoding.UTF8.GetBytes("User=demouser&Password=password&Keyword=honey222&StoredCreditCard=1111");
                writeStream.Write(bytes, 0, bytes.Length);
            }
            try
            {
                using (HttpWebResponse r = (HttpWebResponse)w.GetResponse())
                {
                    ret = GetResponseString(r);
                }
            }
            catch (System.Net.WebException ex)
            {
                isSuccesResponse = false;
                if (ex.Status == WebExceptionStatus.ProtocolError)
                {
                    ret = GetResponseString(ex.Response);
                }
            }
            // use free Json.NET library (http://json.codeplex.com/) for JSON handling
            JObject response = JObject.Parse(ret);
            System.Console.Out.WriteLine("Status: " + response.SelectToken("Response.Status"));
            System.Console.Out.WriteLine("Code: " + response.SelectToken("Response.Code"));
            if (isSuccesResponse)
            {
                System.Console.Out.WriteLine("Keyword ID: " + response.SelectToken("Response.Entry.ID"));
                System.Console.Out.WriteLine("Keyword: " + response.SelectToken("Response.Entry.Keyword"));
                System.Console.Out.WriteLine("Is double opt-in enabled: " + response.SelectToken("Response.Entry.EnableDoubleOptIn"));
                System.Console.Out.WriteLine("Confirm message: " + response.SelectToken("Response.Entry.ConfirmMessage"));
                System.Console.Out.WriteLine("Join message: " + response.SelectToken("Response.Entry.JoinMessage"));
                System.Console.Out.WriteLine("Forward email: " + response.SelectToken("Response.Entry.ForwardEmail"));
                System.Console.Out.WriteLine("Forward url: " + response.SelectToken("Response.Entry.ForwardUrl"));
                System.Console.Out.WriteLine("Groups: " + response.SelectToken("Response.Entry.ContactGroupIDs"));
            }
            else
            {
                System.Console.Out.WriteLine("Errors: " + response.SelectToken("Response.Errors"));
            }
        }

        static string GetResponseString(WebResponse response)
        {
            using (Stream responseStream = response.GetResponseStream())
            {
                using (StreamReader readStream = new StreamReader(responseStream, Encoding.UTF8))
                {
                    return readStream.ReadToEnd();
                }
            }
        }
    }
}

Code Samples - Non-Stored Card

C# - XML
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
using System;
using System.Net;
using System.IO;
using System.Text;
using System.Xml;

namespace RESTex3
{
    class Program
    {
        static void Main(string[] args)
        {
            bool isSuccesResponse = true;
            string ret = string.Empty;
            WebRequest w = WebRequest.Create("https://app.clubtexting.com/keywords?format=xml");
            w.Method = "POST";
            w.ContentType = "application/x-www-form-urlencoded";
            using (Stream writeStream = w.GetRequestStream())
            {
                byte[] bytes = Encoding.UTF8.GetBytes("User=winnie&Password=the-pooh&Keyword=honey&FirstName=Winnie&LastName=The Pooh&Street=Hollow tree, under the name of Mr. Sanders&City=Hundred Acre Woods&State=New York&Zip=12345&Country=US&CreditCardTypeID=Visa&Number=4111111111111111&expm=11&SecurityCode=123&ExpirationMonth=10&ExpirationYear=2017");
                writeStream.Write(bytes, 0, bytes.Length);
            }
            try
            {
                using (HttpWebResponse r = (HttpWebResponse)w.GetResponse())
                {
                    ret = GetResponseString(r);
                }
            }
            catch (System.Net.WebException ex)
            {
                isSuccesResponse = false;
                if (ex.Status == WebExceptionStatus.ProtocolError)
                {
                    ret = GetResponseString(ex.Response);
                }
            }
            XmlDocument response = new XmlDocument();
            response.LoadXml(ret);
            System.Console.Out.WriteLine("Status: " + response.SelectSingleNode("Response/Status").InnerText);
            System.Console.Out.WriteLine("Code: " + response.SelectSingleNode("Response/Code").InnerText);
            if (isSuccesResponse)
            {
                System.Console.Out.WriteLine("Keyword ID: " + response.SelectSingleNode("Response/Entry/ID").InnerText);
                System.Console.Out.WriteLine("Keyword: " + response.SelectSingleNode("Response/Entry/Keyword").InnerText);
                System.Console.Out.WriteLine("Is double opt-in enabled: " + response.SelectSingleNode("Response/Entry/EnableDoubleOptIn").InnerText);
                System.Console.Out.WriteLine("Confirm message: " + response.SelectSingleNode("Response/Entry/ConfirmMessage").InnerText);
                System.Console.Out.WriteLine("Join message: " + response.SelectSingleNode("Response/Entry/JoinMessage").InnerText);
                System.Console.Out.WriteLine("Forward email: " + response.SelectSingleNode("Response/Entry/ForwardEmail").InnerText);
                System.Console.Out.WriteLine("Forward url: " + response.SelectSingleNode("Response/Entry/ForwardUrl").InnerText);
                System.Console.Out.WriteLine("Groups: " + ImplodeList(response.SelectNodes("Response/Entry/ContactGroupIDs/*")));
            }
            else
            {
                System.Console.Out.WriteLine("Errors: " + ImplodeList(response.SelectNodes("Response/Errors/*")));
            }
        }

        static string ImplodeList(XmlNodeList list)
        {
            string ret = "";
            foreach (XmlNode node in list)
            {
                ret += ", " + node.InnerText;
            }
            return ret.Length > 2 ? ret.Substring(2) : ret;
        }

        static string GetResponseString(WebResponse response)
        {
            using (Stream responseStream = response.GetResponseStream())
            {
                using (StreamReader readStream = new StreamReader(responseStream, Encoding.UTF8))
                {
                    return readStream.ReadToEnd();
                }
            }
        }
    }
}
C# - JSON

ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
using System;
using System.Net;
using System.IO;
using System.Text;
using Newtonsoft.Json.Linq;

namespace RESTex3J
{
    class Program
    {
        static void Main(string[] args)
        {
            bool isSuccesResponse = true;
            string ret = string.Empty;
            WebRequest w = WebRequest.Create("https://app.clubtexting.com/keywords?format=json");
            w.Method = "POST";
            w.ContentType = "application/x-www-form-urlencoded";
            using (Stream writeStream = w.GetRequestStream())
            {
                byte[] bytes = Encoding.UTF8.GetBytes("User=winnie&Password=the-pooh&Keyword=honey&FirstName=Winnie&LastName=The Pooh&Street=Hollow tree, under the name of Mr. Sanders&City=Hundred Acre Woods&State=New York&Zip=12345&Country=US&CreditCardTypeID=Visa&Number=4111111111111111&expm=11&SecurityCode=123&ExpirationMonth=10&ExpirationYear=2017");
                writeStream.Write(bytes, 0, bytes.Length);
            }
            try
            {
                using (HttpWebResponse r = (HttpWebResponse)w.GetResponse())
                {
                    ret = GetResponseString(r);
                }
            }
            catch (System.Net.WebException ex)
            {
                isSuccesResponse = false;
                if (ex.Status == WebExceptionStatus.ProtocolError)
                {
                    ret = GetResponseString(ex.Response);
                }
            }
            // use free Json.NET library (http://json.codeplex.com/) for JSON handling
            JObject response = JObject.Parse(ret);
            System.Console.Out.WriteLine("Status: " + response.SelectToken("Response.Status"));
            System.Console.Out.WriteLine("Code: " + response.SelectToken("Response.Code"));
            if (isSuccesResponse)
            {
                System.Console.Out.WriteLine("Keyword ID: " + response.SelectToken("Response.Entry.ID"));
                System.Console.Out.WriteLine("Keyword: " + response.SelectToken("Response.Entry.Keyword"));
                System.Console.Out.WriteLine("Is double opt-in enabled: " + response.SelectToken("Response.Entry.EnableDoubleOptIn"));
                System.Console.Out.WriteLine("Confirm message: " + response.SelectToken("Response.Entry.ConfirmMessage"));
                System.Console.Out.WriteLine("Join message: " + response.SelectToken("Response.Entry.JoinMessage"));
                System.Console.Out.WriteLine("Forward email: " + response.SelectToken("Response.Entry.ForwardEmail"));
                System.Console.Out.WriteLine("Forward url: " + response.SelectToken("Response.Entry.ForwardUrl"));
                System.Console.Out.WriteLine("Groups: " + response.SelectToken("Response.Entry.ContactGroupIDs"));
            }
            else
            {
                System.Console.Out.WriteLine("Errors: " + response.SelectToken("Response.Errors"));
            }
        }

        static string GetResponseString(WebResponse response)
        {
            using (Stream responseStream = response.GetResponseStream())
            {
                using (StreamReader readStream = new StreamReader(responseStream, Encoding.UTF8))
                {
                    return readStream.ReadToEnd();
                }
            }
        }
    }
}




Setup A Keyword

Configures an active Keyword for use on Club Texting's short code in the country your account is set to send messages to.

Code Samples

C# - XML
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
using System;
using System.Net;
using System.IO;
using System.Text;
using System.Xml;

namespace RESTex4
{
    class Program
    {
        static void Main(string[] args)
        {
            bool isSuccesResponse = true;
            string ret = string.Empty;
            WebRequest w = WebRequest.Create("https://app.clubtexting.com/keywords/honey?format=xml");
            w.Method = "POST";
            w.ContentType = "application/x-www-form-urlencoded";
            using (Stream writeStream = w.GetRequestStream())
            {
                byte[] bytes = Encoding.UTF8.GetBytes("User=winnie&Password=the-pooh&EnableDoubleOptIn=1&ConfirmMessage=Reply Y to join our sweetest list&JoinMessage=The only reason for being a bee that I know of, is to make honey. And the only reason for making honey, is so as I can eat it.&[email protected]&ForwardUrl=http://bear-alliance.co.uk/honey-donations/&ContactGroupIDs[]=honey lovers");
                writeStream.Write(bytes, 0, bytes.Length);
            }
            try
            {
                using (HttpWebResponse r = (HttpWebResponse)w.GetResponse())
                {
                    ret = GetResponseString(r);
                }
            }
            catch (System.Net.WebException ex)
            {
                isSuccesResponse = false;
                if (ex.Status == WebExceptionStatus.ProtocolError)
                {
                    ret = GetResponseString(ex.Response);
                }
            }
            XmlDocument response = new XmlDocument();
            response.LoadXml(ret);
            System.Console.Out.WriteLine("Status: " + response.SelectSingleNode("Response/Status").InnerText);
            System.Console.Out.WriteLine("Code: " + response.SelectSingleNode("Response/Code").InnerText);
            if (isSuccesResponse)
            {
                System.Console.Out.WriteLine("Keyword ID: " + response.SelectSingleNode("Response/Entry/ID").InnerText);
                System.Console.Out.WriteLine("Keyword: " + response.SelectSingleNode("Response/Entry/Keyword").InnerText);
                System.Console.Out.WriteLine("Is double opt-in enabled: " + response.SelectSingleNode("Response/Entry/EnableDoubleOptIn").InnerText);
                System.Console.Out.WriteLine("Confirm message: " + response.SelectSingleNode("Response/Entry/ConfirmMessage").InnerText);
                System.Console.Out.WriteLine("Join message: " + response.SelectSingleNode("Response/Entry/JoinMessage").InnerText);
                System.Console.Out.WriteLine("Forward email: " + response.SelectSingleNode("Response/Entry/ForwardEmail").InnerText);
                System.Console.Out.WriteLine("Forward url: " + response.SelectSingleNode("Response/Entry/ForwardUrl").InnerText);
                System.Console.Out.WriteLine("Groups: " + ImplodeList(response.SelectNodes("Response/Entry/ContactGroupIDs/*")));
            }
            else
            {
                System.Console.Out.WriteLine("Errors: " + ImplodeList(response.SelectNodes("Response/Errors/*")));
            }
        }

        static string ImplodeList(XmlNodeList list)
        {
            string ret = "";
            foreach (XmlNode node in list)
            {
                ret += ", " + node.InnerText;
            }
            return ret.Length > 2 ? ret.Substring(2) : ret;
        }

        static string GetResponseString(WebResponse response)
        {
            using (Stream responseStream = response.GetResponseStream())
            {
                using (StreamReader readStream = new StreamReader(responseStream, Encoding.UTF8))
                {
                    return readStream.ReadToEnd();
                }
            }
        }
    }
}
C# - JSON
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
using System;
using System.Net;
using System.IO;
using System.Text;
using Newtonsoft.Json.Linq;

namespace RESTex4J
{
    class Program
    {
        static void Main(string[] args)
        {
            bool isSuccesResponse = true;
            string ret = string.Empty;
            WebRequest w = WebRequest.Create("https://app.clubtexting.com/keywords/honey?format=json");
            w.Method = "POST";
            w.ContentType = "application/x-www-form-urlencoded";
            using (Stream writeStream = w.GetRequestStream())
            {
                byte[] bytes = Encoding.UTF8.GetBytes("User=winnie&Password=the-pooh&EnableDoubleOptIn=1&ConfirmMessage=Reply Y to join our sweetest list&JoinMessage=The only reason for being a bee that I know of, is to make honey. And the only reason for making honey, is so as I can eat it.&[email protected]&ForwardUrl=http://bear-alliance.co.uk/honey-donations/&ContactGroupIDs[]=honey lovers");
                writeStream.Write(bytes, 0, bytes.Length);
            }
            try
            {
                using (HttpWebResponse r = (HttpWebResponse)w.GetResponse())
                {
                    ret = GetResponseString(r);
                }
            }
            catch (System.Net.WebException ex)
            {
                isSuccesResponse = false;
                if (ex.Status == WebExceptionStatus.ProtocolError)
                {
                    ret = GetResponseString(ex.Response);
                }
            }
            // use free Json.NET library (http://json.codeplex.com/) for JSON handling
            JObject response = JObject.Parse(ret);
            System.Console.Out.WriteLine("Status: " + response.SelectToken("Response.Status"));
            System.Console.Out.WriteLine("Code: " + response.SelectToken("Response.Code"));
            if (isSuccesResponse)
            {
                System.Console.Out.WriteLine("Keyword ID: " + response.SelectToken("Response.Entry.ID"));
                System.Console.Out.WriteLine("Keyword: " + response.SelectToken("Response.Entry.Keyword"));
                System.Console.Out.WriteLine("Is double opt-in enabled: " + response.SelectToken("Response.Entry.EnableDoubleOptIn"));
                System.Console.Out.WriteLine("Confirm message: " + response.SelectToken("Response.Entry.ConfirmMessage"));
                System.Console.Out.WriteLine("Join message: " + response.SelectToken("Response.Entry.JoinMessage"));
                System.Console.Out.WriteLine("Forward email: " + response.SelectToken("Response.Entry.ForwardEmail"));
                System.Console.Out.WriteLine("Forward url: " + response.SelectToken("Response.Entry.ForwardUrl"));
                System.Console.Out.WriteLine("Groups: " + response.SelectToken("Response.Entry.ContactGroupIDs"));
            }
            else
            {
                System.Console.Out.WriteLine("Errors: " + response.SelectToken("Response.Errors"));
            }
        }

        static string GetResponseString(WebResponse response)
        {
            using (Stream responseStream = response.GetResponseStream())
            {
                using (StreamReader readStream = new StreamReader(responseStream, Encoding.UTF8))
                {
                    return readStream.ReadToEnd();
                }
            }
        }
    }
}




Cancel A Keyword

Cancels an active Keyword on Club Texting's short code in the country your account is set to send messages to.

Code Samples

C# - XML
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
using System;
using System.Net;
using System.IO;
using System.Text;
using System.Xml;

namespace RESTex5
{
    class Program
    {
        static void Main(string[] args)
        {
            bool isSuccesResponse = true;
            string ret = string.Empty;
            HttpStatusCode retStatus = HttpStatusCode.Unused;
            WebRequest w = WebRequest.Create("https://app.clubtexting.com/keywords/honey?format=xml&_method=DELETE");
            w.Method = "POST";
            w.ContentType = "application/x-www-form-urlencoded";
            using (Stream writeStream = w.GetRequestStream())
            {
                byte[] bytes = Encoding.UTF8.GetBytes("User=winnie&Password=the-pooh");
                writeStream.Write(bytes, 0, bytes.Length);
            }
            try
            {
                using (HttpWebResponse r = (HttpWebResponse)w.GetResponse())
                {
                    retStatus = r.StatusCode;
                }
            }
            catch (System.Net.WebException ex)
            {
                isSuccesResponse = false;
                if (ex.Status == WebExceptionStatus.ProtocolError)
                {
                    retStatus = ((HttpWebResponse)ex.Response).StatusCode;
                    ret = GetResponseString(ex.Response);
                }
            }
            System.Console.Out.WriteLine("Status: " + retStatus);
            if (!isSuccesResponse && ret.Length > 0)
            {
                XmlDocument response = new XmlDocument();
                response.LoadXml(ret);
                System.Console.Out.WriteLine("Status: " + response.SelectSingleNode("Response/Status").InnerText);
                System.Console.Out.WriteLine("Code: " + response.SelectSingleNode("Response/Code").InnerText);
                System.Console.Out.WriteLine("Errors: " + ImplodeList(response.SelectNodes("Response/Errors/*")));
            }
        }

        static string ImplodeList(XmlNodeList list)
        {
            string ret = "";
            foreach (XmlNode node in list)
            {
                ret += ", " + node.InnerText;
            }
            return ret.Length > 2 ? ret.Substring(2) : ret;
        }

        static string GetResponseString(WebResponse response)
        {
            using (Stream responseStream = response.GetResponseStream())
            {
                using (StreamReader readStream = new StreamReader(responseStream, Encoding.UTF8))
                {
                    return readStream.ReadToEnd();
                }
            }
        }
    }
}
C# - JSON
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
using System;
using System.Net;
using System.IO;
using System.Text;
using Newtonsoft.Json.Linq;

namespace RESTex5J
{
    class Program
    {
        static void Main(string[] args)
        {
            bool isSuccesResponse = true;
            string ret = string.Empty;
            HttpStatusCode retStatus = HttpStatusCode.Unused;
            WebRequest w = WebRequest.Create("https://app.clubtexting.com/keywords/honey?format=json&_method=DELETE");
            w.Method = "POST";
            w.ContentType = "application/x-www-form-urlencoded";
            using (Stream writeStream = w.GetRequestStream())
            {
                byte[] bytes = Encoding.UTF8.GetBytes("User=winnie&Password=the-pooh");
                writeStream.Write(bytes, 0, bytes.Length);
            }
            try
            {
                using (HttpWebResponse r = (HttpWebResponse)w.GetResponse())
                {
                    retStatus = r.StatusCode;
                }
            }
            catch (System.Net.WebException ex)
            {
                isSuccesResponse = false;
                if (ex.Status == WebExceptionStatus.ProtocolError)
                {
                    retStatus = ((HttpWebResponse)ex.Response).StatusCode;
                    ret = GetResponseString(ex.Response);
                }
            }
            System.Console.Out.WriteLine("Status: " + retStatus);
            if (!isSuccesResponse)
            {
                // use free Json.NET library (http://json.codeplex.com/) for JSON handling
                JObject response = JObject.Parse(ret);
                System.Console.Out.WriteLine("Status: " + response.SelectToken("Response.Status"));
                System.Console.Out.WriteLine("Code: " + response.SelectToken("Response.Code"));
                System.Console.Out.WriteLine("Errors: " + response.SelectToken("Response.Errors"));
            }
        }

        static string GetResponseString(WebResponse response)
        {
            using (Stream responseStream = response.GetResponseStream())
            {
                using (StreamReader readStream = new StreamReader(responseStream, Encoding.UTF8))
                {
                    return readStream.ReadToEnd();
                }
            }
        }
    }
}




Check Credit Balance

Checks credit balances on your account.

Code Samples

C# - XML
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
using System;
using System.Net;
using System.IO;
using System.Text;
using System.Xml;

namespace RESTex6
{
    class Program
    {
        static void Main(string[] args)
        {
            bool isSuccesResponse = true;
            string ret = string.Empty;
            WebRequest w = WebRequest.Create("https://app.clubtexting.com/billing/credits/get?format=xml&User=winnie&Password=the-pooh");
            try
            {
                using (HttpWebResponse r = (HttpWebResponse)w.GetResponse())
                {
                    ret = GetResponseString(r);
                }
            }
            catch (System.Net.WebException ex)
            {
                isSuccesResponse = false;
                if (ex.Status == WebExceptionStatus.ProtocolError)
                {
                    ret = GetResponseString(ex.Response);
                }
            }
            XmlDocument response = new XmlDocument();
            response.LoadXml(ret);
            System.Console.Out.WriteLine("Status: " + response.SelectSingleNode("Response/Status").InnerText);
            System.Console.Out.WriteLine("Code: " + response.SelectSingleNode("Response/Code").InnerText);
            if (isSuccesResponse)
            {
                System.Console.Out.WriteLine("Plan credits: " + response.SelectSingleNode("Response/Entry/PlanCredits").InnerText);
                System.Console.Out.WriteLine("Anytime credits: " + response.SelectSingleNode("Response/Entry/AnytimeCredits").InnerText);
                System.Console.Out.WriteLine("Total: " + response.SelectSingleNode("Response/Entry/TotalCredits").InnerText);
            }
            else
            {
                System.Console.Out.WriteLine("Errors: " + ImplodeList(response.SelectNodes("Response/Errors/*")));
            }
        }

        static string ImplodeList(XmlNodeList list)
        {
            string ret = "";
            foreach (XmlNode node in list)
            {
                ret += ", " + node.InnerText;
            }
            return ret.Length > 2 ? ret.Substring(2) : ret;
        }

        static string GetResponseString(WebResponse response)
        {
            using (Stream responseStream = response.GetResponseStream())
            {
                using (StreamReader readStream = new StreamReader(responseStream, Encoding.UTF8))
                {
                    return readStream.ReadToEnd();
                }
            }
        }
    }
}
C# - JSON
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
using System;
using System.Net;
using System.IO;
using System.Text;
using Newtonsoft.Json.Linq;

namespace RESTex6J
{
    class Program
    {
        static void Main(string[] args)
        {
            bool isSuccesResponse = true;
            string ret = string.Empty;
            WebRequest w = WebRequest.Create("https://app.clubtexting.com/billing/credits/get?format=json&User=winnie&Password=the-pooh");
            try
            {
                using (HttpWebResponse r = (HttpWebResponse)w.GetResponse())
                {
                    ret = GetResponseString(r);
                }
            }
            catch (System.Net.WebException ex)
            {
                isSuccesResponse = false;
                if (ex.Status == WebExceptionStatus.ProtocolError)
                {
                    ret = GetResponseString(ex.Response);
                }
            }
            // use free Json.NET library (http://json.codeplex.com/) for JSON handling
            JObject response = JObject.Parse(ret);
            System.Console.Out.WriteLine("Status: " + response.SelectToken("Response.Status"));
            System.Console.Out.WriteLine("Code: " + response.SelectToken("Response.Code"));
            if (isSuccesResponse)
            {
                System.Console.Out.WriteLine("Plan credits: " + response.SelectToken("Response.Entry.PlanCredits"));
                System.Console.Out.WriteLine("Anytime credits: " + response.SelectToken("Response.Entry.AnytimeCredits"));
                System.Console.Out.WriteLine("Total: " + response.SelectToken("Response.Entry.TotalCredits"));
            }
            else
            {
                System.Console.Out.WriteLine("Errors: " + response.SelectToken("Response.Errors"));
            }
        }

        static string GetResponseString(WebResponse response)
        {
            using (Stream responseStream = response.GetResponseStream())
            {
                using (StreamReader readStream = new StreamReader(responseStream, Encoding.UTF8))
                {
                    return readStream.ReadToEnd();
                }
            }
        }
    }
}




Buy Credits

Buys more credits for your account. You may purchase credits using a credit card you have stored in your Club Texting account, or you may pass credit card details when you call the API.

Code Samples - Stored Card

C# - XML
using System;
using System.Net;
using System.IO;
using System.Text;
using System.Xml;

namespace RESTex7_saved
{
    class Program
    {
        static void Main(string[] args)
        {
            bool isSuccesResponse = true;
            string ret = string.Empty;
            WebRequest w = WebRequest.Create("https://app.clubtexting.com/billing/credits?format=xml");
            w.Method = "POST";
            w.ContentType = "application/x-www-form-urlencoded";
            using (Stream writeStream = w.GetRequestStream())
            {
                byte[] bytes = Encoding.UTF8.GetBytes("User=demouser&Password=password&NumberOfCredits=1000&CouponCode=honey2011&StoredCreditCard=1111");
                writeStream.Write(bytes, 0, bytes.Length);
            }
            try
            {
                using (HttpWebResponse r = (HttpWebResponse)w.GetResponse())
                {
                    ret = GetResponseString(r);
                }
            }
            catch (System.Net.WebException ex)
            {
                isSuccesResponse = false;
                if (ex.Status == WebExceptionStatus.ProtocolError)
                {
                    System.Console.Out.WriteLine(((HttpWebResponse)ex.Response).StatusCode);
                    ret = GetResponseString(ex.Response);
                }
            }
            if (ret.Length > 0)
            {
                XmlDocument response = new XmlDocument();
                response.LoadXml(ret);
                System.Console.Out.WriteLine("Status: " + response.SelectSingleNode("Response/Status").InnerText);
                System.Console.Out.WriteLine("Code: " + response.SelectSingleNode("Response/Code").InnerText);
                if (isSuccesResponse)
                {
                    System.Console.Out.WriteLine("Credits purchased: " + response.SelectSingleNode("Response/Entry/BoughtCredits").InnerText);
                    System.Console.Out.WriteLine("Amount charged, $: " + response.SelectSingleNode("Response/Entry/Amount").InnerText);
                    System.Console.Out.WriteLine("Discount, $: " + response.SelectSingleNode("Response/Entry/Discount").InnerText);
                    System.Console.Out.WriteLine("Plan credits: " + response.SelectSingleNode("Response/Entry/PlanCredits").InnerText);
                    System.Console.Out.WriteLine("Anytime credits: " + response.SelectSingleNode("Response/Entry/AnytimeCredits").InnerText);
                    System.Console.Out.WriteLine("Total: " + response.SelectSingleNode("Response/Entry/TotalCredits").InnerText);
                }
                else
                {
                    System.Console.Out.WriteLine("Errors: " + ImplodeList(response.SelectNodes("Response/Errors/*")));
                }
            }
        }

        static string ImplodeList(XmlNodeList list)
        {
            string ret = "";
            foreach (XmlNode node in list)
            {
                ret += ", " + node.InnerText;
            }
            return ret.Length > 2 ? ret.Substring(2) : ret;
        }

        static string GetResponseString(WebResponse response)
        {
            using (Stream responseStream = response.GetResponseStream())
            {
                using (StreamReader readStream = new StreamReader(responseStream, Encoding.UTF8))
                {
                    return readStream.ReadToEnd();
                }
            }
        }
    }
}
C# - JSON
using System;
using System.Net;
using System.IO;
using System.Text;
using Newtonsoft.Json.Linq;

namespace RESTex7J_saved
{
    class Program
    {
        static void Main(string[] args)
        {
            bool isSuccesResponse = true;
            string ret = string.Empty;
            WebRequest w = WebRequest.Create("https://app.clubtexting.com/billing/credits?format=json");
            w.Method = "POST";
            w.ContentType = "application/x-www-form-urlencoded";
            using (Stream writeStream = w.GetRequestStream())
            {
                byte[] bytes = Encoding.UTF8.GetBytes("User=demouser&Password=password&NumberOfCredits=1000&CouponCode=honey2011&StoredCreditCard=1111");
                writeStream.Write(bytes, 0, bytes.Length);
            }
            try
            {
                using (HttpWebResponse r = (HttpWebResponse)w.GetResponse())
                {
                    ret = GetResponseString(r);
                }
            }
            catch (System.Net.WebException ex)
            {
                isSuccesResponse = false;
                if (ex.Status == WebExceptionStatus.ProtocolError)
                {
                    System.Console.Out.WriteLine(((HttpWebResponse)ex.Response).StatusCode);
                    ret = GetResponseString(ex.Response);
                }
            }
            if (ret.Length > 0)
            {
                // use free Json.NET library (http://json.codeplex.com/) for JSON handling
                JObject response = JObject.Parse(ret);

                System.Console.Out.WriteLine("Status: " + response.SelectToken("Response.Status"));
                System.Console.Out.WriteLine("Code: " + response.SelectToken("Response.Code"));
                if (isSuccesResponse)
                {
                    System.Console.Out.WriteLine("Credits purchased: " + response.SelectToken("Response.Entry.BoughtCredits"));
                    System.Console.Out.WriteLine("Amount charged, $: " + response.SelectToken("Response.Entry.Amount"));
                    System.Console.Out.WriteLine("Discount, $: " + response.SelectToken("Response.Entry.Discount"));
                    System.Console.Out.WriteLine("Plan credits: " + response.SelectToken("Response.Entry.PlanCredits"));
                    System.Console.Out.WriteLine("Anytime credits: " + response.SelectToken("Response.Entry.AnytimeCredits"));
                    System.Console.Out.WriteLine("Total: " + response.SelectToken("Response.Entry.TotalCredits"));
                }
                else
                {
                    System.Console.Out.WriteLine("Errors: " + response.SelectToken("Response.Errors"));
                }
            }
        }

        static string GetResponseString(WebResponse response)
        {
            using (Stream responseStream = response.GetResponseStream())
            {
                using (StreamReader readStream = new StreamReader(responseStream, Encoding.UTF8))
                {
                    return readStream.ReadToEnd();
                }
            }
        }
    }
}

Code Samples - Non-Stored Card

C# - XML
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
using System;
using System.Net;
using System.IO;
using System.Text;
using System.Xml;

namespace RESTex7
{
    class Program
    {
        static void Main(string[] args)
        {
            bool isSuccesResponse = true;
            string ret = string.Empty;
            WebRequest w = WebRequest.Create("https://app.clubtexting.com/billing/credits?format=xml");
            w.Method = "POST";
            w.ContentType = "application/x-www-form-urlencoded";
            using (Stream writeStream = w.GetRequestStream())
            {
                byte[] bytes = Encoding.UTF8.GetBytes("User=winnie&Password=the-pooh&NumberOfCredits=1000&CouponCode=honey2011&FirstName=Winnie&LastName=The Pooh&Street=Hollow tree, under the name of Mr. Sanders&City=Hundred Acre Woods&State=New York&Zip=12345&Country=US&CreditCardTypeID=Visa&Number=4111111111111111&SecurityCode=123&ExpirationMonth=10&ExpirationYear=2017");
                writeStream.Write(bytes, 0, bytes.Length);
            }
            try
            {
                using (HttpWebResponse r = (HttpWebResponse)w.GetResponse())
                {
                    ret = GetResponseString(r);
                }
            }
            catch (System.Net.WebException ex)
            {
                isSuccesResponse = false;
                if (ex.Status == WebExceptionStatus.ProtocolError)
                {
                    System.Console.Out.WriteLine(((HttpWebResponse)ex.Response).StatusCode);
                    ret = GetResponseString(ex.Response);
                }
            }
            if (ret.Length > 0)
            {
                XmlDocument response = new XmlDocument();
                response.LoadXml(ret);
                System.Console.Out.WriteLine("Status: " + response.SelectSingleNode("Response/Status").InnerText);
                System.Console.Out.WriteLine("Code: " + response.SelectSingleNode("Response/Code").InnerText);
                if (isSuccesResponse)
                {
                    System.Console.Out.WriteLine("Credits purchased: " + response.SelectSingleNode("Response/Entry/BoughtCredits").InnerText);
                    System.Console.Out.WriteLine("Amount charged, $: " + response.SelectSingleNode("Response/Entry/Amount").InnerText);
                    System.Console.Out.WriteLine("Discount, $: " + response.SelectSingleNode("Response/Entry/Discount").InnerText);
                    System.Console.Out.WriteLine("Plan credits: " + response.SelectSingleNode("Response/Entry/PlanCredits").InnerText);
                    System.Console.Out.WriteLine("Anytime credits: " + response.SelectSingleNode("Response/Entry/AnytimeCredits").InnerText);
                    System.Console.Out.WriteLine("Total: " + response.SelectSingleNode("Response/Entry/TotalCredits").InnerText);
                }
                else
                {
                    System.Console.Out.WriteLine("Errors: " + ImplodeList(response.SelectNodes("Response/Errors/*")));
                }
            }
        }

        static string ImplodeList(XmlNodeList list)
        {
            string ret = "";
            foreach (XmlNode node in list)
            {
                ret += ", " + node.InnerText;
            }
            return ret.Length > 2 ? ret.Substring(2) : ret;
        }

        static string GetResponseString(WebResponse response)
        {
            using (Stream responseStream = response.GetResponseStream())
            {
                using (StreamReader readStream = new StreamReader(responseStream, Encoding.UTF8))
                {
                    return readStream.ReadToEnd();
                }
            }
        }
    }
}
C# - JSON
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
using System;
using System.Net;
using System.IO;
using System.Text;
using Newtonsoft.Json.Linq;

namespace RESTex7J
{
    class Program
    {
        static void Main(string[] args)
        {
            bool isSuccesResponse = true;
            string ret = string.Empty;
            WebRequest w = WebRequest.Create("https://app.clubtexting.com/billing/credits?format=json");
            w.Method = "POST";
            w.ContentType = "application/x-www-form-urlencoded";
            using (Stream writeStream = w.GetRequestStream())
            {
                byte[] bytes = Encoding.UTF8.GetBytes("User=winnie&Password=the-pooh&NumberOfCredits=1000&CouponCode=honey2011&FirstName=Winnie&LastName=The Pooh&Street=Hollow tree, under the name of Mr. Sanders&City=Hundred Acre Woods&State=New York&Zip=12345&Country=US&CreditCardTypeID=Visa&Number=4111111111111111&SecurityCode=123&ExpirationMonth=10&ExpirationYear=2017");
                writeStream.Write(bytes, 0, bytes.Length);
            }
            try
            {
                using (HttpWebResponse r = (HttpWebResponse)w.GetResponse())
                {
                    ret = GetResponseString(r);
                }
            }
            catch (System.Net.WebException ex)
            {
                isSuccesResponse = false;
                if (ex.Status == WebExceptionStatus.ProtocolError)
                {
                    System.Console.Out.WriteLine(((HttpWebResponse)ex.Response).StatusCode);
                    ret = GetResponseString(ex.Response);
                }
            }
            if (ret.Length > 0)
            {
                // use free Json.NET library (http://json.codeplex.com/) for JSON handling
                JObject response = JObject.Parse(ret);

                System.Console.Out.WriteLine("Status: " + response.SelectToken("Response.Status"));
                System.Console.Out.WriteLine("Code: " + response.SelectToken("Response.Code"));
                if (isSuccesResponse)
                {
                    System.Console.Out.WriteLine("Credits purchased: " + response.SelectToken("Response.Entry.BoughtCredits"));
                    System.Console.Out.WriteLine("Amount charged, $: " + response.SelectToken("Response.Entry.Amount"));
                    System.Console.Out.WriteLine("Discount, $: " + response.SelectToken("Response.Entry.Discount"));
                    System.Console.Out.WriteLine("Plan credits: " + response.SelectToken("Response.Entry.PlanCredits"));
                    System.Console.Out.WriteLine("Anytime credits: " + response.SelectToken("Response.Entry.AnytimeCredits"));
                    System.Console.Out.WriteLine("Total: " + response.SelectToken("Response.Entry.TotalCredits"));
                }
                else
                {
                    System.Console.Out.WriteLine("Errors: " + response.SelectToken("Response.Errors"));
                }
            }
        }

        static string GetResponseString(WebResponse response)
        {
            using (Stream responseStream = response.GetResponseStream())
            {
                using (StreamReader readStream = new StreamReader(responseStream, Encoding.UTF8))
                {
                    return readStream.ReadToEnd();
                }
            }
        }
    }
}




Carrier Lookup

Returns the wireless carrier of a valid mobile phone number (US & Canada)

Code Samples

C# - XML
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
using System;
using System.Net;
using System.IO;
using System.Text;
using System.Xml;

namespace RESTex8
{
    class Program
    {
        static void Main(string[] args)
        {
            bool isSuccesResponse = true;
            string ret = string.Empty;
            WebRequest w = WebRequest.Create("https://app.clubtexting.com/sending/phone-numbers/2123456786?format=xml&User=winnielkup&Password=winnielkup");
            try
            {
                using (HttpWebResponse r = (HttpWebResponse)w.GetResponse())
                {
                    ret = GetResponseString(r);
                }
            }
            catch (System.Net.WebException ex)
            {
                isSuccesResponse = false;
                if (ex.Status == WebExceptionStatus.ProtocolError)
                {
                    ret = GetResponseString(ex.Response);
                }
            }
            XmlDocument response = new XmlDocument();
            response.LoadXml(ret);
            System.Console.Out.WriteLine("Status: " + response.SelectSingleNode("Response/Status").InnerText);
            System.Console.Out.WriteLine("Code: " + response.SelectSingleNode("Response/Code").InnerText);
            if (isSuccesResponse)
            {
                System.Console.Out.WriteLine("Phone number: " + response.SelectSingleNode("Response/Entry/PhoneNumber").InnerText);
                System.Console.Out.WriteLine("CarrierName: " + response.SelectSingleNode("Response/Entry/CarrierName").InnerText);
            }
            else
            {
                System.Console.Out.WriteLine("Errors: " + ImplodeList(response.SelectNodes("Response/Errors/*")));
            }
        }

        static string ImplodeList(XmlNodeList list)
        {
            string ret = "";
            foreach (XmlNode node in list)
            {
                ret += ", " + node.InnerText;
            }
            return ret.Length > 2 ? ret.Substring(2) : ret;
        }

        static string GetResponseString(WebResponse response)
        {
            using (Stream responseStream = response.GetResponseStream())
            {
                using (StreamReader readStream = new StreamReader(responseStream, Encoding.UTF8))
                {
                    return readStream.ReadToEnd();
                }
            }
        }
    }
}
C# - JSON
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
using System;
using System.Net;
using System.IO;
using System.Text;
using Newtonsoft.Json.Linq;

namespace RESTex8J
{
    class Program
    {
        static void Main(string[] args)
        {
            bool isSuccesResponse = true;
            string ret = string.Empty;
            WebRequest w = WebRequest.Create("https://app.clubtexting.com/sending/phone-numbers/2123456786?format=json&User=winnielkup&Password=winnielkup1");
            try
            {
                using (HttpWebResponse r = (HttpWebResponse)w.GetResponse())
                {
                    ret = GetResponseString(r);
                }
            }
            catch (System.Net.WebException ex)
            {
                isSuccesResponse = false;
                if (ex.Status == WebExceptionStatus.ProtocolError)
                {
                    ret = GetResponseString(ex.Response);
                }
            }
            // use free Json.NET library (http://json.codeplex.com/) for JSON handling
            JObject response = JObject.Parse(ret);
            System.Console.Out.WriteLine("Status: " + response.SelectToken("Response.Status"));
            System.Console.Out.WriteLine("Code: " + response.SelectToken("Response.Code"));
            if (isSuccesResponse)
            {
                System.Console.Out.WriteLine("Phone number: " + response.SelectToken("Response.Entry.PhoneNumber"));
                System.Console.Out.WriteLine("CarrierName: " + response.SelectToken("Response.Entry.CarrierName"));
            }
            else
            {
                System.Console.Out.WriteLine("Errors: " + response.SelectToken("quot;Response.Errors"));
            }
        }

        static string GetResponseString(WebResponse response)
        {
            using (Stream responseStream = response.GetResponseStream())
            {
                using (StreamReader readStream = new StreamReader(responseStream, Encoding.UTF8))
                {
                    return readStream.ReadToEnd();
                }
            }
        }
    }
}




Contacts

When working with Contacts you can perform five actions: Post (Add New Contact), Put (Update/Edit A Contact), Delete (Delete A Contact), Get (Get Contact By ID), Index (Get All Contacts). The code samples below use shared libraries and packages.

You can download them, along with the code samples here: CsharpLib.zip.

Code Samples

C# - XML
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SmsTexting;

namespace SmsTextingApiExamples
{
    class Contacts
    {
        static void Main(string[] args)
        {
            var sms = new SmsTextingRestClient("demouser", "password", SmsTextingRestClient.XML);
            System.Console.Out.WriteLine("XML encoding.");

            var contacts = sms.GetContacts(null, null, null, "Honey Lovers", null, null, null, null);
            System.Console.Out.WriteLine("Get contacts:");
            contacts.ForEach(t => System.Console.Out.WriteLine(t));


            var contact = new Contact("2123456899", "Piglet", "P.", "[email protected]", "It is hard to be brave, when you are only a Very Small Animal.", null);
            contact = sms.CreateContact(contact);
            System.Console.Out.WriteLine("Contact create: " + contact);

            contact = sms.GetContact(contact.ID);
            System.Console.Out.WriteLine("Contact get: " + contact);

            contact.Note = "The note";
            contact.Groups.Add("Friends");
            contact.Groups.Add("Neighbors");
            contact = sms.UpdateContact(contact);
            System.Console.Out.WriteLine("Contact update: " + contact);

            sms.DeleteContact(contact.ID);
            System.Console.Out.WriteLine("Contact delete.");
            try
            {
                sms.DeleteContact(contact.ID);
            }
            catch (Exception e)
            {
                System.Console.Out.WriteLine("Get Exception after delete not existent contact: " + e.Message);
            }

        }
    }
}
C# - JSON
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SmsTexting;

namespace SmsTextingApiExamples
{
    class Contacts
    {
        static void Main(string[] args)
        {
            var sms = new SmsTextingRestClient("demouser", "password", SmsTextingRestClient.JSON);
            System.Console.Out.WriteLine("JSON encoding.");

            var contacts = sms.GetContacts(null, null, null, "Honey Lovers", null, null, null, null);
            System.Console.Out.WriteLine("Get contacts:");
            contacts.ForEach(t => System.Console.Out.WriteLine(t));


            var contact = new Contact("2123456899", "Piglet", "P.", "[email protected]", "It is hard to be brave, when you are only a Very Small Animal.", null);
            contact = sms.CreateContact(contact);
            System.Console.Out.WriteLine("Contact create: " + contact);

            contact = sms.GetContact(contact.ID);
            System.Console.Out.WriteLine("Contact get: " + contact);

            contact.Note = "The note";
            contact.Groups.Add("Friends");
            contact.Groups.Add("Neighbors");
            contact = sms.UpdateContact(contact);
            System.Console.Out.WriteLine("Contact update: " + contact);

            sms.DeleteContact(contact.ID);
            System.Console.Out.WriteLine("Contact delete.");
            try
            {
                sms.DeleteContact(contact.ID);
            }
            catch (Exception e)
            {
                System.Console.Out.WriteLine("Get Exception after delete not existent contact: " + e.Message);
            }

        }
    }
}




Groups

When working with Groups you can perform five actions: Post (Add New Group), Put (Update/Edit A Group), Delete (Delete A Group), Get (Get Group By ID), Index (Get All Groups). The code samples below use shared libraries.

You can download them, along with the code samples here: CsharpLib.zip.

Code Samples

C# - XML
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SmsTexting;

namespace SmsTextingApiExamples
{
    class Groups
    {
        static void Main(string[] args)
        {
            var sms = new SmsTextingRestClient("demouser", "password", SmsTextingRestClient.XML);
            System.Console.Out.WriteLine("XML encoding.");

            var groups = sms.GetGroups("Name", "asc", "10", "1");
            System.Console.Out.WriteLine("Get groups:");
            groups.ForEach(t => System.Console.Out.WriteLine(t));


            var group = new Group("Tubby Bears", "A bear, however hard he tries, grows tubby without exercise");
            group = sms.CreateGroup(group);
            System.Console.Out.WriteLine("Group create: " + group);

            group = sms.GetGroup(group.ID);
            System.Console.Out.WriteLine("Group get: " + group);

            group.Note = "The note";
            group = sms.UpdateGroup(group);
            System.Console.Out.WriteLine("Group update: " + group);

            sms.DeleteGroup(group.ID);
            System.Console.Out.WriteLine("Group delete.");
            try
            {
                sms.DeleteGroup(group.ID);
            }
            catch (Exception e)
            {
                System.Console.Out.WriteLine("Get Exception after delete not existent group: " + e.Message);
            }


        }
    }
}
C# - JSON
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SmsTexting;

namespace SmsTextingApiExamples
{
    class Groups
    {
        static void Main(string[] args)
        {
            
            var sms = new SmsTextingRestClient("demouser", "password", SmsTextingRestClient.JSON);
            System.Console.Out.WriteLine("JSON encoding.");

            var groups = sms.GetGroups("Name", "asc", "10", "1");
            System.Console.Out.WriteLine("Get groups:");
            groups.ForEach(t => System.Console.Out.WriteLine(t));


            var group = new Group("Tubby Bears", "A bear, however hard he tries, grows tubby without exercise");
            group = sms.CreateGroup(group);
            System.Console.Out.WriteLine("Group create: " + group);

            group = sms.GetGroup(group.ID);
            System.Console.Out.WriteLine("Group get: " + group);

            group.Note = "The note";
            group = sms.UpdateGroup(group);
            System.Console.Out.WriteLine("Group update: " + group);

            sms.DeleteGroup(group.ID);
            System.Console.Out.WriteLine("Group delete.");
            try
            {
                sms.DeleteGroup(group.ID);
            }
            catch (Exception e)
            {
                System.Console.Out.WriteLine("Get Exception after delete not existent group: " + e.Message);
            }

        }
    }
}

Get started for free!

Sign up now