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
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
- 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.
- Select and subscribe to your desired API.
Step 2: Configuring the Environment
- Download and install Postman 7.24.0.
- Download the Postman configuration file for OCR.
Download link: SDK.postman_collection_v2.json
- Import the configuration file.
- Open and log in to Postman.
- 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.
- In the navigation pane of Postman, click the get-token configuration file.
- 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
- 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
- In the navigation pane of Postman, click the OCR_idcard configuration file.
- 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.
- Click Headers and copy the token value to X-Auth-Token. Figure 5 Modifying the configuration file
- Click Body and enter the Base64 code of the image to image.
- In the example, the value of side is front, indicating that the front of the ID card is recognized. For details about the API description, see API Description.
- For details about how to obtain the Base64 code of an image, see How Do I Obtain the Base64 Code of an Image?
Figure 6 Modifying the configuration file
- 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" } }
Last Article: Introduction to OCR
Next Article: Using SDK to Call OCR
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.