Python 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

Python - XML
import pycurl, StringIO, urllib, xml.etree.ElementTree as ET

curl = pycurl.Curl()
curl.setopt(pycurl.SSL_VERIFYPEER, 1)
curl.setopt(pycurl.SSL_VERIFYHOST, 2)
curl.setopt(pycurl.CAINFO, "cacert.pem")

params = ""
params+= "User=winnie&Password=the-pooh"
params+= "&Subject=From Winnie"
params+= "&Message=I am a Bear of Very Little Brain, and long words bother me"
params+= "&PhoneNumbers[]=2123456785&PhoneNumbers[]=2123456786"
params+= "&MessageTypeID=1&StampToSend=1305582245"

curl.setopt(pycurl.POSTFIELDS, params)

curl.setopt(pycurl.URL, "https://app.clubtexting.com/sending/messages?format=xml")

contents = StringIO.StringIO()
curl.setopt(pycurl.WRITEFUNCTION, contents.write) 

curl.perform()

print contents.getvalue() + "\n==============================" #result of API call

responseCode = curl.getinfo(pycurl.HTTP_CODE);
print 'Response code: ' + str(responseCode);
isSuccesResponse = responseCode < 400;

def getText(x): return x.text

doc = ET.XML(contents.getvalue())

print 'Status: ' + doc.findtext('Status')
print 'Code: ' + doc.findtext('Code')
if (isSuccesResponse):
    print 'Message ID: ' + doc.findtext('Entry/ID')
    print 'Subject: ' + doc.findtext('Entry/Subject')
    print 'Message: ' + doc.findtext('Entry/Message')
    print 'Message Type ID: ' + doc.findtext('Entry/MessageTypeID')
    print 'Total Recipients: ' + doc.findtext('Entry/RecipientsCount')
    print 'Credits Charged: ' + doc.findtext('Entry/Credits')
    print 'Time To Send: ' + doc.findtext('Entry/StampToSend')
    print 'Phone Numbers: ' + ', '.join(map(getText, doc.findall('Entry/PhoneNumbers/PhoneNumber')))
    print 'Locally Opted Out Numbers: ' + ', '.join(map(getText, doc.findall('Entry/LocalOptOuts/PhoneNumber')))
    print 'Globally Opted Out Numbers: ' + ', '.join(map(getText, doc.findall('Entry/GlobalOptOuts/PhoneNumber')))
else:
    print 'Errors: ' + ', '.join(map(getText, doc.findall('Errors/Error')))
Python - JSON
import pycurl, StringIO, urllib, simplejson as json

curl = pycurl.Curl()
curl.setopt(pycurl.SSL_VERIFYPEER, 1)
curl.setopt(pycurl.SSL_VERIFYHOST, 2)
curl.setopt(pycurl.CAINFO, "cacert.pem")

params = ""
params+= "User=winnie&Password=the-pooh"
params+= "&Subject=From Winnie"
params+= "&Message=I am a Bear of Very Little Brain, and long words bother me"
params+= "&PhoneNumbers[]=2123456785&PhoneNumbers[]=2123456786"
params+= "&MessageTypeID=1&StampToSend=1305582245"

curl.setopt(pycurl.POSTFIELDS, params)

curl.setopt(pycurl.URL, "https://app.clubtexting.com/sending/messages?format=json")

contents = StringIO.StringIO()
curl.setopt(pycurl.WRITEFUNCTION, contents.write) 

curl.perform()

print contents.getvalue() + "\n==============================\n" #result of API call

responseCode = curl.getinfo(pycurl.HTTP_CODE);
print 'Response code: ' + str(responseCode);
isSuccesResponse = responseCode < 400;

pyobj = json.loads(contents.getvalue())

print 'Status: ' + str(pyobj['Response']['Status'])
print 'Code: ' + str(pyobj['Response']['Code'])
if (isSuccesResponse):
    print 'Message ID: ' + str(pyobj['Response']['Entry']['ID'])
    print 'Subject: ' + pyobj['Response']['Entry']['Subject']
    print 'Message: ' + pyobj['Response']['Entry']['Message']
    print 'Message Type ID: ' + str(pyobj['Response']['Entry']['MessageTypeID'])
    print 'Total Recipients: ' + str(pyobj['Response']['Entry']['RecipientsCount'])
    print 'Credits Charged: ' + str(pyobj['Response']['Entry']['Credits'])
    print 'Time To Send: ' + pyobj['Response']['Entry']['StampToSend']
    print 'Phone Numbers: ' + str(pyobj['Response']['Entry']['PhoneNumbers'])
    try:    
        print 'Locally Opted Out Numbers: ' + str(pyobj['Response']['Entry']['LocalOptOuts'])
    except KeyError:
        pyobj['Response']['Entry']['LocalOptOuts'] = ''
    try:
        print 'Globally Opted Out Numbers: ' + pyobj['Response']['Entry']['GlobalOptOuts']
    except KeyError:
        pyobj['Response']['Entry']['GlobalOptOuts'] = ''
else:
    print 'Errors: ' + str(pyobj['Response']['Errors'])




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 the shared libraries:
· SmsTextingBase.py
· SmsTextingJSON.py
· SmsTextingXML.py
You can download them, along with the code samples here: PythonLib.zip.

Code Samples - Inbox Messages

Python - XML
import SmsTextingXML as SmsTexting

sms = SmsTexting.SmsTextingXML("https://app.clubtexting.com", "demouser", "password")


try:
    print 'get_all_messages'
    messages = sms.get_all_messages(sortBy='Name', sortDir='asc', itemsPerPage=10)
    print messages
    print
    
    message_id = messages[0].id
    message_id2 = messages[1].id

    print 'move messages to folder: '
    sms.move_message_to_folder([message_id, message_id2], 77)


    message = sms.get_message_by_id(message_id2)
    print 'get_message_by_id: ' + str(message)

    print 'delete.'
    sms.delete_message(message_id)

    print 'second delete. try to get error'
    sms.delete_message(message_id)

except SmsTexting.SmsTextingError, error:
    print str(error)
Python - JSON
import SmsTextingJSON as SmsTexting

sms = SmsTexting.SmsTextingJSON("https://app.clubtexting.com", "demouser", "password")


try:
    print 'get_all_messages'
    messages = sms.get_all_messages(sortBy='Name', sortDir='asc', itemsPerPage=10)
    print messages
    print
    
    message_id = messages[0].id

    print 'move messages to folder: '
    sms.move_message_to_folder(message_id, 77)


    message = sms.get_message_by_id(message_id)
    print 'get_message_by_id: ' + str(message)

    print 'delete.'
    sms.delete_message(message_id)

    print 'second delete. try to get error'
    sms.delete_message(message_id)

except SmsTexting.SmsTextingError, error:
    print str(error)


Code Samples - Inbox Folders

Python - XML
import SmsTextingXML as SmsTexting

sms = SmsTexting.SmsTextingXML("https://app.clubtexting.com", "demouser", "password")


try:
    print 'get_all_folders'
    print sms.get_all_folders()
    print

    folder = SmsTexting.Group('Customers')
    folder = sms.create_folder(folder)
    print 'create_folder: ' + str(folder)

    folder_id = folder.id

    folder = sms.get_folder_by_id(folder_id)
    print 'get_folder_by_id: ' + str(folder)

    print 'update_folder.'
    folder.id = folder_id
    folder.name = 'Customers2'
    sms.update_folder(folder)

    folder = sms.get_folder_by_id(folder_id)
    print 'get_folder_by_id: ' + str(folder)

    print 'delete.'
    sms.delete_folder(folder_id)

    print 'second delete. try to get error'
    sms.delete_folder(folder_id)

except SmsTexting.SmsTextingError, error:
    print str(error)
Python - JSON
import SmsTextingJSON as SmsTexting

sms = SmsTexting.SmsTextingJSON("https://app.clubtexting.com", "demouser", "password")


try:
    print 'get_all_folders'
    print sms.get_all_folders()
    print

    folder = SmsTexting.Group('Customers')
    folder = sms.create_folder(folder)
    print 'create_folder: ' + str(folder)

    folder_id = folder.id

    folder = sms.get_folder_by_id(folder_id)
    print 'get_folder_by_id: ' + str(folder)

    print 'update_folder.'
    folder.id = folder_id
    folder.name = 'Customers2'
    sms.update_folder(folder)

    folder = sms.get_folder_by_id(folder_id)
    print 'get_folder_by_id: ' + str(folder)

    print 'delete.'
    sms.delete_folder(folder_id)

    print 'second delete. try to get error'
    sms.delete_folder(folder_id)

except SmsTexting.SmsTextingError, error:
    print str(error)




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

Python - XML
import pycurl, StringIO, urllib, xml.etree.ElementTree as ET

curl = pycurl.Curl()
curl.setopt(pycurl.SSL_VERIFYPEER, 1)
curl.setopt(pycurl.SSL_VERIFYHOST, 2)
curl.setopt(pycurl.CAINFO, "cacert.pem")

params = ""
params+= "User=winnie&Password=the-pooh"
params+= "&Keyword=honey"


curl.setopt(pycurl.URL, "https://app.clubtexting.com/keywords/new?format=xml&"+params)

contents = StringIO.StringIO()
curl.setopt(pycurl.WRITEFUNCTION, contents.write) 

curl.perform()

print contents.getvalue() + "\n==============================\n" #result of API call

responseCode = curl.getinfo(pycurl.HTTP_CODE);
print 'Response code: ' + str(responseCode);
isSuccesResponse = responseCode < 400;

def getText(x): return x.text
doc = ET.XML(contents.getvalue())

print 'Status: ' + doc.findtext('Status')
print 'Code: ' + doc.findtext('Code')
if (isSuccesResponse):
     print 'Keyword: ' + doc.findtext('Entry/Keyword')
     print 'Availability: ' + doc.findtext('Entry/Available')
else:
    print 'Errors: ' + ', '.join(map(getText, doc.findall('Errors/Error')))
Python - JSON
import pycurl, StringIO, urllib, simplejson as json

curl = pycurl.Curl()
curl.setopt(pycurl.SSL_VERIFYPEER, 1)
curl.setopt(pycurl.SSL_VERIFYHOST, 2)
curl.setopt(pycurl.CAINFO, "cacert.pem")

params = ""
params+= "User=winnie&Password=the-pooh"
params+= "&Keyword=honey"

curl.setopt(pycurl.URL, "https://app.clubtexting.com/keywords/new?format=json&"+params)

contents = StringIO.StringIO()
curl.setopt(pycurl.WRITEFUNCTION, contents.write) 

curl.perform()

print contents.getvalue() + "\n==============================\n" #result of API call

responseCode = curl.getinfo(pycurl.HTTP_CODE);
print 'Response code: ' + str(responseCode);
isSuccesResponse = responseCode < 400;

pyobj = json.loads(contents.getvalue())

print 'Status: ' + str(pyobj['Response']['Status'])
print 'Code: ' + str(pyobj['Response']['Code'])
if (isSuccesResponse):
    print 'Keyword: ' + str(pyobj['Response']['Entry']['Keyword'])
    print 'Availability: ' + str(pyobj['Response']['Entry']['Available'])
else:
    print 'Errors: ' + str(pyobj['Response']['Errors'])




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

Python - XML
import pycurl, StringIO, urllib, xml.etree.ElementTree as ET

curl = pycurl.Curl()
curl.setopt(pycurl.SSL_VERIFYPEER, 1)
curl.setopt(pycurl.SSL_VERIFYHOST, 2)
curl.setopt(pycurl.CAINFO, "cacert.pem")

params = ""
params+= "User=demo&Password=texting121212"
params+= "&Keyword=honey"
params+= "&Subject=From Winnie"
params+= "&Keyword=honey"
params+= "&StoredCreditCard=1111"

curl.setopt(pycurl.POSTFIELDS, params)

curl.setopt(pycurl.URL, "https://app.clubtexting.com/keywords?format=xml")

contents = StringIO.StringIO()
curl.setopt(pycurl.WRITEFUNCTION, contents.write) 

curl.perform()

print contents.getvalue() + "\n==============================\n" #result of API call

responseCode = curl.getinfo(pycurl.HTTP_CODE);
print 'Response code: ' + str(responseCode);
isSuccesResponse = responseCode < 400;

def getText(x): return x.text
doc = ET.XML(contents.getvalue())

print 'Status: ' + doc.findtext('Status')
print 'Code: ' + doc.findtext('Code')
if (isSuccesResponse):
     print 'Keyword ID: ' + doc.findtext('Entry/ID')
     print 'Keyword: ' + doc.findtext('Entry/Keyword')
     print 'Is double opt-in enabled: ' + doc.findtext('Entry/EnableDoubleOptIn')
     print 'Confirm message: ' + doc.findtext('Entry/ConfirmMessage')
     print 'Join message: ' + doc.findtext('Entry/JoinMessage')
     print 'Forward email: ' + doc.findtext('Entry/ForwardEmail')
     print 'Forward url: ' + doc.findtext('Entry/ForwardUrl')
     print 'Groups: ' + ', '.join(map(getText, doc.findall('Entry/ContactGroupIDs/Group')))
else:
    print 'Errors: ' + ', '.join(map(getText, doc.findall('Errors/Error')))
Python - JSON
import pycurl, StringIO, urllib, simplejson as json

curl = pycurl.Curl()
curl.setopt(pycurl.SSL_VERIFYPEER, 1)
curl.setopt(pycurl.SSL_VERIFYHOST, 2)
curl.setopt(pycurl.CAINFO, "cacert.pem")

params = ""
params+= "User=demo&Password=texting121212"
params+= "&Keyword=honey"
params+= "&Subject=From Winnie"
params+= "&Keyword=honey"
params+= "&StoredCreditCard=1111"

curl.setopt(pycurl.POSTFIELDS, params)

curl.setopt(pycurl.URL, "https://app.clubtexting.com/keywords?format=json")

contents = StringIO.StringIO()
curl.setopt(pycurl.WRITEFUNCTION, contents.write) 

curl.perform()

print contents.getvalue() + "\n==============================\n" #result of API call

responseCode = curl.getinfo(pycurl.HTTP_CODE);
print 'Response code: ' + str(responseCode);
isSuccesResponse = responseCode < 400;

pyobj = json.loads(contents.getvalue())

print 'Status: ' + str(pyobj['Response']['Status'])
print 'Code: ' + str(pyobj['Response']['Code'])
if (isSuccesResponse):
    print 'Keyword ID: ' + str(pyobj['Response']['Entry']['ID'])
    print 'Keyword: ' + str(pyobj['Response']['Entry']['Keyword'])
    print 'Is double opt-in enabled: ' + str(pyobj['Response']['Entry']['EnableDoubleOptIn'])
    print 'Confirm message: ' + str(pyobj['Response']['Entry']['ConfirmMessage'])
    print 'Join message: ' + str(pyobj['Response']['Entry']['JoinMessage'])
    print 'Forward email: ' + str(pyobj['Response']['Entry']['ForwardEmail'])
    print 'Forward url: ' + str(pyobj['Response']['Entry']['ForwardUrl'])
    print 'Groups: ' + str(pyobj['Response']['Entry']['ContactGroupIDs'])
else:
    print 'Errors: ' + str(pyobj['Response']['Errors'])

Code Samples - Non-Stored Card

Python - XML
import pycurl, StringIO, urllib, xml.etree.ElementTree as ET

curl = pycurl.Curl()
curl.setopt(pycurl.SSL_VERIFYPEER, 1)
curl.setopt(pycurl.SSL_VERIFYHOST, 2)
curl.setopt(pycurl.CAINFO, "cacert.pem")

params = ""
params+= "User=winnie&Password=the-pooh"
params+= "&Keyword=honey"
params+= "&Subject=From Winnie"
params+= "&Keyword=honey"
params+= "&FirstName=Winnie"
params+= "&LastName=The Pooh"
params+= "&Street=Hollow tree, under the name of Mr. Sanders"
params+= "&City=Hundred Acre Woods"
params+= "&State=New York"
params+= "&Zip=12345"
params+= "&Country=US"
params+= "&CreditCardTypeID=Visa"
params+= "&Number=4111111111111111"
params+= "&SecurityCode=123"
params+= "&ExpirationMonth=10"
params+= "&ExpirationYear=2017"

curl.setopt(pycurl.POSTFIELDS, params)

curl.setopt(pycurl.URL, "https://app.clubtexting.com/keywords?format=xml")

contents = StringIO.StringIO()
curl.setopt(pycurl.WRITEFUNCTION, contents.write) 

curl.perform()

print contents.getvalue() + "\n==============================\n" #result of API call

responseCode = curl.getinfo(pycurl.HTTP_CODE);
print 'Response code: ' + str(responseCode);
isSuccesResponse = responseCode < 400;

def getText(x): return x.text
doc = ET.XML(contents.getvalue())

print 'Status: ' + doc.findtext('Status')
print 'Code: ' + doc.findtext('Code')
if (isSuccesResponse):
     print 'Keyword ID: ' + doc.findtext('Entry/ID')
     print 'Keyword: ' + doc.findtext('Entry/Keyword')
     print 'Is double opt-in enabled: ' + doc.findtext('Entry/EnableDoubleOptIn')
     print 'Confirm message: ' + doc.findtext('Entry/ConfirmMessage')
     print 'Join message: ' + doc.findtext('Entry/JoinMessage')
     print 'Forward email: ' + doc.findtext('Entry/ForwardEmail')
     print 'Forward url: ' + doc.findtext('Entry/ForwardUrl')
     print 'Groups: ' + ', '.join(map(getText, doc.findall('Entry/ContactGroupIDs/Group')))
else:
    print 'Errors: ' + ', '.join(map(getText, doc.findall('Errors/Error')))
Python - JSON
import pycurl, StringIO, urllib, simplejson as json

curl = pycurl.Curl()
curl.setopt(pycurl.SSL_VERIFYPEER, 1)
curl.setopt(pycurl.SSL_VERIFYHOST, 2)
curl.setopt(pycurl.CAINFO, "cacert.pem")

params = ""
params+= "User=winnie&Password=the-pooh"
params+= "quot;&Keyword=honey"
params+= "&Subject=From Winnie"
params+= "&Keyword=honey"
params+= "&FirstName=Winnie"
params+= "&LastName=The Pooh"
params+= "&Street=Hollow tree, under the name of Mr. Sanders"
params+= "&City=Hundred Acre Woods"
params+= "&State=New York"
params+= "&Zip=12345"
params+= "&Country=US"
params+= "&CreditCardTypeID=Visa"
params+= "&Number=4111111111111111"
params+= "&SecurityCode=123"
params+= "&ExpirationMonth=10"
params+= "&ExpirationYear=2017"

curl.setopt(pycurl.POSTFIELDS, params)

curl.setopt(pycurl.URL, "https://app.clubtexting.com/keywords?format=json")

contents = StringIO.StringIO()
curl.setopt(pycurl.WRITEFUNCTION, contents.write) 

curl.perform()

print contents.getvalue() + "\n==============================\n" #result of API call

responseCode = curl.getinfo(pycurl.HTTP_CODE);
print 'Response code: ' + str(responseCode);
isSuccesResponse = responseCode < 400;

pyobj = json.loads(contents.getvalue())

print 'Status: ' + str(pyobj['Response']['Status'])
print 'Code: ' + str(pyobj['Response']['Code'])
if (isSuccesResponse):
    print 'Keyword ID: ' + str(pyobj['Response']['Entry']['ID'])
    print 'Keyword: ' + str(pyobj['Response']['Entry']['Keyword'])
    print 'Is double opt-in enabled: ' + str(pyobj['Response']['Entry']['EnableDoubleOptIn'])
    print 'Confirm message: ' + str(pyobj['Response']['Entry']['ConfirmMessage'])
    print 'Join message: ' + str(pyobj['Response']['Entry']['JoinMessage'])
    print 'Forward email: ' + str(pyobj['Response']['Entry']['ForwardEmail'])
    print 'Forward url: ' + str(pyobj['Response']['Entry']['ForwardUrl'])
    print 'Groups: ' + str(pyobj['Response']['Entry']['ContactGroupIDs'])
else:
    print 'Errors: ' + str(pyobj['Response']['Errors'])




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

Python - XML
import pycurl, StringIO, urllib, xml.etree.ElementTree as ET

curl = pycurl.Curl()
curl.setopt(pycurl.SSL_VERIFYPEER, 1)
curl.setopt(pycurl.SSL_VERIFYHOST, 2)
curl.setopt(pycurl.CAINFO, "cacert.pem")

params = ""
params+= "User=winnie&Password=the-pooh"
params+= "&EnableDoubleOptIn=true";
params+= "&ConfirmMessage=Reply Y to join our sweetest list";
params+= "&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.";
params+= "&[email protected]";
params+= "&ForwardUrl=http://bear-alliance.co.uk/honey-donations/";
params+= "&ContactGroupIDs[]=honey";
params+= "&ContactGroupIDs[]=lovers";


curl.setopt(pycurl.POSTFIELDS, params)

curl.setopt(pycurl.URL, "https://app.clubtexting.com/keywords/honey?format=xml")

contents = StringIO.StringIO()
curl.setopt(pycurl.WRITEFUNCTION, contents.write) 

curl.perform()

print contents.getvalue() + "\n==============================\n" #result of API call

responseCode = curl.getinfo(pycurl.HTTP_CODE);
print 'Response code: ' + str(responseCode);
isSuccesResponse = responseCode < 400;

def getText(x): return x.text
doc = ET.XML(contents.getvalue())

print 'Status: ' + doc.findtext('Status')
print 'Code: ' + doc.findtext('Code')
if (isSuccesResponse):
     print 'Keyword ID: ' + doc.findtext('Entry/ID')
     print 'Keyword: ' + doc.findtext('Entry/Keyword')
     print 'Is double opt-in enabled: ' + doc.findtext('Entry/EnableDoubleOptIn')
     print 'Confirm message: ' + doc.findtext('Entry/ConfirmMessage')
     print 'Join message: ' + doc.findtext('Entry/JoinMessage')
     print 'Forward email: ' + doc.findtext('Entry/ForwardEmail')
     print 'Forward url: ' + doc.findtext('Entry/ForwardUrl')
     print 'Groups: ' + ', '.join(map(getText, doc.findall('Entry/ContactGroupIDs/Group')))
else:
    print 'Errors: ' + ', '.join(map(getText, doc.findall('Errors/Error')))
Python - JSON
import pycurl, StringIO, urllib, simplejson as json

curl = pycurl.Curl()
curl.setopt(pycurl.SSL_VERIFYPEER, 1)
curl.setopt(pycurl.SSL_VERIFYHOST, 2)
curl.setopt(pycurl.CAINFO, "cacert.pem")

params = ""
params+= "User=winnie&Password=the-pooh"
params+= "&EnableDoubleOptIn=true";
params+= "&ConfirmMessage=Reply Y to join our sweetest list";
params+= "&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.";
params+= "&[email protected]";
params+= "&ForwardUrl=http://bear-alliance.co.uk/honey-donations/";
params+= "&ContactGroupIDs[]=honey";
params+= "&ContactGroupIDs[]=lovers";


curl.setopt(pycurl.POSTFIELDS, params)

curl.setopt(pycurl.URL, "https://app.clubtexting.com/keywords/honey?format=json")

contents = StringIO.StringIO()
curl.setopt(pycurl.WRITEFUNCTION, contents.write) 

curl.perform()

print contents.getvalue() + "\n==============================\n" #result of API call

responseCode = curl.getinfo(pycurl.HTTP_CODE);
print 'Response code: ' + str(responseCode);
isSuccesResponse = responseCode < 400;

pyobj = json.loads(contents.getvalue())

print 'Status: ' + str(pyobj['Response']['Status'])
print 'Code: ' + str(pyobj['Response']['Code'])
if (isSuccesResponse):
     print 'Keyword ID: ' + str(pyobj['Response']['Entry']['ID'])
     print 'Keyword: ' + str(pyobj['Response']['Entry']['Keyword'])
     print 'Is double opt-in enabled: ' + str(pyobj['Response']['Entry']['EnableDoubleOptIn'])
     print 'Confirm message: ' + str(pyobj['Response']['Entry']['ConfirmMessage'])
     print 'Join message: ' + str(pyobj['Response']['Entry']['JoinMessage'])
     print 'Forward email: ' + str(pyobj['Response']['Entry']['ForwardEmail'])
     print 'Forward url: ' + str(pyobj['Response']['Entry']['ForwardUrl'])
     print 'Groups: ' + str(pyobj['Response']['Entry']['ContactGroupIDs'])
else:
    print 'Errors: ' + str(pyobj['Response']['Errors'])




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

Python - XML
import pycurl, StringIO, urllib, xml.etree.ElementTree as ET

curl = pycurl.Curl()
curl.setopt(pycurl.SSL_VERIFYPEER, 1)
curl.setopt(pycurl.SSL_VERIFYHOST, 2)
curl.setopt(pycurl.CAINFO, "cacert.pem")

params = ""
params+= "User=winnie&Password=the-pooh"


curl.setopt(pycurl.POSTFIELDS, params)

curl.setopt(pycurl.URL, "https://app.clubtexting.com/keywords/honey?format=xml&_method=DELETE")

contents = StringIO.StringIO()
curl.setopt(pycurl.WRITEFUNCTION, contents.write) 

curl.perform()

print contents.getvalue() + "\n==============================\n" #result of API call

responseCode = curl.getinfo(pycurl.HTTP_CODE);
print 'Response code: ' + str(responseCode);
isSuccesResponse = responseCode < 400;

def getText(x): return x.text

if (not isSuccesResponse):
    doc = ET.XML(contents.getvalue())
    print 'Status: ' + doc.findtext('Status')
    print 'Code: ' + doc.findtext('Code')
    print 'Errors: ' + ', '.join(map(getText, doc.findall('Errors/Error')))
Python - JSON
import pycurl, StringIO, urllib, simplejson as json

curl = pycurl.Curl()
curl.setopt(pycurl.SSL_VERIFYPEER, 1)
curl.setopt(pycurl.SSL_VERIFYHOST, 2)
curl.setopt(pycurl.CAINFO, "cacert.pem")

params = ""
params+= "User=winnie&Password=the-pooh"


curl.setopt(pycurl.POSTFIELDS, params)

curl.setopt(pycurl.URL, "https://app.clubtexting.com/keywords/honey?format=json&_method=DELETE")

contents = StringIO.StringIO()
curl.setopt(pycurl.WRITEFUNCTION, contents.write) 

curl.perform()

print contents.getvalue() + "\n==============================\n" #result of API call

responseCode = curl.getinfo(pycurl.HTTP_CODE);
print 'Response code: ' + str(responseCode);
isSuccesResponse = responseCode < 400;

if (not isSuccesResponse):
    pyobj = json.loads(contents.getvalue())
    print 'Status: ' + str(pyobj['Response']['Status'])
    print 'Code: ' + str(pyobj['Response']['Code'])
    print 'Errors: ' + str(pyobj['Response']['Errors'])




Check Credit Balance

Checks credit balances on your account.

Code Samples

Python - XML
import pycurl, StringIO, urllib, xml.etree.ElementTree as ET

curl = pycurl.Curl()
curl.setopt(pycurl.SSL_VERIFYPEER, 1)
curl.setopt(pycurl.SSL_VERIFYHOST, 2)
curl.setopt(pycurl.CAINFO, "cacert.pem")

params = "User=winnie&Password=the-pooh"

curl.setopt(pycurl.URL, "https://app.clubtexting.com/billing/credits/get?format=xml&"+params)

contents = StringIO.StringIO()
curl.setopt(pycurl.WRITEFUNCTION, contents.write) 

curl.perform()

print contents.getvalue() + "\n==============================" #result of API call

responseCode = curl.getinfo(pycurl.HTTP_CODE);
print 'Response code: ' + str(responseCode);
isSuccesResponse = responseCode < 400;

def getText(x): return x.text
doc = ET.XML(contents.getvalue())

print 'Status: ' + doc.findtext('Status')
print 'Code: ' + doc.findtext('Code')
if (isSuccesResponse):
    print 'Plan credits: ' + doc.findtext('Entry/PlanCredits')
    print 'Anytime credits: ' + doc.findtext('Entry/AnytimeCredits')
    print 'Total: ' + doc.findtext('Entry/TotalCredits')
else:
    print 'Errors: ' + ', '.join(map(getText, doc.findall('Errors/Error')))
Python - JSON
import pycurl, StringIO, urllib, simplejson as json

curl = pycurl.Curl()
curl.setopt(pycurl.SSL_VERIFYPEER, 1)
curl.setopt(pycurl.SSL_VERIFYHOST, 2)
curl.setopt(pycurl.CAINFO, "cacert.pem")

params = ""
params+= "User=winnie&Password=the-pooh"

curl.setopt(pycurl.URL, "https://app.clubtexting.com/billing/credits/get?format=json&"+params)

contents = StringIO.StringIO()
curl.setopt(pycurl.WRITEFUNCTION, contents.write) 

curl.perform()

print contents.getvalue() + "\n==============================\n" #result of API call

responseCode = curl.getinfo(pycurl.HTTP_CODE);
print 'Response code: ' + str(responseCode);
isSuccesResponse = responseCode < 400;

pyobj = json.loads(contents.getvalue())

print 'Status: ' + str(pyobj['Response']['Status'])
print 'Code: ' + str(pyobj['Response']['Code'])
if (isSuccesResponse):
    print 'Plan credits: ' + str(pyobj['Response']['Entry']['PlanCredits'])
    print 'Anytime credits: ' + str(pyobj['Response']['Entry']['AnytimeCredits'])
    print 'Total: ' + str(pyobj['Response']['Entry']['TotalCredits'])
else:
    print 'Errors: ' + str(pyobj['Response']['Errors'])




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

Python - XML
import pycurl, StringIO, urllib, xml.etree.ElementTree as ET

curl = pycurl.Curl()
curl.setopt(pycurl.SSL_VERIFYPEER, 1)
curl.setopt(pycurl.SSL_VERIFYHOST, 2)
curl.setopt(pycurl.CAINFO, "cacert.pem")

params = ""
params+= "User=demo&Password=texting121212"
params+= "&NumberOfCredits=1000"
params+= "&CouponCode=honey2011"
params+= "&StoredCreditCard=1111"


curl.setopt(pycurl.POSTFIELDS, params)

curl.setopt(pycurl.URL, "https://app.clubtexting.com/billing/credits?format=xml")

contents = StringIO.StringIO()
curl.setopt(pycurl.WRITEFUNCTION, contents.write) 

curl.perform()

print contents.getvalue() + "\n==============================" #result of API call

responseCode = curl.getinfo(pycurl.HTTP_CODE);
print 'Response code: ' + str(responseCode);
isSuccesResponse = responseCode < 400;

def getText(x): return x.text
doc = ET.XML(contents.getvalue())

print 'Status: ' + doc.findtext('Status')
print 'Code: ' + doc.findtext('Code')
if (isSuccesResponse):
    print 'Credits purchased: ' + doc.findtext('Entry/BoughtCredits')
    print 'Amount charged, $: ' + doc.findtext('Entry/Amount')
    print 'Discount, $: ' + doc.findtext('Entry/Discount')
    print 'Plan credits: ' + doc.findtext('Entry/PlanCredits')
    print 'Anytime credits: ' + doc.findtext('Entry/AnytimeCredits')
    print 'Total: ' + doc.findtext('Entry/TotalCredits')
else:
    print 'Errors: ' + ', '.join(map(getText, doc.findall('Errors/Error')))
Python - JSON
import pycurl, StringIO, urllib, simplejson as json

curl = pycurl.Curl()
curl.setopt(pycurl.SSL_VERIFYPEER, 1)
curl.setopt(pycurl.SSL_VERIFYHOST, 2)
curl.setopt(pycurl.CAINFO, "cacert.pem")

params = ""
params+= "User=demo&Password=texting121212"
params+= "&NumberOfCredits=1000"
params+= "&CouponCode=honey2011"
params+= "&StoredCreditCard=1111"


curl.setopt(pycurl.POSTFIELDS, params)

curl.setopt(pycurl.URL, "https://app.clubtexting.com/billing/credits?format=json")

contents = StringIO.StringIO()
curl.setopt(pycurl.WRITEFUNCTION, contents.write) 

curl.perform()

print contents.getvalue() + "\n==============================\n" #result of API call

responseCode = curl.getinfo(pycurl.HTTP_CODE);
print 'Response code: ' + str(responseCode);
isSuccesResponse = responseCode < 400;

pyobj = json.loads(contents.getvalue())

print 'Status: ' + str(pyobj['Response']['Status'])
print 'Code: ' + str(pyobj['Response']['Code'])
if (isSuccesResponse):
    print 'Credits purchased: ' + str(pyobj['Response']['Entry']['BoughtCredits'])
    print 'Amount charged, $: ' + str(pyobj['Response']['Entry']['Amount'])
    print 'Discount, $: ' + str(pyobj['Response']['Entry']['Discount'])
    print 'Plan credits: ' + str(pyobj['Response']['Entry']['PlanCredits'])
    print 'Anytime credits: ' + str(pyobj['Response']['Entry']['AnytimeCredits'])
    print 'Total: ' + str(pyobj['Response']['Entry']['TotalCredits'])
else:
    print 'Errors: ' + str(pyobj['Response']['Errors'])

Code Samples - Non-Stored Card

Python - XML
import pycurl, StringIO, urllib, xml.etree.ElementTree as ET

curl = pycurl.Curl()
curl.setopt(pycurl.SSL_VERIFYPEER, 1)
curl.setopt(pycurl.SSL_VERIFYHOST, 2)
curl.setopt(pycurl.CAINFO, "cacert.pem")

params = ""
params+= "User=winnie&Password=the-pooh"
params+= "&NumberOfCredits=1000"
params+= "&CouponCode=honey2011"
params+= "&FirstName=Winnie"
params+= "&LastName=The Pooh"
params+= "&Street=Hollow tree, under the name of Mr. Sanders"
params+= "&City=Hundred Acre Woods"
params+= "&State=New York"
params+= "&Zip=12345"
params+= "&Country=US"
params+= "&CreditCardTypeID=Visa"
params+= "&Number=4111111111111111"
params+= "&SecurityCode=123"
params+= "&ExpirationMonth=10"
params+= "&ExpirationYear=2017"


curl.setopt(pycurl.POSTFIELDS, params)

curl.setopt(pycurl.URL, "https://app.clubtexting.com/billing/credits?format=xml")

contents = StringIO.StringIO()
curl.setopt(pycurl.WRITEFUNCTION, contents.write) 

curl.perform()

print contents.getvalue() + "\n==============================" #result of API call

responseCode = curl.getinfo(pycurl.HTTP_CODE);
print 'Response code: ' + str(responseCode);
isSuccesResponse = responseCode < 400;

def getText(x): return x.text
doc = ET.XML(contents.getvalue())

print 'Status: ' + doc.findtext('Status')
print 'Code: ' + doc.findtext('Code')
if (isSuccesResponse):
    print 'Credits purchased: ' + doc.findtext('Entry/BoughtCredits')
    print 'Amount charged, $: ' + doc.findtext('Entry/Amount')
    print 'Discount, $: ' + doc.findtext('Entry/Discount')
    print 'Plan credits: ' + doc.findtext('Entry/PlanCredits')
    print 'Anytime credits: ' + doc.findtext('Entry/AnytimeCredits')
    print 'Total: ' + doc.findtext('Entry/TotalCredits')
else:
    print 'Errors: ' + ', '.join(map(getText, doc.findall('Errors/Error')))
Python - JSON
import pycurl, StringIO, urllib, simplejson as json

curl = pycurl.Curl()
curl.setopt(pycurl.SSL_VERIFYPEER, 1)
curl.setopt(pycurl.SSL_VERIFYHOST, 2)
curl.setopt(pycurl.CAINFO, "cacert.pem")

params = ""
params+= "User=winnie&Password=the-pooh"
params+= "&NumberOfCredits=1000"
params+= "&CouponCode=honey2011"
params+= "&FirstName=Winnie"
params+= "&LastName=The Pooh"
params+= "&Street=Hollow tree, under the name of Mr. Sanders"
params+= "&City=Hundred Acre Woods"
params+= "&State=New York"
params+= "&Zip=12345"
params+= "&Country=US"
params+= "&CreditCardTypeID=Visa"
params+= "&Number=4111111111111111"
params+= "&SecurityCode=123"
params+= "&ExpirationMonth=10"
params+= "&ExpirationYear=2017"


curl.setopt(pycurl.POSTFIELDS, params)

curl.setopt(pycurl.URL, "https://app.clubtexting.com/billing/credits?format=json")

contents = StringIO.StringIO()
curl.setopt(pycurl.WRITEFUNCTION, contents.write) 

curl.perform()

print contents.getvalue() + "\n==============================\n" #result of API call

responseCode = curl.getinfo(pycurl.HTTP_CODE);
print 'Response code: ' + str(responseCode);
isSuccesResponse = responseCode < 400;

pyobj = json.loads(contents.getvalue())

print 'Status: ' + str(pyobj['Response']['Status'])
print 'Code: ' + str(pyobj['Response']['Code'])
if (isSuccesResponse):
    print 'Credits purchased: ' + str(pyobj['Response']['Entry']['BoughtCredits'])
    print 'Amount charged, $: ' + str(pyobj['Response']['Entry']['Amount'])
    print 'Discount, $: ' + str(pyobj['Response']['Entry']['Discount'])
    print 'Plan credits: ' + str(pyobj['Response']['Entry']['PlanCredits'])
    print 'Anytime credits: ' + str(pyobj['Response']['Entry']['AnytimeCredits'])
    print 'Total: ' + str(pyobj['Response']['Entry']['TotalCredits'])
else:
    print 'Errors: ' + str(pyobj['Response']['Errors'])




Carrier Lookup

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

Code Samples

Python - XML
import pycurl, StringIO, urllib, xml.etree.ElementTree as ET

curl = pycurl.Curl()
curl.setopt(pycurl.SSL_VERIFYPEER, 1)
curl.setopt(pycurl.SSL_VERIFYHOST, 2)
curl.setopt(pycurl.CAINFO, "cacert.pem")

params = ""
params+= "User=winnielkup&Password=winnielkup"

curl.setopt(pycurl.URL, "https://app.clubtexting.com/sending/phone-numbers/2345678910?format=xml&"+params)

contents = StringIO.StringIO()
curl.setopt(pycurl.WRITEFUNCTION, contents.write) 

curl.perform()

print contents.getvalue() + "\n==============================" #result of API call

responseCode = curl.getinfo(pycurl.HTTP_CODE);
print 'Response code: ' + str(responseCode);
isSuccesResponse = responseCode < 400;

def getText(x): return x.text
doc = ET.XML(contents.getvalue())

print 'Status: ' + doc.findtext('Status')
print 'Code: ' + doc.findtext('Code')
if (isSuccesResponse):
    print 'Phone number: ' + doc.findtext('Entry/PhoneNumber')
    print 'CarrierName: ' + doc.findtext('Entry/CarrierName')
else:
    print 'Errors: ' + ', '.join(map(getText, doc.findall('Errors/Error')))
Python - JSON
import pycurl, StringIO, urllib, simplejson as json

curl = pycurl.Curl()
curl.setopt(pycurl.SSL_VERIFYPEER, 1)
curl.setopt(pycurl.SSL_VERIFYHOST, 2)
curl.setopt(pycurl.CAINFO, "cacert.pem")

params = ""
params+= "User=winnielkup&Password=winnielkup"

curl.setopt(pycurl.URL, "https://app.clubtexting.com/sending/phone-numbers/2345678910?format=json&"+params)

contents = StringIO.StringIO()
curl.setopt(pycurl.WRITEFUNCTION, contents.write) 

curl.perform()

print contents.getvalue() + "\n==============================\n" #result of API call

responseCode = curl.getinfo(pycurl.HTTP_CODE);
print 'Response code: ' + str(responseCode);
isSuccesResponse = responseCode < 400;

pyobj = json.loads(contents.getvalue())

print 'Status: ' + str(pyobj['Response']['Status'])
print 'Code: ' + str(pyobj['Response']['Code'])
if (isSuccesResponse):
    print 'Phone number: ' + str(pyobj['Response']['Entry']['PhoneNumber'])
    print 'CarrierName: ' + pyobj['Response']['Entry']['CarrierName']
else:
    print 'Errors: ' + str(pyobj['Response']['Errors'])




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:
· SmsTextingBase.py
· SmsTextingJSON.py
· SmsTextingXML.py
You can download them, along with the code samples here: PythonLib.zip.

Code Samples

Python - XML
import SmsTextingXML as SmsTexting

sms = SmsTexting.SmsTextingXML("https://app.clubtexting.com", "demouser", "password")


try:
    print 'get_all_contacts'
    print sms.get_all_contacts(group='Honey Lovers')
    print

    contact = SmsTexting.Contact('2123456796', 'Piglet', 'P.', '[email protected]', 'It is hard to be brave, when you are only a Very Small Animal.')
    contact = sms.create_contact(contact)
    print 'create_contact: ' + str(contact)

    contact = sms.get_contact_by_id(contact.id)
    print 'get_contact_by_id: ' + str(contact)

    contact.groups=['Friends', 'Neighbors']
    contact = sms.update_contact(contact)
    print 'update_contact: ' + str(contact)

    print 'delete.'
    sms.delete_contact(contact.id)

    print 'second delete. try to get error'
    sms.delete_contact(contact.id)

except SmsTexting.SmsTextingError, error:
    print str(error)
Python - JSON
import SmsTextingJSON as SmsTexting

sms = SmsTexting.SmsTextingJSON("https://app.clubtexting.com", "demouser", "password")


try:
    print 'get_all_contacts'
    print sms.get_all_contacts(group='Honey Lovers')
    print

    contact = SmsTexting.Contact('2123456796', 'Piglet', 'P.', '[email protected]', 'It is hard to be brave, when you are only a Very Small Animal.')
    contact = sms.create_contact(contact)
    print 'create_contact: ' + str(contact)

    contact = sms.get_contact_by_id(contact.id)
    print 'get_contact_by_id: ' + str(contact)

    contact.groups=['Friends', 'Neighbors']
    contact = sms.update_contact(contact)
    print 'update_contact: ' + str(contact)

    print 'delete.'
    sms.delete_contact(contact.id)

    print 'second delete. try to get error'
    sms.delete_contact(contact.id)

except SmsTexting.SmsTextingError, error:
    print str(error)




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:
· SmsTextingBase.py
· SmsTextingJSON.py
· SmsTextingXML.py
You can download them, along with the code samples here: PythonLib.zip.

Code Samples

Python - XML
import SmsTextingXML as SmsTexting

sms = SmsTexting.SmsTextingXML("https://app.clubtexting.com", "demouser", "password")


try:
    print 'get_all_groups'
    print sms.get_all_groups(sortBy='Name', sortDir='asc', itemsPerPage=10)
    print

    group = SmsTexting.Group('Tubby Bears', 'A bear, however hard he tries, grows tubby without exercise')
    group = sms.create_group(group)
    print 'create_group: ' + str(group)

    group = sms.get_group_by_id(group.id)
    print 'get_group_by_id: ' + str(group)

    group = sms.update_group(group)
    print 'update_group: ' + str(group)

    print 'delete.'
    sms.delete_group(group.id)

    print 'second delete. try to get error'
    sms.delete_group(group.id)

except SmsTexting.SmsTextingError, error:
    print str(error)
Python - JSON
import SmsTextingJSON as SmsTexting

sms = SmsTexting.SmsTextingJSON("https://app.clubtexting.com", "demouser", "password")


try:
    print 'get_all_groups'
    print sms.get_all_groups(sortBy='Name', sortDir='asc', itemsPerPage=10)
    print

    group = SmsTexting.Group('Tubby Bears', 'A bear, however hard he tries, grows tubby without exercise')
    group = sms.create_group(group)
    print 'create_group: ' + str(group)

    group = sms.get_group_by_id(group.id)
    print 'get_group_by_id: ' + str(group)

    group = sms.update_group(group)
    print 'update_group: ' + str(group)

    print 'delete.'
    sms.delete_group(group.id)

    print 'second delete. try to get error'
    sms.delete_group(group.id)

except SmsTexting.SmsTextingError, error:
    print str(error)

Get started for free!

Sign up now