Parsing Invoices with Mindee's API
Tags: invoice, ocr, machinelearning, api
Published: 2021-02-25 21:51:15

---
title: Parsing Invoices with Mindee's API
published: true
description: 
tags: invoice, ocr, machinelearning, api
cover_image: https://mindee-public-website.s3.amazonaws.com/documentation/parse_an_invoice_multiples_article.jpg
canonical_url: https://mindee.com/documentation/apis/invoice-parsing
---

<h1><span style="color:#001e3c">Parsing Invoices with Mindee&rsquo;s API</span></h1>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>Scanning and inputting data from invoices into accounting systems is a slow and tedious process.&nbsp; Using Mindee&rsquo;s invoice parsing API, all of the pertinent data can be automatically and accurately extracted from your invoice in seconds, allowing for fast and painless data entry.&nbsp;&nbsp;</p>

<p>&nbsp;</p>

<p>Interested in learning more? In this tutorial, we will walk through the steps to use Mindee&rsquo;s Invoice API.&nbsp;</p>

<p><span style="color:#001e3c">&nbsp;</span></p>

<h2><span style="color:#001e3c">API Prerequisites</span></h2>

<p><span style="color:#001e3c">&nbsp;</span></p>

<ol>
	<li style="list-style-type:decimal"><span style="color:#001e3c">You&rsquo;ll need Mindee account.<a href="http://platform.mindee.net/signup"> Sign up</a></span><span style="color:#001e3c"><a href="http://platform.mindee.net/signup">&nbsp;for free</a>.&nbsp; Then confirm your email to login.</span></li>
	<li style="list-style-type:decimal"><span style="color:#001e3c">An invoice.&nbsp; Use a recently received invoice, or do a <a href="https://www.google.com/search?q=invoice">Google Image search</a> for a invoice&nbsp;and download a few to test with</span><span style="color:#001e3c">.&nbsp;&nbsp;</span></li>
</ol>

<p>&nbsp;</p>

<h2>Setting up the API</h2>

<p>&nbsp;</p>

<p>Log into you Mindee account and access your Invoices API environment by clicking the <strong>Invoices </strong>card :</p>

<p>&nbsp;</p>

<h1><img alt="" src="https://mindee-public-website.s3.amazonaws.com/blog/2020/09/11/screenshot-2020-09-11-at-192210.png" style="height:558px; width:400px" /></h1>

<p>To activate the API, click the &ldquo;Try for Free&rdquo; button to access the free tier. You&rsquo;ll land on the dashboard page - this page will show the usage of your account with the Invoice API - of course, it is empty now.&nbsp; On the left navigation, there are links to &ldquo;Documentation&rdquo;, &ldquo;Credentials&rdquo; and &ldquo;Live Interface&rdquo;.&nbsp; The docs tab has all of the technical details you&rsquo;ll need to build for the Invoce API endpoint, and the Live Interface is a cool interactive demo. Rather than try out the demo, we want to build with the API,&nbsp; so click on &ldquo;Credentials&rdquo; to create an API token.</p>

<p>&nbsp;</p>

<p>Add a new token. In this example, I&rsquo;ve named it &ldquo;Tutorial&rdquo;</p>

<h1><br />
<img alt="" src="https://mindee-public-website.s3.amazonaws.com/blog/2020/09/01/pasted-image-0-1.png" style="height:247px; width:500px" /></h1>

<p>&nbsp;</p>

<p>Click &ldquo;Add New Key&rdquo; and you&rsquo;ll be able to see your API token.</p>

<p>Now, we are ready to make an API call.&nbsp; In this example, we&rsquo;ll be using cURL.</p>

<p>&nbsp;</p>

<pre>
<code class="language-bash">curl -X POST \ https://api.mindee.net/products/invoices/v1/predict  
    -H 'X-Inferuser-Token: {apiToken}'  
    -H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW'  
    -F file=@/path/to/your/file.png</code></pre>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>Simply replace ```{apiToken}``` with your new API token and ```/path/to/your/file/png``` with the path to your invoice - wither an image or a pdf.&nbsp;</p>

<p>&nbsp;</p>

<p>NOTE: You can also copy this code right from the documentation tab of the API with your API token inserted for you.</p>

<p>Here&rsquo;s the invoice I used - the roofer who fixed the gasket around our chimney this spring (I&rsquo;ve obfuscated my home address in the image):</p>

<p>&nbsp;</p>

<h1><img alt="" src="https://mindee-public-website.s3.amazonaws.com/blog/2020/09/11/screenshot-2020-09-11-at-193913.png" style="height:383px; width:500px" /></h1>

<p>&nbsp;</p>

<p>Pasting the cURL sample into my terminal, I hit enter and about a second later, I received a JSON response with the receipt details.&nbsp; The full JSON can be accessed here (link to JSON file).&nbsp; Since the response is quite verbose, we will walk through the various fields section by section.</p>

<p>&nbsp;</p>

<h2>Extracted fields</h2>

<p>&nbsp;</p>

<h2>Summary &amp; Documents section</h2>

<p>&nbsp;</p>

<p>The first two sections of the response contain information about the API call made:</p>

<pre>
<code class="language-json">	"call": {
		"endpoint": { "name": "invoices", "version": "1.0" },
		"finished_at": "2020-09-11T18:39:58+00:00",
		"id": "3b4ac75a-f800-466b-bfc4-56c8f8e75134",
		"n_documents": 1,
		"n_inputs": 1,
		"processing_time": 1.047,
		"started_at": "2020-09-11T18:39:57+00:00"
	},
	"documents": [
		{
			"id": "5d72b0c2-16dd-481d-9e8b-031c5d1ab33a",
			"name": "Screenshot 2020-09-11 at 19.39.13.png"
		}
	],</code></pre>

<p>&nbsp;</p>

<p>The call section tells us that we ran on the v1 of the invoice endpoint, uploading one document that is one page long.&nbsp; After a second, the file was processed, and the response transmitted back to me.&nbsp; The documents section gives the Mindee id for the file, and the filename (and you can tell I used a screenshot of the original invoice).</p>

<p>&nbsp;</p>

<h2>Predictions:&nbsp;</h2>

<p>&nbsp;</p>

<p>This is the fun part, where the API extraxcts pertinent details form teh invoice automatcilly, saving tedious manual data entry.&nbsp; Every invoice is different, and will have different fields. This invoice, being sent from the UNited States will not have some common European features like and IBAN or Tax Id.&nbsp;&nbsp;</p>

<p>Other peices are rpesent in this invoice, but not picked up by the API.&nbsp; We are planning multiple additional releases to this API in 2020 that will continue to improve the accuracy and precision of the results.&nbsp;&nbsp;</p>

<p>&nbsp;</p>

<h3>Company Number</h3>

<p>In this case, there is no company number in the invoice:</p>

<pre>
<code class="language-json">"company_number": {
				"probability": 0,
				"segmentation": { "bounding_box": [] },
				"type": "N/A",
				"value": "N/A"
			},</code></pre>

<h2>&nbsp;</h2>

<h3>Due Date</h3>

<p>My invoice does have a due date, but it was not extracted.&nbsp;</p>

<pre>
<code class="language-json">			"due_date": {
				"iso": "N/A",
				"probability": 0,
				"raw": "N/A",
				"segmentation": { "bounding_box": [] }
			},</code></pre>

<h2>&nbsp;</h2>

<h3>Invoice Date</h3>

<p>The work was done in late June of this year, and the API correctly extracts the invoice date, along with four [x,y] points boxing in the value:</p>

<pre>
<code class="language-json">			"invoice_date": {
				"iso": "2020-06-29",
				"probability": 0.99,
				"segmentation": {
					"bounding_box": [
						[ 0.766, 0.392 ],
						[ 0.855, 0.392 ],
						[ 0.855, 0.416 ],
						[ 0.766, 0.416 ]
					]
				}
			},</code></pre>

<h3>&nbsp;</h3>

<h3>Invoice Number</h3>

<p>The invoice is numbered 1277, which is extracted by the API, along with the four [x,y] corrdinates denoting the location in the image.</p>

<pre>
<code class="language-json">			"invoice_number": {
				"probability": 0.99,
				"segmentation": {
					"bounding_box": [
						[ 0.766, 0.363 ],
						[ 0.807, 0.363 ],
						[ 0.807, 0.382 ],
						[ 0.766, 0.382 ]
					]
				},
				"value": "1277"
			},</code></pre>

<h3>&nbsp;</h3>

<h3>Locale</h3>

<p>Based on the information on the invoice, the API is able to predict (with 82% confidence) that this bill originated in the United States, is in USD, and is in English.</p>

<pre>
<code class="language-json">"locale": { "currency": "USD", "language": "en", "probability": 0.82 },</code></pre>

<h2>&nbsp;</h2>

<h3>Orientation</h3>

<p>The invoice did not require rotation to be parsed.</p>

<pre>
<code class="language-json">"orientation": { "degrees": 0, "probability": 0.99 },</code></pre>

<h2>&nbsp;</h2>

<h3>Payment Details</h3>

<p>The invoice does not contain any payment details, so were not extracted.</p>

<pre>
<code class="language-json">"payment_details": {
				"iban": "N/A",
				"probability": 0,
				"segmentation": { "bounding_box": [] }
			},</code></pre>

<h3>&nbsp;</h3>

<h3>Supplier</h3>

<p>The API is only 50% confident in this result, but it does extract the name of the company (despite without any spaces in the name).&nbsp;&nbsp;</p>

<pre>
<code class="language-json">			"supplier": {
				"probability": 0.5,
				"segmentation": {
					"bounding_box": [
						[ 0.446, 0.066 ],
						[ 0.561, 0.066 ],
						[ 0.561, 0.083 ],
						[ 0.446, 0.083 ]
					]
				},
				"value": "SILVERHAMMER"
			},</code></pre>

<h3>&nbsp;</h3>

<h3>Tax Id</h3>

<p>Companies in the US generally do not list their Tax IDs on invoices, so this was not found.</p>

<pre>
<code class="language-json">			"tax_id": {
				"probability": 0,
				"segmentation": { "bounding_box": [] },
				"value": "N/A"
			},</code></pre>

<h3>&nbsp;</h3>

<h3>Taxes</h3>

<p>The API did not extract the texes, or the percentage tax rate (we have an update later this year t better extract US tax details.)</p>

<pre>
<code class="language-json">"taxes": [],</code></pre>

<h2>&nbsp;</h2>

<h3>Total without Taxes</h3>

<p>The API did not extract the taxes, but did get the cost before taxes with 99% confidence.&nbsp;&nbsp;</p>

<pre>
<code class="language-json">	"total_excl": {
				"amount": 350,
				"probability": 0.99,
				"segmentation": {
					"bounding_box": [
						[ 0.874, 0.803 ],
						[ 0.931, 0.803 ],
						[ 0.931, 0.825 ],
						[ 0.874, 0.825 ]
					]
				}
			},</code></pre>

<h2>&nbsp;</h2>

<h3>Total with Taxes</h3>

<p>The total with taxes was alos extracted accurately with 99% confidence, meaning that the tax value could easily be calculated with a simple difference.</p>

<pre>
<code class="language-json">"total_incl": {
				"amount": 380.45,
				"probability": 0.99,
				"segmentation": {
					"bounding_box": [
						[ 0.842, 0.897 ],
						[ 0.933, 0.897 ],
						[ 0.933, 0.93 ],
						[ 0.842, 0.93 ]
					]
				}
			}</code></pre>

<p>&nbsp;</p>

<h2>Conclusion</h2>

<p>Manual entry of invoices is a time consuming task. Adding the Mindee API to your system will simplify the extraction and make your accounts paybale processes run more accurately and smoothly.&nbsp; Do you have more questions? Click the chat button at the bottom right.</p>

<p>&nbsp;</p>

<h1>&nbsp;</h1>

<p>&nbsp;</p>

<p>&nbsp;</p>