What’s Postman
Postman is a great tool when trying to test RESTful APIs. It offers a user-friendly graphical user interface, which streamlines making HTML requests to test an APIs functionality without the hassle of writing a bunch of code. With the Postman, all you need to do is copy an API endpoint URL to the address bar, select the HTTP request method on the dropdown box to its left, list the query params in an easy-to-read table format or specify those in a JSON format, and hit send. Then, the Postman pretty prints the API response data in JSON. It’s that simple!
Because of this, it is an essential tool for the Internet of Things (IoT) projects. It is common to employ various APIs or even build one for the connection between IoT devices and web applications. For example, the pipelines for getting the status of devices and servers as well as sending messages and notifications to PCs and phones. You can use the Postman to test what data are sent to or received from the APIs.
So, let’s start to do some exercises to study how to fetch data from a public API service using the Postman. In the following sections, you will practice it with Disqus REST API, which enables you to communicate with the data stored on the Disqus comment system. If you’re new to Postman, here is a video series for you to can learn the basics about that.
[ Back to Top ]
Access Disqus REST API with Postman
Disqus is a comment system for readers to have discussions about online content, and the stack of comments on a web page is called a discussion thread. The Disqus comments can be an interesting data source for trend statistics and natural language analysis. You can build an application to consume and digest the information by getting the data from the API.
With the Postman, you can quickly test the API endpoints and your parameters and then generate the codes for your prototype app. This article contains two beginner-level exercises. The first one is to get the discussion threads of a specific Disqus forum. The second one is to try querying the thread details by a thread ID, an identifier, or a source URL, respectively.
Before that, you have to prepare the following:
- Get your Disqus API key
- Create a new workspace in Postman
- Create a new environment to store variables in Postman
Preparations
Get your Disqus API key
The Disqus API works over the HTTP protocol. It supports both server-side (secret key) methods, as well as a public-facing JavaScript API using your public key and HTTP referrer checks. If you are using the public-facing JavaScript API, you will need to send api_key
with your public API key value. To obtain your key, you have to go to register an application on this page (https://disqus.com/api/applications/).
- Click on the Register new application button.
- In the registration form, fill in the name and description of your application as well as your organization and website.
- In the Application Settings, scroll to the Authentication section to select the scope for the Disqus API access.
- Go the Settings > Domains, add the domains that will access the API for security check.
After that, you can find the API key for your registered application in its Details page.
Create new personal workspace in Postman
Open the Postman on your PC. I suggest you start with a new workspace. In this way, you can isolate your projects and prevent override variables when you are unfamiliar with Postman. You can create unlimited Personal workspaces. To create a new workspace, select the workspace dropdown menu at the top and center of Postman, and click on Create New. Enter the name, such as Disqus API, for you to identify your workspaces.
Create new environment to store API key in Postman
When you access APIs, it often includes sensitive data values, such as API keys and credentials. You can prevent accidentally share your values by making use of environments to store the values as environment variables. To use the Disqus API, create a variable called api_key
and copy your Public Key as its value.
[ Back to Top ]
Exercise 1 – Get Discussions using Disqus API endpoint
Documentation: https://disqus.com/api/docs/forums/listThreads/
The forum/listThreads
endpoint returns a list of threads within a forum sorted by the date created. It does not require authentication. Only two parameters are necessary: api_key
and forum
. Alternatively, you can use the threads/list
endpoint to query a list of threads by forum
, category
, author
, and more. Both endpoints return the data in the same structure. Use the following data to set up the request of the forum/listThreads
endpoint:
Method | GET |
URL | https://disqus.com/api/3.0/forums/listThreads.json |
api_key | {{api_key}} The Public Key stored in your environment |
forum | A Disqus shortname |
Make sure that you select the right environment to apply the environment variable. The request query should look like the screenshot below.
Response
{
"cursor": {
"prev": null,
"hasNext": true,
"next": "1591067876042540:0:0",
"hasPrev": false,
"total": null,
"id": "1591067876042540:0:0",
"more": true
},
"code": 0,
"response": [
{
"feed": "https://shortname.disqus.com/pond_race_juegalo_juegos_gratis_online/latest.rss",
"clean_title": "pond race | Juegalo - juegos gratis online",
"dislikes": 0,
"likes": 0,
"message": "",
"ratingsEnabled": false,
"isSpam": false,
"isDeleted": false,
"category": "40878",
"adsDisabled": false,
"author": "99012",
"userScore": 0,
"id": "8090350709",
"signedLink": "https://https-www-juegalo-com-co.disqus.com/",
"createdAt": "2020-06-22T21:59:23",
"hasStreaming": false,
"raw_message": "",
"isClosed": false,
"link": "https://https-www-juegalo-com-co.disqus.com/",
"slug": "pond_race_juegalo_juegos_gratis_online",
"forum": "shortname",
"identifiers": [],
"posts": 0,
"userSubscription": false,
"validateAllPosts": false,
"title": "pond race | Juegalo - juegos gratis online",
"highlightedPost": null
}
]
}
The JSON-formatted data above is an example response of the forum/listThreads
endpoint. It contains only one thread, since the parameter limit=1
was added to restrict the number of results. To load more results, you can copy the value of cursor.next
from the response and carry out pagination with cursor in the query parameters.
[ Back to Top ]
Exercise 2 – Get Disqus Thread Details
Documentation: https://disqus.com/api/docs/threads/details/
The threads/details
endpoint returns the information of a single thread. It provides three ways to look up a thread:
Looks up a thread by ID
Method | GET |
URL | https://disqus.com/api/3.0/forums/listThreads.json |
api_key |
|
thread | A Disqus Thread ID |
Looks up a thread by identifier and Disqus shortname
Method | GET |
URL | https://disqus.com/api/3.0/forums/listThreads.json |
api_key |
|
thread:ident | A Disqus Identifier |
forum | A Disqus Shortname |
Looks up a thread by link and Disqus shortname
Method | GET |
URL | https://disqus.com/api/3.0/forums/listThreads.json |
api_key | {{api_key}} The Public Key stored in your environment |
thread:link | Source URL |
forum | A Disqus Shortname |
Response
{
"code": 0,
"response": {
"feed": "https://shortname.disqus.com/pond_race_juegalo_juegos_gratis_online/latest.rss",
"canModerate": false,
"clean_title": "pond race | Juegalo - juegos gratis online",
"dislikes": 0,
"likes": 0,
"message": "",
"ratingsEnabled": false,
"isSpam": false,
"isDeleted": false,
"category": "40878",
"adsDisabled": false,
"author": "99012",
"userScore": 0,
"id": "8090350709",
"signedLink": "https://https-www-juegalo-com-co.disqus.com/",
"createdAt": "2020-06-22T21:59:23",
"hasStreaming": false,
"raw_message": "",
"isClosed": false,
"link": "https://https-www-juegalo-com-co.disqus.com/",
"slug": "pond_race_juegalo_juegos_gratis_online",
"forum": "shortname",
"identifiers": [],
"posts": 0,
"userSubscription": false,
"validateAllPosts": false,
"title": "pond race | Juegalo - juegos gratis online",
"canPost": true,
"highlightedPost": null
}
}
[ Back to Top ]
Generate Python requests code snippet using Postman
You can apply the request to other platforms by generating code snippets using Postman. After testing the API request, click on “Code” below the Send and Save buttons. A dialog will show up for you to select programming languages and preview the generated code. The following screenshot is an example code snippet for Python.
To test the Python code, you can open a Jupyter notebook on Google Colab. Copy the code to the notebook and run by pressing Ctrl + Enter. It should return the same API response as in Postman.
Find out more
- Disqus API Documentation (https://disqus.com/api/docs/)
- Common Disqus API Recipes (https://github.com/disqus/DISQUS-API-Recipes)
- Postman: The Complete Guide – REST API Testing | Udemy
- Postman Crash Course for Beginners – Learn API Testing | Udemy
Note: This post includes affiliate links for which I may make a small commission at no extra cost to you when you make a purchase.
Wrap up
Based on this case study, you should understand how to access public data from the Disqus REST API using Postman. First, start with register an application on Disqus to get your API keys. Second, create a workspace and environment in Postman for the project. Third, build and send a GET request with the Postman GUI (such as enter an endpoint URL and query params according to the Disqus API Documentation). You can apply this know-how to hot topic detection and tracking.
Keep on reading:
- Postman: Disqus API Case Study (2) – OAuth 2.0 Authentication
- Postman: Disqus API Case Study (3) – Create/Update Thread
If you enjoy this post, please share it on Facebook and Twitter. You might also support us by making a donation through Ko-fi.