percentVAT invoice

Extracting metadata and VAT rates from invoices with examples in Python and Node.

Overview

This guide covers how to extract metadata and VAT rates from 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

  • Net amount

You will extract the following VAT rate fields:

  • VAT rate percentage

  • VAT rate net

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 VAT 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 named vat-invoice with the following fields:

  • supplier_name

  • invoice_number

  • purchase_order_number

  • receiver_name

  • issue_date

  • pay_due_date

  • total_amount

  • net_amount

The document type will have a VAT rate plugin already set up for your fields.

2. Add suppliers

Typless is a tool for automation. That's why you need to fill the dataset and train it first. To automate a new supplier, you first need to add its invoices to the data set. Download an example invoice from Best Flowers Inc:

circle-check

The dataset is created by uploading an original file with the correct value for each field defined inside the document type. A key point to note regarding VAT invoices is that you must also fill out all the VAT rates listed on the document, so the engine will take these into account the next time it performs extraction.

chevron-right1 Open file as base 64 string (Lines 6-9)hashtag

Open the file and encode it as a base64 String. Make sure you are pointing to the directory with the file.

chevron-right2 Specify payload (Lines 11-72)hashtag

Specify your payload with the required fields:

  • file - base64 encoded file

  • file_name - name of the file

  • document_type_name - the name of the document type we want to add the supplier to

  • learning_fields - fields with the correct values used for training

  • vat_rates

chevron-right3 VAT rates payload property (Lines 49-71)hashtag

The vat_rates property represents all the VAT rates present on the document. A VAT rate is represented with a list of field structures with a vat_rate_percentage field and a vat_rate_net field.

chevron-right4 Specify headers (Lines 76-80)hashtag

Add all the required request headers.

chevron-right5 Send the request (Lines 82-84)hashtag

Send the request and make sure that everything went smoothly.

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 provided example, you will change some fields:

  • total_amount value was converted with number type rules from 735,33 to 735.3300

  • net_amount value was converted with number type rules from 644,14 to 644.1400

  • issue_date value was converted with date type rules from 16.06.2017 to 2017-06-16

  • pay_due_date value was converted with date type rules from 30.06.2017 to 2017-06-30

You also applied the same rules to the VAT rates on the document. VAT rates are structured as a list of lists, similarly to line items, so keep that in mind when building the data structure for training.

circle-info

Do you need more information on the VAT rate plugin? Learn more about how it works and its limitations here.

You will have one supplier added to your document type after you run the code example.

3. Execute training

circle-check

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

circle-info

Need more information about training? Read more about it here.

4. Extract data from documents

After the training is finished, you can start precisely extracting data from documents from trained suppliers. Download a new example from Best Flowers Inc:

Download it and extract the data using the code:

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

Open the file in binary mode and correctly decode it into a base64 string. Make sure that your file is in the same directory as the script.

chevron-right2 Create payload (Lines 8-11)hashtag

Create request payload with all the required parameters:

  • file

  • file_name

  • document_type_name

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

Make sure that the Content-Type is set as application/json. Fill the Authorization header with your API key.

chevron-right4 Execute the request (Line 22)hashtag

Send the request and wait for the extraction to finish.

Response:

You should successfully extract fields along with all the VAT rates present on the invoice.

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 a dataset page.

circle-check
circle-info

To send feedback, use the add-document-feedback with 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-info

Have any questions or need some help? Contact us in chat or send us an email to support@typless.com

Typless usage is simple and straightforward!

Last updated