Welcome folks today in this post we will be sending sms alert message using msg91 api
in python 3. All the source code of application is given below.
Get Started
In order to get started we need to register at msg91 website
here and create a free account to actually send messages
After this you need to get the api key
for your project. Once you logged in just go to the dashboard and there you will see this image below
Here you need to click the create new
option to create a new auth key
for your project like this
Once supplied the auth key
name and the small description
then click add
And now you can see the auth key
created and you just need to copy it somewhere we will use it later
Now you need to create a app.py
file and copy paste the following code
app.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
import http.client as ht conn = ht.HTTPSConnection("api.msg91.com") headers = {# Paste your MSG91 API Key 'authkey' : "###authkey###", 'content-type': "application/json"} payload = '''{"sender": "MSGAPI", "route": "4", "country": "91", "sms": [ { "message": "Welcome Gautam, Today you have PC class", "to": [ "##mobilenumber##" ] } ] }''' # sending the connection request conn.request("POST", "/api/v2/sendsms", payload, headers) res = conn.getresponse() data = res.read() # printing the acknowledgement print(data.decode("utf-8")) |
Here in this block of code just replace auth key
with your own auth key and replace your own mobile number
where you want to send sms alert text message.
Here we are using the built in http
library to send a post
request to the msg91
api
Now if you execute this python script app.py
by executing the command as follows
python app.py
Then you will be receiving a sms alert text message
on your respective mobile number that you provided inside the application.