Invoice
1. Extract invoice information with image URL or pdf URL input
API:
| Method | URL |
|---|---|
| GET | https://demo.computervision.com.vn/api/v2/ocr/document/invoice |
Params:
| Key | Value | Description |
|---|---|---|
img | https://example.com/image.png | URL of photo or pdf |
format_type | url | Type of data to pass in, receive value: url, file, base64 |
get_thumb | true/false | Returns a aligned image |
Demo Python:
import requestsapi_key = "YOUR_API_KEY"api_secret = "YOUR_API_SECRET"image_url = 'https://example.com/image.png'response = requests.get("https://demo.computervision.com.vn/api/v2/ocr/document/invoice?img=%s&format_type=url&get_thumb=false"% image_url,auth=(api_key, api_secret))print(response.json())
2. Extract invoice information with image file or pdf file input
API:
| Method | URL | content-type |
|---|---|---|
| POST | https://demo.computervision.com.vn/api/v2/ocr/document/invoice | multipart/form-data |
Params:
| Key | Value | Description |
|---|---|---|
format_type | file | Type of data to pass in, receive value: url, file, base64 |
get_thumb | true/false | Returns a aligned image |
Body:
| Key | Type | Value | Description |
|---|---|---|---|
img | file | example.jpg | Image file or pdf file |
Demo Python:
import requestsapi_key = "YOUR_API_KEY"api_secret = "YOUR_API_SECRET"image_path = '/path/to/your/image.jpg'response = requests.post("https://demo.computervision.com.vn/api/v2/ocr/document/invoice?format_type=file&get_thumb=false",auth=(api_key, api_secret),files={'img': open(image_path, 'rb')})print(response.json())
3. Extract invoice information with JSON input
API:
| Method | URL | content-type |
|---|---|---|
| POST | https://demo.computervision.com.vn/api/v2/ocr/document/invoice | application/json |
Params:
| Key | Value | Description |
|---|---|---|
format_type | base64 | Type of data to pass in, receive value: url, file, base64 |
get_thumb | true/false | Returns a aligned image |
Body:
{"img": "iVBORw0KGgoAAAANSU..." // string base64 of the image or pdf to extract}
Demo Python:
import base64import ioimport requestsfrom PIL import Imagedef get_byte_img(img):img_byte_arr = io.BytesIO()img.save(img_byte_arr, format='PNG')encoded_img = base64.encodebytes(img_byte_arr.getvalue()).decode('ascii')return encoded_imgapi_key = "YOUR_API_KEY"api_secret = "YOUR_API_SECRET"img_name = "path_img"encode_cmt = get_byte_img(Image.open(img_name))response = requests.post("https://demo.computervision.com.vn/api/v2/ocr/document/invoice?format_type=base64&get_thumb=false",auth=(api_key, api_secret),json={'img' : encode_cmt})print(response.json())
4. Extract invoice information with xml file input
API:
| Method | URL | content-type |
|---|---|---|
| POST | https://demo.computervision.com.vn/api/v2/ocr/document/invoice-xml | multipart/form-data |
Params:
| Key | Value | Description |
|---|---|---|
format_type | file | Type of data to pass in, receive value: url, file, base64 |
get_thumb | true/false | Returns a aligned image |
Body:
| Key | Type | Value | Description |
|---|---|---|---|
img | file | example.xml | Xml file |
Demo Python:
import requestsapi_key = "YOUR_API_KEY"api_secret = "YOUR_API_SECRET"image_path = '/path/to/your/invoice.xml'response = requests.post("https://demo.computervision.com.vn/api/v2/ocr/document/invoice-xml?format_type=file&get_thumb=false",auth=(api_key, api_secret),files={'img': open(image_path, 'rb')})print(response.json())
5. Response
The response will be a JSON with the following format:
{"data": [xxxx],"errorCode": string,"errorMessage": string}
Where the data field is a list, each element in the list corresponds to an invoice page. Each of these elements has the following format:
{"type": "invoice", // Thể hiện loại giấy tờ ở đây là hóa đơn"info": [xxxx]}
The info field will contain the following information:
account_bank: This field is a list. Each element contains the following fields:account_noaccount_no_boxaccount_no_confidencebankbank_boxbank_confidence
buyer_namebuyer_name_boxbuyer_name_confidencedatedate_boxdate_confidenceformform_boxform_confidenceimageimage_tableinvoice_noinvoice_no_boxinvoice_no_confidencelookup_codelookup_code_boxlookup_code_confidencelookup_websitelookup_website_boxlookup_website_confidencepayment_methodpayment_method_boxpayment_method_confidencepurchaser_namepurchaser_name_boxpurchaser_name_confidenceserial_noserial_no_boxserial_no_confidencesub_totalsub_total_boxsub_total_confidencesuppliersupplier_boxsupplier_confidencesupplier_addresssupplier_address_boxsupplier_address_confidencetable: This field is a list. Each element contains the following fields:valueboxscorelabel: Can be one of the following values:numberdescriptionunitquantityunit_priceamount_before_taxtaxtax_amountamount_total
tax_codetax_code_boxtax_code_confidencetotal_amounttotal_amount_boxtotal_amount_confidencevat_amountvat_amount_boxvat_amount_confidencevat_ratevat_rate_boxvat_rate_confidence
Error code table:
| Code | Message |
|---|---|
| 0 | Success |
| 1 | The photo does not contain content |
| 2 | Url is unavailable |
| 3 | Incorrect image format |
| 4 | Out of requests |
| 5 | Incorrect api_key or api_secret |
| 6 | Incorrect format type |