Using Postman to Call OCR

Use Postman as an example to help you quickly experience and understand how to call an OCR API without coding, for example, ID Card OCR.

To call an OCR API using Postman, do the following:

Step 1: Subscribing to a Service

Step 2: Configuring the Environment

Step 3: Using a Token for Authentication

Step 4: Calling the Service

Preparations

You have registered an account with HUAWEI CLOUD and completed identity authentication. Your account cannot be in arrears or frozen.

Step 1: Subscribing to a Service

  1. Log in to the HUAWEI CLOUD OCR console.

    The service is deployed in the CN North-Beijing4 region by default. Select a region based on service requirements. For details about the region where each service is deployed, see Regions and Endpoints.

  2. Select and subscribe to your desired API.

    For this example, subscribe to the ID Card OCR API.

Step 2: Configuring the Environment

  1. Download and install Postman 7.24.0.
  2. Download the Postman configuration file for OCR.

    Download link: SDK.postman_collection_v2.json

  3. Import the configuration file.
    1. Open and log in to Postman.
    2. Choose File > Import > Import File > Choose Files to import the configuration file.
      Figure 1 Importing the configuration file

      After the configuration file is imported, it is displayed in the left navigation pane.

      Figure 2 Modifying the configuration file

      This configuration file uses the CN North-Beijing4 region by default. If you select another region when subscribing to the service, replace all cn-north-4 fields in the configuration file with the actual region when performing steps 3 to 4. For details about the region where each service is deployed, see Regions and Endpoints.

Step 3: 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 navigation pane of Postman, click the get-token configuration file.
  2. Click Body. Enter the username, password, and domain name.

    Log in to the My Credential page, copy the IAM username and account name to username and domain name respectively, and enter the password.

    Figure 3 Token-based authentication
  3. Click Send to send a request, and obtain and copy the token.

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

    Figure 4 Obtaining a token

Step 4: Calling the Service

  1. In the navigation pane of Postman, click the OCR_idcard configuration file.
  2. Log in to the My Credential page, obtain the project ID of the CN North-Beijing4 region, and replace {project_id} in the URL of the configuration file with the obtained project ID.
  3. Click Headers and copy the token value to X-Auth-Token.
    Figure 5 Modifying the configuration file
  4. Click Body and enter the Base64 code of the image to image.
    Figure 6 Modifying the configuration file
  5. Click Send to send the request and obtain the API calling result.
    {
        "result": {
            "name": "xx", 
            "sex": "Gender recognized from the image",
            "ethnicity": "Ethnicity recognized from the image",
            "birth": "1990-xx-xx", 
            "address": "Address recognized from the image",
            "number": "3892011990012xxxxx"
        }
    }