API Example-Python

Hi guys, hope you all are having wonderful time here. In my previous Article I have explained about the concepts of Request Module, if you have not been through i would recommend you to learn that first before you proceed going through API Example from our Intermediate Section of the Tutorials

Let learn here about API (application program interface), APIs are one of the most common ways technology companies integrate with each other. Application programming interface (API) is a set of routines, protocols, and tools for building software and applications.

So lets start here with simple demonstration of API Example.

Suppose i need to know some information about my Mobile Number like from where which place i have registered it, Operator name and so.

We can get the above mentioned Information using API call, here i will be using paytm API to complete my task, you must have noticed that when you have typed in your mobile number in Paytm site on Recharging your phone  the UI immediately pop’s up that Information for you.

Let’s get the same information here using Python with just few lines of code.

>>> import requests
>>> parameters = {‘number’:’819*******’}
>>> getInfo = requests.get("https://catalog.paytm.com/v1/mobile/getopcirclebyrange",params=parameters)
>>> Information = getInfo.text
>>> Information
u’{“Operator”:”Airtel","Circle":"Karnataka","product_id":2**,"postpaid":false,"source":"prefix","status":true}'

Here i am using get method to accomplish the task, it requires payload which is your mobile number and rest is the information what you get.

I hope you would have enjoyed this small session of Dealing with API, we will come with many more useful python tricks to keep you interested in Python.

So in case of any queries or question do reach us, We will help you in best possible way to keep the things going in you favour, Thank you.