Use the OCR engine

Learn how to use Payabli's OCR engine via the API to recognize text and import invoices and bills
View as MarkdownOpen in Claude
Applies to:DevelopersPartners

Use Payabli’s OCR (Optical Character Recognition) engine to recognize and scrape text from bills and invoices directly from your PDF or image files, simplifying your data management. You can then use the OCR engine’s output to add new invoices and bills in Payabli via the API.

If you need help understanding the difference between invoices and bills, see this resource.

Process the document

Before you begin, note that the bill and invoice typeResult values return the information needed to create the specified kind of record in Payabli, so make sure you choose the right one. You can’t use a bill typeResult OCR output to import an invoice, and vice versa.

The first step is to choose whether you need to process an image file or a base64-encoded string version of your bill or invoice.

See the API reference for complete details about this endpoint.

1

Build the request

Make a POST request to /Import/ocrDocumentForm/{typeResult}, uploading the file. The OCR engine supports pdf, jpg, jpeg, png, and gif files.

This example is for a bill, notice that the typeResult path parameter is bill. If you want to OCR an invoice for a customer, this value should be invoice.

1curl -L 'https://api-sandbox.payabli.com/api/Import/ocrDocumentForm/bill' \
2 -H 'requestToken: <API TOKEN>' \
3 --form 'file=@"/C:/Users/accounting/Desktop/invoices/paulsPaper_invoice.pdf"'
2

Copy the response

Copy the content inside the resultData object. This content makes up the body of the add bill or add invoice request you make in the next step.

1 {
2 "isSuccess": true,
3 "responseText": "Success",
4 "responseCode": 1,
5 "responseData": {
6 "resultData": {
7 "billNumber": "6654477",
8 "netAmount": 3000.21,
9 "billDate": "2024-02-01T00:00:00",
10 "dueDate": "2024-02-01T00:00:00",
11 "comments": null,
12 "billItems": [
13 {
14 "itemTotalAmount": 3000.0,
15 "itemTaxAmount": 0,
16 "itemTaxRate": 0,
17 "itemProductCode": null,
18 "itemProductName": "Paper Airplane Stock",
19 "itemDescription": "",
20 "itemCommodityCode": null,
21 "itemUnitOfMeasure": null,
22 "itemCost": 3.0,
23 "itemQty": 1000,
24 "itemMode": null,
25 "itemCategories": []
26 }
27 ],
28 "mode": 0,
29 "accountingField1": null,
30 "accountingField2": "VBGEB-45841",
31 "additionalData": {
32 "category": "Job Supplies",
33 "currency_code": "USD",
34 "type": "invoice",
35 "reference_number": "VBGEB-45841"
36 },
37 "vendor": {
38 "vendorNumber": null,
39 "name1": "Paul\u0027s Paper Supply",
40 "name2": "Paul\u0027s Paper Supply Company",
41 "ein": null,
42 "phone": "970-222-2121",
43 "email": null,
44 "address1": "123 North 1st St",
45 "address2": null,
46 "city": null,
47 "state": null,
48 "zip": null,
49 "country": null,
50 "mcc": null,
51 "locationCode": null,
52 "contacts": null,
53 "billingData": {
54 "id": 0,
55 "bankName": "",
56 "routingAccount": "",
57 "accountNumber": "",
58 "typeAccount": "",
59 "bankAccountHolderName": "",
60 "bankAccountHolderType": "Business",
61 "bankAccountFunction": 0
62 },
63 "paymentMethod": null,
64 "vendorStatus": 1,
65 "remitAddress1": null,
66 "remitAddress2": null,
67 "remitCity": null,
68 "remitState": null,
69 "remitZip": null,
70 "remitCountry": null,
71 "payeeName1": null,
72 "payeeName2": null,
73 "customerVendorAccount": null,
74 "internalReferenceId": null,
75 "customField1": null,
76 "customField2": null,
77 "additionalData": {
78 "web": "www.paulspaper.com"
79 }
80 },
81 "endDate": null,
82 "frequency": null,
83 "terms": null,
84 "status": 0,
85 "lotNumber": null,
86 "attachments": [
87 {
88 "ftype": "pdf",
89 "filename": "paulsPaper_sample Invoice.pdf",
90 "fileDescriptor": null,
91 "furl": null,
92 "fContent": "JVBERi0xLjQKMSAwIG9iago8PCAvVHlwZSAvQ2F0YWxvZyAvUGFnZXMgMiAwIFIgPj4KZW5kb2JqCjIgMCBvYmoKPDwgL1R5cGUgL1BhZ2VzIC9LaWRzIFszIDAgUl0gL0NvdW50IDEgPj4KZW5kb2JqCjMgMCBvYmoKPDwgL1R5cGUgL1BhZ2UgL1BhcmVudCAyIDAgUiAvTWVkaWFCb3ggWzAgMCA2MTIgNzkyXQogICAvQ29udGVudHMgNCAwIFIgL1Jlc291cmNlcyA8PCAvRm9udCA8PCAvRjEgNSAwIFIgPj4gPj4gPj4KZW5kb2JqCjQgMCBvYmoKPDwgL0xlbmd0aCAzMzggPj4Kc3RyZWFtCkJUCi9GMSAxNiBUZiA1MCA3NDAgVGQgKElOVk9JQ0UpIFRqCi9GMSAxMCBUZiA1MCA3MTAgVGQgKEludm9pY2UgTm8uIDY2NTQ0NzcpIFRqCjUwIDY5NSBUZCAoRGF0ZTogMi8xLzIwMjQpIFRqCjUwIDY2NSBUZCAoRnJvbTogUGF1bCdzIFBhcGVyIFN1cHBseSkgVGoKNTAgNjUwIFRkICgxMjMgTm9ydGggMXN0IFN0LCBEdXJhbmdvLCBDTyA4MTMwMSkgVGoKNTAgNjIwIFRkIChUbzogQmlsbCBGcmFua3MpIFRqCjUwIDYwNSBUZCAoNTI1IEFuaW1hcyBWaWV3IERyaXZlLCBEdXJhbmdvLCBDTyA4MTMwMSkgVGoKNTAgNTc1IFRkIChJdGVtOiBBNCBQYXBlciB4IDEwMCkgVGoKNTAgNTYwIFRkIChBbW91bnQ6ICQyNTAuMDApIFRqCkVUCmVuZHN0cmVhbQplbmRvYmoKNSAwIG9iago8PCAvVHlwZSAvRm9udCAvU3VidHlwZSAvVHlwZTEgL0Jhc2VGb250IC9IZWx2ZXRpY2EgPj4KZW5kb2JqCnhyZWYKMCA2CjAwMDAwMDAwMDAgNjU1MzUgZiAKMDAwMDAwMDAwOSAwMDAwMCBuIAowMDAwMDAwMDU4IDAwMDAwIG4gCjAwMDAwMDAxMTUgMDAwMDAgbiAKMDAwMDAwMDI2NiAwMDAwMCBuIAowMDAwMDAwNjU2IDAwMDAwIG4gCnRyYWlsZXIKPDwgL1NpemUgNiAvUm9vdCAxIDAgUiA+PgpzdGFydHhyZWYKNzMzCiUlRU9G"
93 }
94 ]
95 },
96 "rawData": {
97 "account_number": null,
98 "bill_to": {
99 "address": "525 Animas View Drive\nDurango, CO 81301",
100 "name": "Bill Franks",
101 "vat_number": null
102 },
103 "cashback": null,
104 "category": "Job Supplies",
105 "created_date": "2024-01-31 19:57:12",
106 "currency_code": "USD",
107 "date": "2024-02-01 00:00:00",
108 "delivery_date": null,
109 "discount": null,
110 "document_reference_number": null,
111 "document_title": null,
112 "document_type": "invoice",
113 "due_date": "2024-02-01",
114 "duplicate_of": null,
115 "external_id": null,
116 "guest_count": null,
117 "id": 182145841,
118 "img_file_name": "182145841.jpg",
119 "insurance": null,
120 "invoice_number": "6654477",
121 "is_approved": null,
122 "is_duplicate": false,
123 "lat": null,
124 "line_items": [
125 {
126 "category": null,
127 "date": null,
128 "description": "Paper Airplane Stock",
129 "discount": null,
130 "discount_rate": null,
131 "end_date": null,
132 "full_description": null,
133 "hsn": null,
134 "id": 803620149,
135 "order": 0,
136 "price": 3.0,
137 "quantity": 1000.0,
138 "reference": null,
139 "section": null,
140 "sku": null,
141 "start_date": null,
142 "tags": [],
143 "tax": null,
144 "tax_rate": null,
145 "text": "1000\tPaper Airplane Stock\t\t\t3.00\t3000.00",
146 "total": 3000.0,
147 "type": "product",
148 "unit_of_measure": null,
149 "upc": null,
150 "weight": null
151 }
152 ],
153 "lng": null,
154 "notes": null,
155 "ocr_text": "2/1/2024\tInvoice No. 6654477\n\nTo\nBill Franks\n525 Animas View Drive\nDurango, CO 81301\n\nShip To\nBill Franks\n\nInstructions\nKnock three times\n\nQuantity\tDescription\t\t\tUnit Price\tTotal\n\n1000\tPaper Airplane Stock\t\t\t3.00\t3000.00\n\n\tSubtotal\n\n\tSales Tax\t\t0.21\n\tShipping \u0026 Handling\t\t0.00\n\n\tTotal Due\t\t3000.21\n\n\tDue upon receipt\n\tThank you for your business!\n\nPaul\u0027s Paper Supply Company\n\tPaul\u0027s\nTel 970-222-2121\t123 North 1st St\twww.paulspaper.com\nFax 970-222-2122\tDurango, CO 81301\tpaul@paper.com\t\tpaper",
156 "order_date": null,
157 "payment": {
158 "terms": null,
159 "card_number": null,
160 "display_name": null,
161 "type": null
162 },
163 "purchase_order_number": null,
164 "rounding": null,
165 "reference_number": "VBGEB-45841",
166 "server_name": null,
167 "service_end_date": null,
168 "service_start_date": null,
169 "ship_date": null,
170 "ship_to": {
171 "address": "Durango, CO 81301",
172 "name": "Bill Franks",
173 "vat_number": null
174 },
175 "shipping": null,
176 "status": null,
177 "store_number": null,
178 "subtotal": 3000.0,
179 "tax": 0.21,
180 "tax_lines": [],
181 "timezone_offset": null,
182 "tip": null,
183 "total": 3000.21,
184 "total_weight": null,
185 "tracking_number": null,
186 "updated_date": "2024-01-31 19:57:13",
187 "vendor": {
188 "types": null,
189 "abn_number": null,
190 "account_number": null,
191 "address": "123 North 1st St",
192 "bank_name": null,
193 "bank_number": null,
194 "bank_swift": null,
195 "category": null,
196 "email": null,
197 "external_id": null,
198 "fax_number": "970-222-2122",
199 "iban": null,
200 "name": "Paul\u0027s Paper Supply",
201 "phone_number": "970-222-2121",
202 "parsed_address": {
203 "city": null,
204 "country": null,
205 "postcode": null,
206 "state": null,
207 "street_address": "123 North 1st St"
208 },
209 "raw_name": "Paul\u0027s Paper Supply Company",
210 "reg_number": null,
211 "type": null,
212 "vat_number": null,
213 "web": "www.paulspaper.com"
214 },
215 "weights": null
216 }
217 },
218 "pageidentifier": null,
219 "roomId": 0
220 }

Create the bill or invoice

After you get the OCR results, you can use the API to create a bill or invoice in Payabli. You’ll need the contents of the resultData object returned in with the OCR response.

Follow these steps to create an invoice (money in).

See the API reference for complete details about this endpoint.

1

Build the request

Make a POST request to /Invoice/{entry}, adding the content you copied from the resultData object from the OCR response. The resultData contents is the body of the request.

Invoice payload
1 curl -L 'https://api-sandbox.payabli.com/api/Invoice/41035afaa7?forceCustomerCreation=false'
2 -H 'Content-Type: application/json' \
3 -H 'Accept: application/json' \
4 -H 'requestToken: <API TOKEN>' \
5 -d '{
6 "customerData": {
7 "customerId": 0,
8 "firstName": "Bill Franks",
9 "lastName": null,
10 "company": "",
11 "customerNumber": null,
12 "billingAddress1": null,
13 "billingAddress2": null,
14 "billingCity": null,
15 "billingState": null,
16 "billingZip": null,
17 "billingCountry": null,
18 "billingPhone": null,
19 "billingEmail": null,
20 "shippingAddress1": "Durango, CO 81301",
21 "shippingAddress2": null,
22 "shippingCity": null,
23 "shippingState": null,
24 "shippingZip": null,
25 "shippingCountry": null,
26 "additionalData": {},
27 "identifierFields": null
28 },
29 "invoiceData": {
30 "invoiceNumber": "6654477",
31 "invoiceDate": "2024-02-01 00:00:00",
32 "invoiceDueDate": "2024-02-01",
33 "invoiceEndDate": null,
34 "invoiceStatus": 0,
35 "invoiceType": 0,
36 "frequency": null,
37 "paymentTerms": "-",
38 "termsConditions": null,
39 "notes": null,
40 "tax": 0.21,
41 "discount": null,
42 "invoiceAmount": 3000.21,
43 "freightAmount": null,
44 "dutyAmount": null,
45 "purchaseOrder": null,
46 "firstName": "Bill Franks",
47 "lastName": null,
48 "company": "",
49 "shippingAddress1": "Durango, CO 81301",
50 "shippingAddress2": null,
51 "shippingCity": null,
52 "shippingState": null,
53 "shippingZip": null,
54 "shippingCountry": null,
55 "shippingEmail": null,
56 "shippingPhone": null,
57 "shippingFromZip": null,
58 "summaryCommodityCode": null,
59 "items": [
60 {
61 "itemTotalAmount": 3000.0,
62 "itemTaxAmount": 0,
63 "itemTaxRate": 0,
64 "itemProductCode": null,
65 "itemProductName": "Paper Airplane Stock",
66 "itemDescription": "",
67 "itemCommodityCode": null,
68 "itemUnitOfMeasure": null,
69 "itemCost": 3.0,
70 "itemQty": 1000,
71 "itemMode": null,
72 "itemCategories": []
73 }
74 ],
75 "attachments": [
76 {
77 "ftype": "pdf",
78 "filename": "paulsPaper_sample Invoice.pdf",
79 "fileDescriptor": null,
80 "furl": null,
81 "fContent": "JVBERi0xLjQKMSAwIG9iago8PCAvVHlwZSAvQ2F0YWxvZyAvUGFnZXMgMiAwIFIgPj4KZW5kb2JqCjIgMCBvYmoKPDwgL1R5cGUgL1BhZ2VzIC9LaWRzIFszIDAgUl0gL0NvdW50IDEgPj4KZW5kb2JqCjMgMCBvYmoKPDwgL1R5cGUgL1BhZ2UgL1BhcmVudCAyIDAgUiAvTWVkaWFCb3ggWzAgMCA2MTIgNzkyXQogICAvQ29udGVudHMgNCAwIFIgL1Jlc291cmNlcyA8PCAvRm9udCA8PCAvRjEgNSAwIFIgPj4gPj4gPj4KZW5kb2JqCjQgMCBvYmoKPDwgL0xlbmd0aCAzMzggPj4Kc3RyZWFtCkJUCi9GMSAxNiBUZiA1MCA3NDAgVGQgKElOVk9JQ0UpIFRqCi9GMSAxMCBUZiA1MCA3MTAgVGQgKEludm9pY2UgTm8uIDY2NTQ0NzcpIFRqCjUwIDY5NSBUZCAoRGF0ZTogMi8xLzIwMjQpIFRqCjUwIDY2NSBUZCAoRnJvbTogUGF1bCdzIFBhcGVyIFN1cHBseSkgVGoKNTAgNjUwIFRkICgxMjMgTm9ydGggMXN0IFN0LCBEdXJhbmdvLCBDTyA4MTMwMSkgVGoKNTAgNjIwIFRkIChUbzogQmlsbCBGcmFua3MpIFRqCjUwIDYwNSBUZCAoNTI1IEFuaW1hcyBWaWV3IERyaXZlLCBEdXJhbmdvLCBDTyA4MTMwMSkgVGoKNTAgNTc1IFRkIChJdGVtOiBBNCBQYXBlciB4IDEwMCkgVGoKNTAgNTYwIFRkIChBbW91bnQ6ICQyNTAuMDApIFRqCkVUCmVuZHN0cmVhbQplbmRvYmoKNSAwIG9iago8PCAvVHlwZSAvRm9udCAvU3VidHlwZSAvVHlwZTEgL0Jhc2VGb250IC9IZWx2ZXRpY2EgPj4KZW5kb2JqCnhyZWYKMCA2CjAwMDAwMDAwMDAgNjU1MzUgZiAKMDAwMDAwMDAwOSAwMDAwMCBuIAowMDAwMDAwMDU4IDAwMDAwIG4gCjAwMDAwMDAxMTUgMDAwMDAgbiAKMDAwMDAwMDI2NiAwMDAwMCBuIAowMDAwMDAwNjU2IDAwMDAwIG4gCnRyYWlsZXIKPDwgL1NpemUgNiAvUm9vdCAxIDAgUiA+PgpzdGFydHhyZWYKNzMzCiUlRU9G"
82 }
83 ],
84 "additionalData": {
85 "category": "Job Supplies",
86 "currency_code": "USD",
87 "type": "invoice",
88 "reference_number": "VBGIJ-80131"
89 }
90 },
91 "scheduledOptions": null
92 }
2

Read the results

If your request was successful, you’ll recieve a success response with the new invoice’s ID in responseData.

1{
2 "isSuccess": true,
3 "responseText": "Success",
4 "responseCode": 1,
5 "responseData": 816,
6 "pageidentifier": null,
7}

See these related resources to help you get the most out of Payabli.