Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Send SMS with REST Using Python

  • Last Updated : 14 Sep, 2021

In this article, we are going to see how we can send SMS with REST using Python. The requests library can be used to make REST requests using Python to send SMS. 

Approach:

  • You need to first create a REST API KEY for sending SMS using Python Script. We have used Fast2SMS for creating API KEY.
  • You can go on the website and create an account after which you can have your own API KEY.
  • Create a Python File and copy the below code, Replace “API_KEY_OF_YOURS” with your API KEY, and in the numbers parameter, enter the number on which you want to send SMS, you can enter multiple numbers.

Following are the parameters used in GET API:

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course

  • authorization –  true, Provide “YOUR_API_KEY”. Sign up for API Key
  • message – true, Message “text” to be sent
  • language – false, Default language is “english”. API will detect “unicode” messages automatically.
  • route – true, For Quick SMS use “q”
  • numbers – true, You can send multiple mobile numbers separated by commas like: “XXXXXXXX98, YYYYYYYY89”
  • flash – false, This field is optional, it will use “0” as a default value or you can set it to “1” for sending a flash message.

Below is the implementation:

Python




import requests
  
  
querystring = {
    "authorization": "API_KEY_OF_YOURS",
    "message": "This is test Message sent from \
         Python Script using REST API.",
    "language": "english",
    "route": "q",
    "numbers": "XXXXXXXX98, YYYYYYYY89"}
  
headers = {
    'cache-control': "no-cache"
}
try:
    response = requests.request("GET", url,
                                headers = headers,
                                params = querystring)
      
    print("SMS Successfully Sent")
except:
    print("Oops! Something wrong")

Output:

SMS Successfully Sent

Message sent using REST in Python




My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!