Help Center> Image Recognition> Getting Started> Using Postman to Call Image Recognition
Updated on 2022-03-08 GMT+08:00

Using Postman to Call Image Recognition

This section provides an example of how to use Postman to call Image Recognition, helping you quickly get familiar with the service without coding. The procedure is as follows:

Step 1: Subscribing to a Service. Subscribe to your desired service on the Service List or Service Management page.

(Optional) Step 2: Enabling OBS Authorization. To use the data stored on OBS for Image Recognition, enable OBS authorization.

Step 3: Configuring the Environment. Obtain the SDK and sample project and import them to the development environment.

Step 4: Using a Token for Authentication. During API authentication using a token, the token is added to request headers to obtain permissions for calling an API.

Step 5: Calling a Service API. Call the service API. You can view the status code and error code at any time during the usage.

Step 1: Subscribing to a Service

To subscribe to Image Recognition, perform the following steps:

  1. Log in to HUAWEI CLOUD, apply for a HUAWEI CLOUD account, and complete real-name authentication.
  2. On the top of the HUAWEI CLOUD page, choose Products > AI > Image Recognition.
  3. On the product page, click Try Now and enter the username and password to access the Image Recognition management console.
  4. Subscribe to your desired service on the Service List or Service Management page.

    For example, to subscribe to Image Tagging on the Service Management page, select Image Tagging in the Commercial services area and click Subscribe.

    • You only need to subscribe to the service once.

  5. After being subscribed to, the service is displayed in My Services on the Service Management page. In this case, you can call related APIs to use the service.

(Optional) Step 2: Enabling OBS Authorization

If you want to use the data stored on OBS, enable OBS authorization. The procedure is as follows:

  1. The region and permissions of OBS must be consistent with those of Image Recognition.
  2. OBS authorization must be performed by an account, not by an IAM user.
  1. Log in to the management console and choose Service List > Image Recognition. In the navigation pane, choose Service Management .
  2. Enable OBS Authorization.

Step 3: Configuring the Environment

  1. Download and install Postman.

    Postman 7.24.0 is recommended.

  2. Download the Postman configuration file for Image Recognition.
  3. Import the configuration file.
    1. Open and log in to Postman.
    2. Choose File > Import in the upper left corner. In the displayed dialog, click Upload Files to import the configuration file.
      Figure 1 Importing the configuration file
  4. After the configuration file is imported, it is displayed in the Collections directory in the left navigation pane.
    Figure 2 Configuration Files

Step 4: Using a Token for Authentication

A token is a user's access credential, which includes user identities and permissions. When you call an API to access a cloud service, a token is required for identity authentication.

  1. In the Collections directory in the navigation pane of Postman, click the get-token configuration file.
  2. Click Body. Enter the username, password, and domain name.

    To obtain the username, password, and domain name, perform the following steps:

    1. Log in to the management console.
    2. Hover the cursor on the username and choose My Credentials from the drop-down list. Copy the IAM username and account name to username and domainname, and enter the IAM user password.
    Figure 3 Token-based authentication
  3. Click Send to send a request, and obtain and copy the token.

    In Headers, obtain the value of X-Subject-Token, which is the token. The token is valid for 24 hours.

    Figure 4 Obtaining a token

Step 5: Calling a Service API

  1. In the Collections directory in the navigation pane of Postman, click the Image_tagging configuration file.
  2. Click Headers and copy the token value to X-Auth-Token.
    Figure 5 Entering the token
  3. Click Body and enter the Base64 code of the image to image.
    Figure 6 Modifying the parameters
  4. Click Send to send the request and obtain the API call results.
    {
        "result": {
            "tags": [
                {
                    "confidence": "94.53",
                    "i18n_tag": {
                        "en": "Animation",
                        "zh": "Enter the Chinese characters of Animation here".
                    },
                    "tag": "Animation",
                    "type": "object"
                },
                {
                    "confidence": "73.55",
                    "i18n_tag": {
                        "en": "Design",
                        "zh": "Enter the Chinese characters of Design here".
                    },
                    "tag": "Design",
                    "type": "object"
                },
                {
                    "confidence": "71.97",
                    "i18n_tag": {
                        "en": "Cartoon",
                        "zh": "Enter the Chinese characters of Cartoon here".
                    },
                    "tag": "Cartoon",
                    "type": "object"
                },
                {
                    "confidence": "63.4",
                    "i18n_tag": {
                        "en": "Art",
                        "zh": "Enter the Chinese characters of Art here".
                    },
                    "tag": "Art",
                    "type": "object"
                }
            ]
        }
    }