Help Center> Optical Character Recognition> Getting Started> Using Postman to Call the Passport OCR API
Updated on 2022-12-21 GMT+08:00

Using Postman to Call the Passport OCR API

Use Postman to call the Passport OCR API.

To call an OCR API, there are four steps:

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. Your account cannot be in arrears or frozen.

Step 1: Subscribing to a Service

  1. Log in to the Huawei Cloud OCR management console.

    The default region is displayed in the upper left corner. Select a region based on service requirements. For details about the region where the OCR service is available, see Regions and Endpoints.

  2. Select and subscribe to your desired API.

    For this example, subscribe to the Passport OCR API.

    • The OCR service is released on ModelArts. Error codes starting with "ModelArts" may be reported. For details about error codes, see Error Codes.
    • If the ModelArts.4204 error is reported, the service may not be subscribed to or the region where the service is subscribed to is inconsistent with the region where the service is called. Before calling the service, log in to the console and ensure the region is the same.

Step 2: Configuring the Environment

Download and install Postman 7.24.0.

Step 3: Using a Token for Authentication

  1. On the Postman page, choose New > Collection, set the name, and click Create.

  2. Right-click the created collection, choose Add Request from the shortcut menu, set Request name, and click Save.

  3. Change the request mode to POST and enter the URL.

    For example, if ap-southeast-1 is used, the URL is https://iam.ap-southeast-1.myhuaweicloud.com/v3/auth/tokens.

  4. In the Headers list, set KEY to Content-Type and VALUE to application/json.

  5. Click Body, select raw, and enter the code in the blank area, as shown below.
    Figure 1 Token-based authentication

    Replace username, domainname, ******** (login password), and project name (region where the service is deployed) with the actual values. To obtain the values of these parameters, log in to the management console and click My Credentials.

    The region where OCR is deployed must be the same as the region where the called service is located. In this example, the region is ap-southeast-1.

    {
        "auth": {
            "identity": {
                "methods": [
                    "password"
                ],
                "password": {
                    "user": {
                        "name": "username",
                        "password": "**********",
                        "domain": {
                            "name": "domainname"
                        }
                    }
                }
            },
            "scope": {
                "project": {
                    "name": "ap-southeast-1"
                }
            }
        }
    }
  6. Click Send in the upper right corner to send the request. Obtain the token value from the returned result. The token is valid for 24 hours.

Step 4: Calling the Service

  1. Create a request, set the request mode to POST, and enter the URL as required.

    For example, if Passport OCR is deployed in the CN-Hong Kong region, the request URL is https://ocr.ap-southeast-1.myhuaweicloud.com/v2/{project_id}/ocr/passport.

    Click Headers and copy the token value to X-Auth-Token.

    Log in to the My Credential page, query the ID of the project in the CN-Hong Kong region, and replace {project_id} in the URI with the queried project ID.

  2. Click Body and enter the Base64 code of the image to the request body. For details about the API description, see Passport OCR.
    {     
         "image":"/9j/4AAQSkZJRgABAgEASABIAAD/4RFZRXhpZgAATU0AKgAAAA...",
         "country_code": "GENERAL" 
    }
  3. Click Send in the upper right corner to send the request and view the results.