Skip to Content

Use the Topic Detection API from a REST Client

0 %
Use the Topic Detection API from a REST Client

Use the Topic Detection API from a REST Client

Discover how to call the Topic Detection API from a REST Client like Postman

You will learn

  • Call an API from a REST client like Postman
  • The basics about Machine Learning Foundation Service for Topic Detection

Note: This service was in alpha version when this tutorial was released.

Step 1: The Topic Detection Service

The Topic Detection service detects and ranks topics from documents.

The input archive file is provided using form data (as an element named files in the form data).

Note that the archive must include at least 2 documents.

This is the list of accepted file extensions:

Name Description
Archive file zip, tar or tar.gz

A series of settings can also be provided as part of the form data (named options in the form data) using a JSON string format.

Name Description
numTopics Total number of topics to be detected
numTopicsPerDoc Number of most relevant topics to be listed per document
numKeywordsPerTopic Number of keywords to be listed per topic
numFeatures Maximum number of keywords to be extracted from documents in total

The service will return a JSON response that includes the categories predictions along with a score.

For more details, you can check the following link:

Log on to answer question
Step 2: Call the API

First, let’s build an archive with at least 3 text files (so that we can set numTopics equal to 3).

If you are missing some inspiration, use the following articles content to create your text files:

Create a zip out of these text files.

Note for MacOS users:

The built-in ZIP feature for MacOS will create an improper ZIP archive file.
You should instead use the following command to create your ZIP archive:

zip -r -X <your archive>.zip <your folder>

Open a new tab in Postman.

Make sure that the my-ml-foundation environment is selected.

On the Authorization tab, select Bearer Token, then enter {{OAuthToken}} as value.


Note:: the OAuthToken environment variable can be retrieved following the Get your OAuth Access Token using a REST Client tutorial.

Fill in the following additional information:

Field Name Value
URL the value for TOPIC_DETECTION_URL in your service key

Note As a reminder, the URL depends on you Cloud Platform landscape region but for the trial landscape only Europe (Frankfurt) provide access to the Machine Learning Foundation services.

On the Body tab, keep form-data selected.

Add a new key named files and switch it to File instead of Text (default).

Select your archive file.

Add a new key named options and switch it to Text.

Paste the following value:

{"numTopics":3, "numTopicsPerDoc":1, "numKeywordsPerTopic":5}

This will extract 3 topics, and get the top topic for each document with 5 attached keyword for the topic.


Click on Send.

You should receive a response that includes a series of entries:

    "docName": "cc.txt",
    "keywords": [
        ["cheesecake", "cheese", "cream", "style", "bake"],
        ["deep", "learning", "network", "neural", "layer" ]
    "scores": [
    "topics": [
Log on to answer question
Step 3: Validate your results

Provide an answer to the question below then click on Validate.

Paste the full response returned with the previous test.

Next Steps

Back to top