In this article, we will continue to explore the Disqus REST API with Postman. This time focuses on studying the authenticated API POST services, such as create, update, and remove a discussion thread. The following exercises will require a Disqus API access token. If you don’t know how to get the access token using OAuth 2.0, please go back to read the article Disqus API Case Study (2).
Exercise 1- Create a new Disqus thread
Documentation: https://disqus.com/api/docs/threads/create/
The threads/create
endpoint is to add a new discussion thread to a specific forum. If your website installs with Disqus code or plug-in, once Disqus detects a new post, it will automatically create a discussion thread. So, where can it be used?
I think you can make use of it to migrate comments to Disqus. You may also use it to set up off-site discussions, which aid to branch off the subtopics from their main thread.
The threads/create
endpoint requires the following parameters:
Method | POST |
URL | https://disqus.com/api/3.0/threads/create.json |
Authorization | OAuth 2.0 (Request Headers) Refer to Disqus API Case Study (2) |
api_key | {{api_key}} The Public Key stored in your environment |
forum | A Disqus Shortname |
title | The name to describe the new Disqus thread |
Make sure that you select the right environment to apply the environment variable. The request query should look like the screenshot below.
Response
{
"code": 0,
"response": {
"feed": "https://craftweeks.disqus.com/hello_world/latest.rss",
"clean_title": "Hello World",
"dislikes": 0,
"likes": 0,
"message": null,
"ratingsEnabled": false,
"isSpam": false,
"isDeleted": false,
"category": "7486595",
"adsDisabled": false,
"author": "243188002",
"media": [],
"userScore": 0,
"id": "8223786231",
"signedLink": "https://disqus.com/home/discussion/craftweeks/hello_world/",
"createdAt": "2020-10-02T06:46:21",
"hasStreaming": false,
"raw_message": null,
"isClosed": false,
"link": "https://disqus.com/home/discussion/craftweeks/hello_world/",
"slug": "hello_world",
"forum": "craftweeks",
"identifiers": [],
"posts": 0,
"userSubscription": false,
"validateAllPosts": false,
"title": "Hello World",
"highlightedPost": null
}
}
Find and note down the thread id in the JSON-formatted API response. It will be used in the requests for thread update and removal. To confirm the new Disqus discussion, open the link URL in your browser and you should visit a Disqus webpage like the screenshot below.
[ Back to Top ]
Exercise 2- Updates information on a Disqus thread
Documentation: https://disqus.com/api/docs/threads/update/
The threads/update API endpoint is one of the suggested methods to update discussion URLs by the Disqus Help Desk. It can be also employed to change a post’s title appearing in Disqus Recommendations.
For instance, we want to change the title and link of the thread created in Excercise 1. Set up the request using the data in the first five rows of the below table. Then, append the last three optional parameters to assign the new title and link URL to the specific thread.
Method | POST |
URL | https://disqus.com/api/3.0/threads/update.json |
Authorization | OAuth 2.0 (Request Headers) Refer to Disqus API Case Study (2) |
api_key | {{api_key}} The Public Key stored in your environment |
thread | A Disqus Thread ID |
title optional | e.g. Hello World!! Maximum length of 200 |
url optional | e.g. https://disqus.com/home/discussion/craftweeks/hello_world-2/ An URL (defined by RFC 3986, Maximum length of 500) |
slug optional | e.g. hello_world-2 Alpha-numeric slug (Maximum length of 200) |
Hint: To query the thread, we must know its ID. If you forget the value, please try to recall it by using the methods described in the article Disqus API case study (1).
Make sure that you select the right environment to apply the environment variable. The request query should look like the screenshot below.
Response
{
"code": 0,
"response": {
"feed": "https://craftweeks.disqus.com/hello_world-2/latest.rss",
"clean_title": "Hello World!!",
"dislikes": 0,
"likes": 0,
"message": null,
"ratingsEnabled": false,
"isSpam": false,
"isDeleted": false,
"category": "7486595",
"adsDisabled": false,
"author": "243188002",
"media": [],
"userScore": 0,
"id": "8223786231",
"signedLink": "https://disqus.com/home/discussion/craftweeks/hello_world-2/",
"createdAt": "2020-10-02T06:46:21",
"hasStreaming": false,
"raw_message": null,
"isClosed": false,
"link": "https://disqus.com/home/discussion/craftweeks/hello_world-2/",
"slug": "hello_world-2",
"forum": "craftweeks",
"identifiers": [],
"posts": 0,
"userSubscription": false,
"validateAllPosts": false,
"title": "Hello World!!",
"highlightedPost": null
}
}
Wait for a while, reload the page in your browser. Disqus will indicate the original page doesn’t exist. Enter the new URL to the address bar, you should visit the discussion page with the updated title.
[ Back to Top ]
Exercise 3 – Delete a Disqus thread
Documentation: https://disqus.com/api/docs/threads/remove/
After exploring the above API services, you may want to delete the test thread. You can now set up a request to the threads/remove
endpoint with the following parameters:
Method | POST |
URL | https://disqus.com/api/3.0/threads/remove.json |
Authorization | OAuth 2.0 (Request Headers) Refer to Disqus API Case Study (2) |
api_key | {{api_key}} The Public Key stored in your environment |
thread | A Disqus Thread ID |
Make sure that you select the right environment to apply the environment variable. The request query should look like the screenshot below.
Response
{
"code": 0,
"response": [
{
"id": "8223786231"
}
]
}
Wait for a while, reload the page in your browser. Disqus will indicate the page is no longer existing.
[ Back to Top ]
Verify your results using online Discussion Editor
The Discussions Editor allows you to 1-click update attributes of any discussion on your site. For example, you might update the title or link associated with a discussion after updating it on your site itself.
What attributes can be updated?
Currently the following discussion attributes are included for updating:
- Title: appears publicly.
- Link: appears publicly.
- Author: does not appear publicly. Update this when you want a non-moderator on your Disqus forum to be considered the author for the discussion. This allows them to moderate comments on that discussion both via Disqus notification emails and inline in the commenting embed.
- Category: does not appear publicly. Categories are primarily used with Disqus API for results filtering. Learn more about categories.
- Open/closed status: open or close a discussion to new comments.
If you enjoy this post, please share it on Facebook and Twitter. You might also support us by making a donation through Ko-fi.