Detect document type and extract data (AI)

Reads a business document using AI (OCR) and classifies it by document type: invoice or bill, credit note, receipt, delivery note, quote request, or any other document such as an order or contract. It reads PDF files, scans and photos (JPEG, PNG), Word (DOCX) and Excel (XLSX) files and text files such as TXT or CSV. For invoices, credit notes and receipts it also returns the invoice data (seller, buyer, items, totals, payment details). Up to 10 own fields can be read from every document.

Detect document type and extract data (AI)
📄 The document as PDF, JPEG or PNG (scan or photo), as XML e-invoice,…
Show advanced options
Optional hints for the AI. They can also set the document type, e.g…
Up to 10 own fields to extract from any document type.
If true, the top and bottom of page 1 are also sent zoomed in, so s…
If true, IBAN, VAT IDs and totals of invoices, credit notes and rec…
How often values are marked for review: Rarely, Normal or Often.▾
Auto: embedded e-invoice first, AI for the rest. Always AI. XML Onl…▾
Appearance of this action in the Power Automate designer (rendered from the connector definition).

What this action is for

Invoices, credit notes, receipts, delivery notes and quote requests often arrive in the same mailbox or folder. This action handles such a mixed inbox in one step: it tells you what kind of document it is (Document Type) and returns its data at the same time. In your flow, a Switch then sends every document type its own way, for example invoices to accounting and delivery notes to the warehouse.

Try it with the sample invoice

Sample invoice of Muster Bau GmbH with cost center KST-4711

Download the sample invoice (PDF) and try the action in a test flow before you connect your mailbox. The sample has the cost center KST-4711 in the address block.

Add the action

Create an instant cloud flow with the trigger Manually trigger a flow and add a File input; here it is called Document. Below the trigger choose + and Add an action, search for document type and select Detect document type and extract data (AI).

Add an action: search for document type

The picture was taken in our test environment. In your flow, the action is part of the connector BILL Converter by Power2Apps.

Choose the file, the hint and your own field

Put the file content of the trigger into Document File: a PDF, JPEG or PNG (scan or photo), an XML e-invoice, or a DOCX, XLSX or text file (for example TXT or CSV in UTF-8). Of a PDF, the AI reads as many pages as your plan allows, at most 50 (free plan: 5); if the PDF has more pages, Notes starts with PagesSkipped. A Word, Excel or text file is read as text, up to 60000 characters (longer text is shortened with the note ContentShortened). Old .doc or .xls files and password-protected Office files cannot be read. Under Advanced parameters choose Additional Instructions and Additional Field (or Show all). In Additional Instructions we write Only invoice or credit note, otherwise document. Under Additional Field we add the field Cost center with the description in the address block, after 'Kostenstelle:' and the type Text.

Parameters: Document File, Additional Instructions and the Additional Field Cost center

Run the flow and check the result

Save the flow, choose Test, then Manually. Select the sample invoice with Import and start the flow with Run flow.

Run flow with sample-invoice.pdf as Document

Open the run and the action. In the outputs, Document Type is invoice with a Document Type Confidence of 95, and the invoice fields are filled.

Outputs: Document Type invoice, Document Type Confidence 95 and the first invoice fields

Further down you find your own field: Additional Field 1 Value is the cost center KST-4711, and Additional Field Details shows the certainty, the page and the text it was read from. Needs Review is false.

Outputs: Needs Review and the own field Cost center with its details

Step by step: sort the email attachments of a mixed inbox

Step 1: Start the flow with the email attachments

Create an automated cloud flow with the trigger When a new email arrives (V3) (Office 365 Outlook). Under Advanced parameters set Include Attachments and Only with Attachments to Yes.

Any trigger that gives you the file content works as well, for example When a file is created in SharePoint or OneDrive.

Step 2: Add the action

Below the trigger choose + and Add an action, search for document type (or classify) and select Detect document type and extract data (AI) from the connector BILL Converter by Power2Apps. Put Attachments Content into Document File. Power Automate adds an Apply to each around the action by itself, so every attachment is read.

Step 3: Branch by document type

Add the control Switch right after the action. In On, choose Document Type from the action. Then add one case per type. The values must be written exactly like this, in lower case and with a space where shown:

In our test flow the hint Only invoice or credit note, otherwise document is set, so two cases and Default are enough:

Switch on Document Type with the cases invoice and credit note and Default

Steer the document type

Without hints, the action decides the document type itself: invoice, credit note, receipt, delivery note, quote request, or document for anything else. With Additional Instructions you can change that decision for your documents:

You can write the hints in English or in your own language, up to 2000 characters. Longer hints are shortened, and Notes then starts with InputShortened.

Read your own fields, for example a cost center

Open Advanced parameters and add an item under Additional Field, for example:

The value comes back in Additional Field 1 Value and in Additional Field Values under the key Cost center. Up to 10 own fields are read for every document type, also for delivery notes and for document.

The action does not reject a field that does not fit: more than 10 fields, a field without a name or with a name used twice, an unknown Field Type, Check Type, Review Level or Data Source Mode are handled with the default or skipped, and Notes says so with a code at the start (FieldsLimited, FieldSkipped, FieldNameShortened, FieldTypeDefaulted, CheckTypeIgnored, ReviewLevelDefaulted, AppliesToDefaulted, DataSourceModeDefaulted). The settings of each field are explained on the page of Detect invoice data with custom fields (AI).

A field with Applies To Line is read for every line item of the document, for any document type, for example the items of a delivery note or the rows of a measurement sheet. It comes back in Invoice Items under Additional Field Values of each line; for types other than invoice, credit note and receipt the other invoice fields stay empty. The invoice lines also carry the article number and the line discount, and a missing net unit price is calculated from the line net amount; both are explained on the page of Detect invoice data with custom fields (AI).

Example: the batch number of each item on a delivery note

Sample delivery note of Muster Bau GmbH with a batch number for each item

Download the sample delivery note (PDF). It has the delivery note number L202611041 at the top right and a batch number for each item in the column Charge: CH-26-0815 for item 4711 and CH-26-0816 for item 4712.

We read the delivery note number once for the document and the batch number for every item:

Parameters: Delivery note number with Applies To Document, Batch number with Applies To Line

The action returns Document Type delivery note. In Invoice Items each item has its description, quantity and article number, and its own Additional Field Values with the batch number:

Outputs: Document Type delivery note and the first item with Batch number CH-26-0815

The document field is at the top level: Additional Field 1 Value is L202611041, and Additional Field Details shows the text it was read from, Lieferschein-Nr.: L202611041.

Outputs at the top level: Delivery note number L202611041 with its details

To use the batch numbers, add an Apply to each over Invoice Items, as shown on the page of Detect invoice data with custom fields (AI), with the expression items('Apply_to_each')?['additionalFieldValues']?['Batch number'].

E-invoices: values from the XML

Document Type Confidence and the type document

Document Type Confidence says how sure the AI is about the type, from 0 to 100.

Parameters

PropertyNameTypeDescription
documentFileDocument File requiredfile (base64)The document as PDF, JPEG or PNG (scan or photo), as XML e-invoice, or as DOCX, XLSX or text file (e.g. TXT, CSV).
additionalInstructionsAdditional Instructions advancedstringOptional hints for the AI. They can also set the document type, e.g. 'Treat delivery notes with prices as invoice' or 'Only invoice or credit note, otherwise document'. Max 2000 characters.
additionalFieldsAdditional Field advancedarray of DtoAdditionalFieldUp to 10 own fields to extract from any document type.
readHeaderAndFooterInDetailRead Header and Footer in Detail advancedbooleanIf true, the top and bottom of page 1 are also sent zoomed in, so small print like bank details is read better.
default: true
validateStandardFieldsValidate Standard Fields advancedbooleanIf true, IBAN, VAT IDs and totals of invoices, credit notes and receipts are checked; problems set 'Needs Review'.
default: true
reviewLevelReview Level advancedstring (dropdown)How often values are marked for review: Rarely, Normal or Often.
default: "Normal"; dynamic dropdown
dataSourceModeData Source Mode advancedstring (dropdown)Auto: embedded e-invoice first, AI for the rest. Always AI. XML Only: no AI.
default: "Auto"; dynamic dropdown

Returns

PropertyNameTypeDescription
invoiceNumberInvoice Number stringRecognized invoice number
invoiceDateInvoice Date stringRecognized invoice date (format: yyyy-MM-dd)
currencyCodeCurrency stringRecognized currency code (e.g., EUR, USD)
sellerNameSeller Name stringRecognized seller company or person name
sellerStreetSeller Street stringRecognized seller street address
sellerPostcodeSeller Postcode stringRecognized seller postal code
sellerCitySeller City stringRecognized seller city or locality
sellerCountrySeller Country stringRecognized seller country (ISO code, e.g., DE)
sellerVatIdSeller VAT ID stringRecognized seller VAT ID
buyerNameBuyer Name stringRecognized buyer company or person name
buyerStreetBuyer Street stringRecognized buyer street address
buyerPostcodeBuyer Postcode stringRecognized buyer postal code
buyerCityBuyer City stringRecognized buyer city or locality
buyerCountryBuyer Country stringRecognized buyer country (ISO code, e.g., DE)
ibanIBAN stringRecognized bank account IBAN for payment
paymentDueDatePayment Due Date stringRecognized payment due date (format: yyyy-MM-dd)
totalNetAmountTotal Net Amount numberRecognized total net amount (without VAT)
totalVatAmountTotal VAT Amount numberRecognized total VAT amount
totalGrossAmountTotal Gross Amount numberRecognized total gross amount (including VAT)
invoiceLinesInvoice Items array of DtoRecognizedInvoiceLineV2Recognized line items of the document (invoice lines, or positions of a delivery note, order or quote request)
needsReviewNeeds Review booleanTrue if a check failed (IBAN, VAT ID, totals, own field checks), a required own field is missing, or the AI was not sure enough
checkStatusCheck Status stringOK if no check found anything, Check if a value should be looked at, Error if a hard check failed (totals, IBAN, a required field or no XML)
documentTypeDocument Type stringDetected document type: invoice, credit note, receipt, delivery note, quote request, or document if unclear.
documentTypeConfidenceDocument Type Confidence integer (int32)How certain the AI is about the document type, from 0 to 100.
deliveryDateDelivery Date advancedstringRecognized delivery date (format: yyyy-MM-dd)
buyerReferenceBuyer Reference advancedstringRecognized buyer reference or Leitweg-ID (BT-10)
buyerOrderNumberOrder Number advancedstringRecognized purchase order number of the buyer (BT-13)
sellerEmailSeller Email advancedstringRecognized seller email address
buyerVatIdBuyer VAT ID advancedstringRecognized buyer VAT ID
bicBIC advancedstringRecognized bank identifier code (BIC)
paymentRecipientPayment Recipient advancedstringRecognized name of the payment recipient
paymentTermPayment Term advancedstringRecognized payment term
isReadyForEInvoiceReady for E-Invoice advancedbooleanWhether the recognized data contains all fields required to create a valid e-invoice (EN 16931). If false, check 'Missing Required Fields'
missingRequiredFieldsMissing Required Fields advancedarray of stringRequired e-invoice fields and required own fields that could not be recognized, for example 'Invoice Number (BT-1)'
notesNotes advancedarray of stringNotes about the recognition, for example skipped pages or uncertain values
checkHintsCheck Hints advancedarray of DtoCheckHintOne entry per finding with a fixed code, the sentence from Notes and the field it concerns; empty if the status is OK
dataSourceData Source advancedstringWhere the values come from: AI (read by the AI), XML (from the e-invoice) or XML and AI (missing fields by AI); empty if nothing was read
additionalFieldValuesAdditional Field Values advancedobjectValues of your own fields with 'Applies To' Document, by field name (line fields are in 'Invoice Items')
additionalField1ValueAdditional Field 1 Value advancedstringValue of own field 1 in the order of 'Additional Field' (empty for a field with 'Applies To' Line)
additionalField2ValueAdditional Field 2 Value advancedstringValue of own field 2 in the order of 'Additional Field' (empty for a field with 'Applies To' Line)
additionalField3ValueAdditional Field 3 Value advancedstringValue of own field 3 in the order of 'Additional Field' (empty for a field with 'Applies To' Line)
additionalField4ValueAdditional Field 4 Value advancedstringValue of own field 4 in the order of 'Additional Field' (empty for a field with 'Applies To' Line)
additionalField5ValueAdditional Field 5 Value advancedstringValue of own field 5 in the order of 'Additional Field' (empty for a field with 'Applies To' Line)
additionalField6ValueAdditional Field 6 Value advancedstringValue of own field 6 in the order of 'Additional Field' (empty for a field with 'Applies To' Line)
additionalField7ValueAdditional Field 7 Value advancedstringValue of own field 7 in the order of 'Additional Field' (empty for a field with 'Applies To' Line)
additionalField8ValueAdditional Field 8 Value advancedstringValue of own field 8 in the order of 'Additional Field' (empty for a field with 'Applies To' Line)
additionalField9ValueAdditional Field 9 Value advancedstringValue of own field 9 in the order of 'Additional Field' (empty for a field with 'Applies To' Line)
additionalField10ValueAdditional Field 10 Value advancedstringValue of own field 10 in the order of 'Additional Field' (empty for a field with 'Applies To' Line)
additionalFieldDetailsAdditional Field Details advancedarray of DtoAdditionalFieldDetailDetails for each own field with 'Applies To' Document: value, certainty, page, found text and whether it needs review

Type DtoAdditionalField

PropertyNameTypeDescription
fieldNameField Name stringName of the field, e.g. 'Project number'. Used as key in 'Additional Field Values'.
fieldDescriptionField Description stringWhere to find the value on the document, e.g. 'top right, after Project:'.
fieldTypeField Type string (dropdown)Kind of value: Text, Number, Date or Amount.
default: "Text"; dynamic dropdown
requiredRequired advancedbooleanIf true, a missing value is listed in 'Missing Required Fields' and marked for review.
default: false
checkTypeCheck Type advancedstring (dropdown)Optional check: None, IBAN, VAT ID, Tax Number, Date, Amount or Custom Format.
default: "None"; dynamic dropdown
customFormatCustom Format advancedstringPattern for 'Custom Format': # = digit, A = letter, e.g. P-######.
appliesToApplies To advancedstring (dropdown)Document = one value per document, Line = one value per line item or table row.
default: "Document"; dynamic dropdown

Type DtoRecognizedInvoiceLineV2

PropertyNameTypeDescription
descriptionDescription stringRecognized description of the invoiced item or service
quantityQuantity numberRecognized quantity of the item
unitCodeUnit Code stringRecognized measurement unit (ISO code, e.g., C62 for piece)
unitPriceUnit Price numberRecognized net unit price after line discount, without tax. If it is missing or does not match the line net amount, it is derived from line net amount and quantity (see Notes)
vatPercentVAT Percent numberRecognized VAT rate for the item (e.g., 19 for 19%)
lineNetAmountLine Net Amount numberRecognized net amount of the line
articleNumberArticle Number stringRecognized article number of the seller (BT-155)
grossUnitPriceGross Unit Price numberRecognized unit price before line discount, without tax (BT-148)
discountPercentDiscount Percent numberRecognized line discount in percent (e.g., 40 for 40%)
discountAmountDiscount Amount numberRecognized discount amount of the whole line, without tax (BT-136)
additionalFieldValuesAdditional Field Values advancedobjectValues of your own fields with 'Applies To' Line for this line, by field name
additionalFieldDetailsAdditional Field Details advancedarray of DtoAdditionalFieldDetailDetails for each own field with 'Applies To' Line for this line: value, certainty, page, found text and whether it needs review

Type DtoAdditionalFieldDetail

PropertyNameTypeDescription
fieldNameField Name stringName of the own field
valueValue stringRecognized value (dates as yyyy-MM-dd, amounts with a decimal point)
certaintyCertainty integer (int32)How sure the AI is, from 0 to 100
needsReviewNeeds Review booleanTrue if the check failed, a required value is missing, or the certainty is below the review level
pagePage advancedinteger (int32)Page where the value was found, starting at 1
foundTextFound Text advancedstringText on the document the value was read from

Type DtoCheckHint

PropertyNameTypeDescription
codeHint Code stringFixed code of the finding, for example TotalsMismatch, IbanInvalid or PagesSkipped
textHint Text stringThe finding as an English sentence (the same as in Notes, except for LowCertainty)
fieldHint Field stringThe field the finding concerns, for example IBAN or Line 2: Cost Center; empty if it concerns the whole document

Example request

{
  "documentFile": "<base64-encoded file content>"
}

Example generated from the connector definition.