Guide to sending justLikeAPI requests with Python

Photo by XPS on Unsplash

 

Despite what many have expected, Python is still going strong in 2020. In fact, according to the most recent RedMonk Programming Language Rankings it’s just behind Javascript in popularity. And, considering its versatility, that’s not one bit surprising.

Experts sometimes call Python the “Swiss knife” of programming languages. Programmers use it for web development, automation of boring tasks, and data analysis. The last one is especially important when it comes to reputation management.

 

 

Here, we decided to make a guide to sending requests in justLikeAPI through Python. We already made a similar guide for sending requests with Postman. In both cases, the result is a JSON code that can be used for further analysis, writing data into Excel file, and much more.

When it comes to this guide, the requirements are:

 

  1. Having Python installed on your computer

     

  2. If you didn’t already, you can install the latest version of Python from the official website. The code in this guide should work with previous versions but its predominantly written for Python 3.8.

     

  3. Having a code editor/environment for sending requests

  4.  

    In theory, this step is not entirely necessary but makes writing and running code much easier. There are many environments available for python development to choose from. Due to simplicity, we used Visual Studio Code but you can use any editor you feel comfortable with.

 

Instructions:

 

a) Start by importing necessary modules

 

For this, we will need the following modules: requests and json. We’ll use the former for sending the actual request and the latter for working with the resulting JSON code.

 

import json
import requests

 

b) Insert the appropriate URL

 

The next step is stating the URL of a page from which we want to scrape reviews.

However, you can use any URL that you need, as long as justLikeAPI supports its website.  The code with your URL should look like this:

 

propertyUrl = "https://www.zomato.com/kochi/bloomsburys-global-kitchen-bakehouse-edappally?utm_source=api_basic_user&utm_medium=api&utm_campaign=v2.1"

 

c) Use your API key

 

The next part is important as it deals with sending your own unique API key that you got when you registered. If you didn’t you can go and start your very own 14 Day Free Trial.

After you acquire it, you can just paste it as follows:

 

auth_token='YOUR API KEY GOES HERE'

 

d) Set header:

 

Next, you can write this code:

 

header = {'Authorization': 'Bearer ' + auth_token}
data = {
   'propertyUrl': propertyUrl,
}

 

e) Get your response

 

The only thing left is to actually request your response like such:

 

url = 'https://api.justlikeapi.io/reviews/get'
response = requests.post(url, json=data, headers=header)

 

The ‘response’ variable now contains raw data. However, in order to transform it in a way that’s usable, you need to use the json module. Simply write:

 

result = response.json()

 

To see the result, write:

 

print(result)

 

At this point, the data is still raw and hard to read. The next steps in working with it depend on one’s goals. However, this should be enough to cover the basics of making justLikeAPI requests with Python. We’ll continue to write more blog posts with useful guides so don’t forget to check it out!

Leave a Comment