receiptInvoice with line items

Extracting metadata and line items from invoices with examples in Python and Node.

Overview

This guide covers how to extract metadata and line items from multiple supplier invoices with examples in Python and Node.

You will extract the following metadata fields:

  • Name of the supplier

  • Name of the receiver

  • Invoice number

  • Purchase order number

  • Issue date

  • Pay due date

  • Total amount

You will extract the following line item fields:

  • Product number

  • Product description

  • Quantity

  • Price

This guide shows you how to

Getting your API Key

The Authorization header for your API key is: Token YOUR-API-KEY (Loginarrow-up-right if you do not see one). You can also obtain the API key by visiting the Settings pagearrow-up-right.

Getting your API key

1. Create a new document type

Before you start extracting data, you need to define a document type. Navigate to the Dashboard pagearrow-up-right and click on the New document type button in the top right corner of the table. Next, select the Line items invoice card. The wizard will already pre-fill all the needed extraction fields along with the document type configuration. Click on the Create document type.

This will create a new document type with name line-item-invoice with the following fields:

  • supplier_name

  • invoice_number

  • purchase_order_number

  • receiver_name

  • issue_date

  • pay_due_date

  • total_amount

and line items fields:

  • product_description

  • product_number

  • price

  • quantity

2. Add suppliers

Once your document type is created, you need to add data to the dataset of your document type. To do that, download the following invoices:

Each invoice is from a different supplier.

circle-check

The dataset is created by uploading an original file with the correct value for each field defined inside the document type.

Example code:

chevron-right1 Open file as base64 string (Lines 6-7)hashtag

Make sure that you are pointing to the correct path.

chevron-right2 Specify payload (Lines 9-65)hashtag

chevron-right3 Specify headers (Lines 70-74)hashtag

chevron-right4 Make POST request (Lines 76-78)hashtag

Response:

As you can see, to achieve high accuracy, Typless only needs the values that are in the document. Nevertheless, there are some rules to keep in mind when providing values.

Applying these rules to the Amazing Company example, you changed three fields:

  • total_amount value was converted with number type rules from 15,00 to 15.0000

  • issue_date value was converted with date type rules from the word Feb 1, 2021, to 2021-02-01

  • pay_due_date value was converted with date type rules from the word Mar 31, 202,1 to 2021-03-31

The same rules were also applied to the Good Services example.

You will have two suppliers added to your document type after you run both code examples.

3. Execute training

circle-check

To immediately see results, you can trigger the training process on the Dashboard pagearrow-up-right. Look for the line-item-invoice document type in the list, and click on cogs icon.

circle-info

Need more information about training? Read more about training.

4. Extract data from documents

After the training is finished, you can start precisely extracting data from documents from trained suppliers. Here you have two new invoices from the trained suppliers:

Download them and extract the data using the code:

chevron-right1 Open file as base64 string (Lines 6-7)hashtag

Make sure that you are pointing to the correct path.

chevron-right2 Specify payload (Lines 8-12)hashtag

chevron-right3 Specify headers (Lines 16-20)hashtag

chevron-right4 Make POST request (Lines 22-24)hashtag

Response:

circle-info

Need a more in-depth explanation of the response? You can read about it here.

5. Continuously improve models

Typless embraces the fact that the world is changing all the time. That's why you can improve models on the fly by providing correct data after extraction. Let's say your company has a new partner, Best Supplier. You don't need to start over with building the dataset. You can simply extract and send the correct data after they are verified by your users. You can learn more about providing feedback on the building dataset page.

circle-check
circle-info

To send feedback, use the add-document-feedback with the object_id.

Running Typless live

The only thing that you need to do to automate your manual data entry is to integrate those simple API calls into your system.

circle-check
Typless usage is very easy and straightforward!

Last updated