Calling the Passport OCR API
Use Postman to call the Passport OCR API.
To call an OCR API, there are four steps:
Step 1: Subscribe to a Service
Step 2: Configure the Environment
Step 3: Use a Token for Authentication
Preparations
You have signed up for a HUAWEI ID and enabled Huawei Cloud services. Your account cannot be in arrears or frozen.
Step 1: Subscribe to a Service
- 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.
- 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 3: Use a Token for Authentication
- On the Postman page, choose New > Collection, set the name, and click Create.
- Right-click the created collection and select Add Request from the shortcut menu. Set the request name and click Save.
- 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.
- In the Headers list, set KEY to Content-Type and VALUE to application/json.
- Click Body, select raw, and enter the code in the blank area.
Figure 1 Token-based authentication
Replace username, ******** (login password), domainname, 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 you call the service. 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" } } } }
- Click Send in the upper right corner to send the request. Obtain the token from the returned result. The token is valid for 24 hours.
Step 4: Call the Service
- Create a request, set the request mode to POST, and enter the URL as needed.
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 to X-Auth-Token.
Log in to the My Credentials 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.
- Click Body and add the Base64 code of an image to the request body. For details about the API description, see Passport OCR.
{ "image":"/9j/4AAQSkZJRgABAgEASABIAAD/4RFZRXhpZgAATU0AKgAAAA...", "country_code": "GENERAL" }
- Click Send in the upper right corner to send the request and view the results.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot