Document Processing - Image-to-Excel API
Call the processDocument API to convert a single image into an Excel document. The API returns the Base64 encoding of the resulting file.
API overview
API name: processDocument
Feature description: Converts an image to an Excel file when the engineType parameter is set to ScanDocConvertExcel.
Item | Description |
|
|
|
|
| Request header |
| Request header |
This feature is billed as Vertical Search, and each successful API call incurs a charge. For pricing details, see the "Vertical Search Billing Information" document.
API definition
Request parameters
Parameter | Type | Required | Default | Description | Example |
|
| Yes | None | Must be set to |
|
|
| Required if | None | The URL of a downloadable image. A public HTTPS URL is recommended. | See request example |
|
| Required if | None | The standard Base64 encoding of a single image, without the | Full image Base64 string |
Note
Response parameters
The following fields are included in a successful response. The field names are case-sensitive.
Field | Type | Return condition | Description |
|
| Always returned | The request ID. Provide this ID when contacting technical support. |
|
| Always returned | Contains the document processing time. |
|
| Always returned | The document processing time, in milliseconds. |
|
| Always returned | A fixed value of |
|
| Always returned | The Base64 encoding of the converted Excel file. |
|
| Always returned | A fixed value of |
|
| Always returned | A fixed value of |
To use the response, parse the JSON and Base64-decode the value of fileBase64 to retrieve the file's binary bytes. Save these bytes to a file named result.xlsx, as specified by the fileName field. Do not save the raw Base64 string as the file content; the correct file type is specified by the mimeType field.
Examples
The image URL in the example is a placeholder. Replace it with a valid, downloadable image URL when you call the API.
Request parameters:
{
"engineType": "ScanDocConvertExcel",
"dataUrl": "https://example.com/images/ScanDocConvertExcel.png"
}Response parameters: The following example shows the response structure. The request ID and processing time are for demonstration purposes only. [FULL_FILE_BASE64] is a placeholder representing the complete Base64-encoded file returned in an actual response; it is not a decodable value.
{
"requestId": "example-request-id",
"searchInformation": {"searchTime": 120},
"functionOption": "excel",
"fileBase64": "[FULL_FILE_BASE64]",
"fileName": "result.xlsx",
"mimeType": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
}Make an API call
To call this API, pass an authorized API Key in the X-API-Key request header. The following example reads the credential from an API_KEY environment variable. Do not embed your actual credential in front-end code or public repositories.
curl -X POST 'https://cloud-iqs.aliyuncs.com/document/process' \
--header "X-API-Key: $API_KEY" \
--header 'Content-Type: application/json' \
--data '{
"engineType": "ScanDocConvertExcel",
"dataUrl": "https://example.com/images/ScanDocConvertExcel.png"
}'To use Base64 encoding instead of dataUrl, use the dataBase64 parameter and provide the complete image encoding as described in the parameter table. Do not include both image source parameters in the same request. The request must be a POST request with a JSON body and use only the fields defined in this document.
Error codes
When handling errors, first check the HTTP status code and the response body format. A JSON response for a document processing error contains the errorCode and errorMessage fields. Optional code and message fields may also be present and have the same meaning. For 403 errors related to permissions or quotas, the presence of these fields is not guaranteed. Prioritize reading errorCode and errorMessage from the response. If they are missing, fall back to reading code and message. The requestId is not guaranteed in all error responses, and the response body may be non-JSON or empty.
Example of a parameter error (including optional mirrored fields):
{
"errorCode": "InvalidParameter",
"errorMessage": "Image too large",
"code": "InvalidParameter",
"message": "Image too large"
}HTTP status code | Error code | Description | Solution |
|
| An image source or a required parameter is missing. | Check the |
|
| A parameter is invalid or the image is too large. | Verify the casing of |
|
| The API Key is invalid. | Check the |
| As returned in the response | Insufficient permissions or available quota. | Verify that the API is enabled for your account, and check your permissions and available quota. |
| As returned in the response | Unsupported request format. The response body may be empty. | Use |
|
| Requests are too frequent. | Reduce the call frequency and implement a backoff and retry strategy. |
| As returned in the response | Failed to process the image or retrieve the result. | Check if the image is downloadable and inspect its content. If the issue persists, contact technical support and provide the request ID, if available. |
| As returned in the response | The service is temporarily unavailable. | Try again later. If the issue persists, contact technical support. |
| As returned in the response | An internal service error occurred. | Contact technical support and provide the request ID (if available) and the error message from the response body. |
Note The service may return a non-JSON response if theengineTypevalue is incorrectly cased (e.g.,scandocconvertexcelinstead ofScanDocConvertExcel) or if the JSON request body is truncated. Do not attempt to parse all error responses as JSON. Handle empty response bodies based on the HTTP status code.