Skip to content

Instantly share code, notes, and snippets.

@BadgerCode
Created October 28, 2017 12:19
Show Gist options
  • Save BadgerCode/1e0ada95427b1d1d1e08f3a228b945e5 to your computer and use it in GitHub Desktop.
Save BadgerCode/1e0ada95427b1d1d1e08f3a228b945e5 to your computer and use it in GitHub Desktop.
Sends a SMS message using Esendex's REST API using Python
# Uses requests library
# http://docs.python-requests.org/en/latest/user/install/
import requests
import base64
username = "user@domain.com"
password = "password" # Sorry no API keys!
accountReference = "EX0123456" # https://www.esendex.com/echo (on the right hand side EX12345)
recipient = "447123456789" # Your number
message = "Hello world!"
authHeader = 'Basic ' + base64.b64encode(("%s:%s" % (username, password)).encode('utf-8')).decode('utf-8')
headers = { 'Authorization': authHeader }
data = {'accountreference': accountReference, 'messages': [ { "to": recipient, "body": message } ]}
r = requests.post("http://api.esendex.com/v1.0/messagedispatcher", headers=headers, json=data)
if r.status_code == 200 :
print("It worked!")
else :
print("Something went wrong")
print(r.status_code)
print(r.text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment