Python Code Examples

Sending SMS Messages - Code Examples:

Send A Single Message

import http.client, urllib.parse
params = urllib.parse.urlencode({'user': 'username', 'pass': 'userpassword', 'phonenumber': '2125551234', 'subject': 'test', 'message' :'test message', 'express': 1})
headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"}
conn = http.client.HTTPSConnection("app.eztexting.com")
conn.request("POST", "/api/sending", params, headers)
response = conn.getresponse()
print(response.status, response.reason)

data = response.read()
print(data)

conn.close()

Send Multiple Messages

When sending the same message to multiple recipients we recommend our REST API.

import http.client, urllib.parse

messages = [
 {'phone' : '2125551234', 'subject': 'test', 'message' :'test message'},
 {'phone' : '2127846501', 'subject': 'test2', 'message' :'test message2'},
 {'phone' : '2127846502', 'subject': 'test3', 'message' :'test message3'}
]


headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"}
conn = http.client.HTTPSConnection("app.eztexting.com")

for msg in messages:
    params = urllib.parse.urlencode({'user': 'username', 'pass': 'userpassword', 'phonenumber': msg['phone'], 'subject': msg['subject'], 'message' :msg['message'], 'express': 1})
    conn.request("POST", "/api/sending", params, headers)
    response = conn.getresponse()
    print(response.status, response.reason)

    data = response.read()
    print(data)

conn.close()

Receiving Keyword Submissions - Code Examples:

#!/usr/bin/python

import cgi

form = cgi.FieldStorage()
message = form.getvalue("Message", "")
sender = form.getvalue("PhoneNumber", "")
print("Content-type: text/html")
print()

if sender is "":
    print("The Python script is waiting for messages")
else:
    #Save incoming messages
    f = open("receivelog.txt","a")
    f.write(sender+"\n")
    f.close()

    #Return a response SMS message
    responsetext = "Thank you for the message!"
    print("{SMS:TEXT}{}{}{"+sender+"}{"+responsetext+"}")

Check Credit Balance - Code Examples:

import urllib.request, urllib.parse
params = urllib.parse.urlencode({'user': 'username', 'pass': 'userpassword'})
f = urllib.request.urlopen("https://app.eztexting.com/api/credits/check", params)
data = f.read()
print(data)

Check Keyword Availability - Code Examples:

import urllib.request, urllib.parse
params = urllib.parse.urlencode({'user': 'username', 'pass': 'userpassword', 'keyword' : 'userkeyword' })
#params = urllib.parse.urlencode({'user': 'exampleuser', 'pass': 'texting', 'keyword' : 'ez' })
f = urllib.request.urlopen("https://app.eztexting.com/api/keyword/check", params)
data = f.read()
print(data)

Buy More Credits - Code Examples:

import urllib.request, urllib.parse
params = urllib.parse.urlencode({'user': 'username', 'pass': 'userpassword', 'credits' : 5, 'firstname': 'firstname', 'lastname': 'lastname', 'address': 'address', 'city': 'newyork', 'state': 'ny', 'zip': '08902', 'country': 'usa', 'type': 'visa', 'ccnumber': 'rIhLJUiXl8M0JIcrelxH9A', 'cccode': '111', 'expm': '11', 'expy': '12'})
f = urllib.request.urlopen("https://app.eztexting.com/api/credits/buy", params)
data = f.read()
print(data)

Rent a Keyword: - Code Examples

import urllib.request, urllib.parse
params = urllib.parse.urlencode({'user': 'username', 'pass': 'userpassword', 'keyword' : 'keywordtorent', 'firstname': 'firstname', 'lastname': 'lastname', 'address': 'address', 'city': 'newyork', 'state': 'ny', 'zip': '08902', 'country': 'usa', 'type': 'visa', 'ccnumber': 'rIhLJUiXl8M0JIcrelxH9A', 'cccode': '111', 'expm': '11', 'expy': '12'})
f = urllib.request.urlopen("https://app.eztexting.com/api/keyword/rent", params)
data = f.read()
print(data)

Configure a Keyword - Code Examples:

import urllib.request, urllib.parse
params = urllib.parse.urlencode({'user': 'username', 'pass': 'userpassword', 'keyword' : 'keywordtoconfigure', 'group': 'test', 'autoreply': 'autoreply', 'url': 'http://test.com/test'})
f = urllib.request.urlopen("https://app.eztexting.com/api/keyword/setup/", params)
data = f.read()
print(data)

Voice Broadcast - Code Examples:

 

(Single Number)

import urllib.request, urllib.parse
params = urllib.parse.urlencode({'user': 'username', 'pass': 'userpassword', 'phonenumbers' : '2125551234', 'soundsource': 'http://mydomain.com/sounds/voice.wav', 'callerid': '2127847840'})
f = urllib.request.urlopen("https://app.eztexting.com/api/voicemessages/", params)
data = f.read()
print(data)

 

(An Array Of Numbers)

import urllib.request, urllib.parse
params = urllib.parse.urlencode({'user': 'username', 'pass': 'userpassword', 'phonenumbers[]' : ['phone1','phone2','phone3'], 'soundfile': '1236019718.wav', 'callerid': '2127847840'}, True)
print(params)
f = urllib.request.urlopen("https://app.eztexting.com/api/voicemessages/", params)
data = f.read()
print(data)

Receiving Inbox Message Replies - Code Examples:

#!/usr/bin/python

import cgi

form = cgi.FieldStorage()
message = form.getvalue("message", "")
sender = form.getvalue("from", "")
print("Content-type: text/html")
print()

if not (sender is ""):
    #Save incoming messages
    f = open("forwardlog.txt","a")
    f.write(sender+"\n")
    f.close()