Set Up a Text Message API With Python in 5 Minutes.

ABHINAV SHARMA
The Startup
Published in
2 min readSep 8, 2020
Photo by Tyler Lastovich on Unsplash

Digitally connected world use automated messages in heavy way. Bills, rent, One Time Passwords there are unlimited scopes of an Automated text.

Suppose you own a mini store and a new item arrives and you want to notify 50 to 100 of your clients. How would you do?, Easy— Text them, Automatically.

Lets setup a SMS Client for quick learning, I found this website www.textlocal.in with reasonable prices in India. It is providing Bulk message options.

Create an Account, They give 10 credits, so lets get trying.

After Sign-up go to Settings >API > Generate a new API Key and save it somewhere safe. You can allow Specific IPs for security, But lets keep the fields empty for now.

Requests will go to link https://api.textlocal.in/{command} with command-name in command and data in headers.

Lets Start Coding Part

Libraries : For now Just One > “import requests”

import requests
url = ‘https://api.textlocal.in/'
params = {‘username’:’yourusername@mailid.com’,
‘apiKey’:’yourGenerated-APIKey’
}

Lets write some Functions():

def check_balance(url):
url = url+'balance'
response = requests.get(url,params=params)
return response.json()
def send_sms(url,params):
url=url+'send'
#Phone numbers inside braces {} in commas
numbers={'9911111xxxx'}
message = {'Hi, This is a Sample message'}
params['numbers'] = numbers
params['message'] = message
response = requests.post(url,params=params)
return response.json()

def inbox(url):
url = url+'get_inboxes'
response = requests.get(url,params=params)
return response.json()

Thats it, Code finished!! In 5 minutes you can setup SMS message for single or bulk messages.

In Next Part I will show you to make a quick app to send message, and OTP confirmation too.

Till then, Good Bye!!!!

Priority queue with Heap → Didn’t understand Heap? Let’s implement and know

--

--

The Startup
The Startup

Published in The Startup

Get smarter at building your thing. Follow to join The Startup’s +8 million monthly readers & +772K followers.

ABHINAV SHARMA
ABHINAV SHARMA

Written by ABHINAV SHARMA

Coder, Writer, Politics Enthusiast