Create a Document Intelligence Logic Apps workflow
This content applies to: v2.1 | Latest version: v4.0 (GA)
Important
This tutorial and the Logic App Document intelligence connector targets Document intelligence REST API v3.0 and forward.
Important
This tutorial and the Logic App Document intelligence connector targets Document intelligence REST API v2.1 and must be used with the FOTT Sample Labeling tool.
Azure Logic Apps is a cloud-based platform that can be used to automate workflows without writing a single line of code. The platform enables you to easily integrate Microsoft and your applications with your apps, data, services, and systems. A Logic App is the Azure resource you create when you want to develop a workflow. Here are a few examples of what you can do with a Logic App:
- Create business processes and workflows visually.
- Integrate workflows with software as a service (SaaS) and enterprise applications.
- Automate enterprise application integration (EAI), business-to-business (B2B), and electronic data interchange (EDI) tasks.
For more information, see Logic Apps Overview.
In this tutorial, we show you how to build a Logic App connector flow to automate the following tasks:
- Detect when an invoice as been added to a OneDrive folder.
- Process the invoice using the Document Intelligence prebuilt-invoice model.
- Send the extracted information from the invoice to a pre-specified email address.
Choose a workflow using a file from either your Microsoft OneDrive account or Microsoft ShareDrive site:
Prerequisites
To complete this tutorial, you need the following resources:
An Azure subscription. You can create a free Azure subscription
A free OneDrive or OneDrive for Business cloud storage account.
Note
- OneDrive is intended for personal storage.
- OneDrive for Business is part of Office 365 and is designed for organizations. It provides cloud storage where you can store, share, and sync all work files.
A free Outlook online or Office 365 email account**.
A sample invoice to test your Logic App. You can download and use our sample invoice document for this tutorial.
A Document Intelligence resource. Once you have your Azure subscription, create a Document Intelligence resource in the Azure portal to get your key and endpoint. If you have an existing Document Intelligence resource, navigate directly to your resource page. You can use the free pricing tier (F0) to try the service, and upgrade later to a paid tier for production.
After the resource deploys, select Go to resource. Copy the Keys and Endpoint values from your resource in the Azure portal and paste them in a convenient location, such as Microsoft Notepad. You need the key and endpoint values to connect your application to the Document Intelligence API. For more information, see create a Document Intelligence resource.
Create a OneDrive folder
Before we jump into creating the Logic App, we have to set up a OneDrive folder.
Sign in to your OneDrive or OneDrive for Business home page.
Select the ➕ Add New button in the upper-left corner sidebar and select Folder.
Enter a name for your new folder and select Create.
You see the new folder in your files.
We're done with OneDrive for now.
Create a Logic App resource
At this point, you should have a Document Intelligence resource and a OneDrive folder all set. Now, it's time to create a Logic App resource.
Navigate to the Azure portal.
Select ➕ Create a resource from the Azure home page.
Search for and choose Logic App from the search bar.
Select the create button
Next, you're going to fill out the Create Logic App fields with the following values:
- Subscription. Select your current subscription.
- Resource group. The Azure resource group that contains your resource. Choose the same resource group you have for your Document Intelligence resource.
- Type. Select Consumption. The Consumption resource type runs in global, multi-tenant Azure Logic Apps and uses the Consumption billing model.
- Logic App name. Enter a name for your resource. We recommend using a descriptive name, for example YourNameLogicApp.
- Publish. Select Workflow.
- Region. Select your local region.
- Enable log analytics. For this project, select No.
- Plan Type. Select Consumption. The Consumption resource type runs in global, multi-tenant Azure Logic Apps and uses the Consumption billing model.
- Zone Redundancy. Select disabled.
When you're done, you have something similar to the following image (Resource group, Logic App name, and Region may be different). After checking these values, select Review + create in the bottom-left corner.
A short validation check runs. After it completes successfully, select Create in the bottom-left corner.
Next, you're redirected to a screen that says Deployment in progress. Give Azure some time to deploy; it can take a few minutes. After the deployment is complete, you see a banner that says, Your deployment is complete. When you reach this screen, select Go to resource.
Finally, you're redirected to the Logic Apps Designer page. There's a short video for a quick introduction to Logic Apps available on the home screen. When you're ready to begin designing your Logic App, select the Blank Logic App button from the Templates section.
You see a screen that looks similar to the following image. Now, you're ready to start designing and implementing your Logic App.
Create an automation flow
Now that you have the Logic App connector resource set up and configured, let's create the automation flow and test it out!
Search for and select OneDrive or OneDrive for Business in the search bar. Then, select the When a file is created trigger.
Next, a pop-up window appears, prompting you to log into your OneDrive account. Select Sign in and follow the prompts to connect your account.
Tip
If you try to sign into the OneDrive connector using an Office 365 account, you may receive the following error: Sorry, we can't sign you in here with your @MICROSOFT.COM account.
- This error happens because OneDrive is a cloud-based storage for personal use that can be accessed with an Outlook.com or Microsoft Live account not with Office 365 account.
- You can use the OneDrive for Business connector if you want to use an Office 365 account. Make sure that you have created a OneDrive Folder for this project in your OneDrive for Business account.
After your account is connected, select the folder you created earlier in your OneDrive or OneDrive for Business account. Leave the other default values in place.
Next, we're going to add a new step to the workflow. Select the ➕ New step button underneath the newly created OneDrive node.
A new node is added to the Logic App designer view. Search for Form Recognizer (Document Intelligence forthcoming) in the Choose an operation search bar and select Analyze Document for Prebuilt or Custom models (v3.0 API) from the list.
Now, you see a window to create your connection. Specifically, you're going to connect your Document Intelligence resource to the Logic Apps Designer Studio:
Enter a Connection name. It should be something easy to remember.
Enter the Document Intelligence resource Endpoint URL and Account Key that you copied previously. If you skipped this step earlier or lost the strings, you can navigate back to your Document Intelligence resource and copy them again. When you're done, select Create.
Note
If you already logged in with your credentials, the prior step is skipped.
Next, you see the selection parameters window for the Analyze Document for Prebuilt or Custom Models (v3.0 API) connector.
Complete the fields as follows:
Model Identifier. Specify which model you want to call, in this case we're calling the prebuilt invoice model, so enter prebuilt-invoice.
Document/Image File Content. Select this field. A dynamic content pop-up appears. If it doesn't, select the Add dynamic content button below the field and choose File content. This step is essentially sending the file(s) to be analyzed to the Document Intelligence prebuilt-invoice model. Once you see the File content badge show in the Document /Image file content field, you've completed this step correctly.
Document/Image URL. Skip this field for this project because we're already pointing to the file content directly from the OneDrive folder.
Add new parameter. Skip this field for this project.
We need to add a few more steps. Once again, select the ➕ New step button to add another action.
In the Choose an operation search bar, enter Control and select the Control tile.
Scroll down and select the For each Control tile from the Control list.
In the For each step window, there's a field labeled Select an output from previous steps. Select this field. A dynamic content pop-up appears. If it doesn't, select the Add dynamic content button below the field and choose documents.
Now, select Add an Action from within the For each step window.
In the Choose an operation search bar, enter Outlook and select Outlook.com (personal) or Office 365 Outlook (work).
In the actions list, scroll down until you find Send an email (V2) and select this action.
Just like with OneDrive, you're asked to sign into your Outlook or Office 365 Outlook account. After you sign in, you see a window where we're going to format the email with dynamic content that Document Intelligence extracts from the invoice.
We're going to use the following expression to complete some of the fields:
items('For_each')?['fields']?['FIELD-NAME']?['content']
In order to access a specific field, we select the add the dynamic content button and select the Expression tab.
In the ƒx box, copy and paste the above formula and replace FIELD-NAME with the name of the field we want to extract. For the full list of available fields, refer to the concept page for the given API. In this case, we use the prebuilt-invoice model field extraction values.
We're almost done! Make the following changes to the following fields:
To. Enter your personal or business email address or any other email address you have access to.
Subject. Enter Invoice received from: and then add the following expression:
items('For_each')?['fields']?['VendorName']?['content']
Body. We're going to add specific information about the invoice:
- Type Invoice ID: and, using the same method as before, append the following expression:
items('For_each')?['fields']?['InvoiceId']?['content']
- On a new line type Invoice due date: and append the following expression:
items('For_each')?['fields']?['DueDate']?['content']
- Type Amount due: and append the following expression:
items('For_each')?['fields']?['AmountDue']?['content']
- Lastly, because the amount due is an important number, we also want to send the confidence score for this extraction in the email. To do this type Amount due (confidence): and append the following expression:
items('For_each')?['fields']?['AmountDue']?['confidence']
When you're done, the window looks similar to the following image:
Select Save in the upper left corner.
Note
- This current version only returns a single invoice per PDF.
- The "For each loop" is required around the send email action to enable an output format that may return more than one invoice from PDFs in the future.
Next, we're going to add a new step to the workflow. Select the ➕ New step button underneath the newly created OneDrive node.
A new node is added to the Logic App designer view. Search for "Form Recognizer (Document Intelligence forthcoming)" in the Choose an operation search bar and select Analyze Invoice from the list.
Now, you see a window where you can create your connection. Specifically, you're going to connect your Form Recognizer resource to the Logic Apps Designer Studio:
- Enter a Connection name. It should be something easy to remember.
- Enter the Form Recognizer resource Endpoint URL and Account Key that you copied previously. If you skipped this step earlier or lost the strings, you can navigate back to your Form Recognizer resource and copy them again. When you're done, select Create.
Note
If you already logged in with your credentials, the prior step is skipped. Continue by completing the Analyze Invoice parameters.
Next, you see the selection parameters window for the Analyze Invoice connector.
Complete the fields as follows:
- Document/Image File Content. Select this field. A dynamic content pop-up appears. If it doesn't, select the Add dynamic content button below the field and choose File content. This step is essentially sending the file(s) to be analyzed to the Document Intelligence prebuilt-invoice model. Once you see the File content badge show in the Document /Image file content field, you've completed this step correctly.
- Document/Image URL. Skip this field for this project because we're already pointing to the file content directly from the OneDrive folder.
- Include Text Details. Select Yes.
- Add new parameter. Skip this field for this project.
We need to add the last step. Once again, select the ➕ New step button to add another action.
In the Choose an operation search bar, enter Outlook and select Outlook.com (personal) or Office 365 Outlook (work).
In the actions list, scroll down until you find Send an email (V2) and select this action.
Sign into your Outlook or Office 365 Outlook account. After doing so, you see a window where we're going to format the email to be sent with dynamic content extracted from the invoice.
We're almost done! Type the following entries in the fields:
To. Enter your personal or business email address or any other email address you have access to.
Subject. Enter Invoice received from: and then append dynamic content Vendor name field Vendor name.
Body. We're going to add specific information about the invoice:
Type Invoice ID: and append the dynamic content Invoice ID field Invoice ID.
On a new line type Invoice due date: and append the dynamic content Invoice date field invoice date (date).
Type Amount due: and append the dynamic content Amount due field Amount due (number).
Lastly, because the amount due is an important number we also want to send the confidence score for this extraction in the email. To do this type Amount due (confidence): and add the dynamic content Amount due field confidence of amount due. When you're done, the window looks similar to the following image.
Tip
If you don't see the dynamic content display automatically, use the Search dynamic content bar to find field entries.
Select Save in the upper left corner.
Note
- This current version only returns a single invoice per PDF.
- The "For each loop" around the send email action enables an output format that may return more than one invoice from PDFs in the future.
Prerequisites
To complete this tutorial, you need the following resources:
An Azure subscription. You can create a free Azure subscription
Access to a SharePoint site.
A free Outlook online or Office 365 email account.
A sample invoice to test your Logic App. You can download and use our sample invoice document for this tutorial.
A Document Intelligence resource. Once you have your Azure subscription, create a Document Intelligence resource in the Azure portal to get your key and endpoint. If you have an existing Document Intelligence resource, navigate directly to your resource page. You can use the free pricing tier (F0) to try the service, and upgrade later to a paid tier for production.
After the resource deploys, select Go to resource. Copy the Keys and Endpoint values from your resource in the Azure portal and paste them in a convenient location, such as Microsoft Notepad. You need the key and endpoint values to connect your application to the Document Intelligence API. For more information, see create a Document Intelligence resource.
Create a Sharepoint folder
Before we jump into creating the Logic App, we have to set up a Sharepoint folder.
Sign in to your SharePoint site home page.
Select Documents, then the ➕ New button near the upper-left corner of the site window, and choose Folder.
Enter a name for your new folder and select Create.
Your new folder is located in your site library.
We're done with SharePoint for now.
Create Logic App resource
At this point, you should have a Document Intelligence resource and a SharePoint folder all set. Now, it's time to create a Logic App resource.
Navigate to the Azure portal.
Select ➕ Create a resource from the Azure home page.
Search for and choose Logic App from the search bar.
Select the create button
Next, you're going to complete the Create Logic App fields with the following values:
- Subscription. Select your current subscription.
- Resource group. The Azure resource group that contains your resource. Choose the same resource group you have for your Document Intelligence resource.
- Type. Select Consumption. The Consumption resource type runs in global, multi-tenant Azure Logic Apps and uses the Consumption billing model.
- Logic App name. Enter a name for your resource. We recommend using a descriptive name, for example YourNameLogicApp.
- Publish. Select Workflow.
- Region. Select your local region.
- Enable log analytics. For this project, select No.
- Plan Type. Select Consumption. The Consumption resource type runs in global, multi-tenant Azure Logic Apps and uses the Consumption billing model.
- Zone Redundancy. Select disabled.
When you're done, you have something similar to the following image (Resource group, Logic App name, and Region may be different). After checking these values, select Review + create in the bottom-left corner.
A short validation check runs. After it completes successfully, select Create in the bottom-left corner.
Next, you're redirected to a screen that says Deployment in progress. Give Azure some time to deploy; it can take a few minutes. After the deployment is complete, you see a banner that says, Your deployment is complete. When you reach this screen, select Go to resource.
Finally, you're redirected to the Logic Apps Designer page. There's a short video for a quick introduction to Logic Apps available on the home screen. When you're ready to begin designing your Logic App, select the Blank Logic App button from the Templates section.
You see a screen that looks similar to the following image. Now, you're ready to start designing and implementing your Logic App.
Search for and select SharePoint from the search bar. Then, select the When a file is created (properties only) trigger.
Logic Apps automatically signs you into your SharePoint account(s).
After your account is connected, complete the Site Address and Library Name fields. Select the Add new parameter field and select Folder.
Select the directory path including the folder that you created earlier.
Tip
Select the arrow at the end of each listed folder to traverse to the next folder in the path:
Next, we're going to add another step to the workflow. Select the ➕ New step button underneath the newly created SharePoint node.
Search for and select SharePoint from the search bar once more. Then, select the Get file content action.
Complete the fields as follows:
- Site Address. Select your SharePoint site.
- File Identifier. Select this field. A dynamic content pop-up appears. If it doesn't, select the Add dynamic content button below the field and choose Identifier.
- Infer Content Type. Select Yes.
We're going to add another new step to the workflow. Select the ➕ New step button underneath the newly created SharePoint node.
A new node is added to the Logic App designer view. Search for Form Recognizer (Document Intelligence forthcoming) in the Choose an operation search bar and select Analyze Document for Prebuilt or Custom models (v3.0 API) from the list.
Now, you see a window where you can create your connection. Specifically, you're going to connect your Document Intelligence resource to the Logic Apps Designer Studio:
Enter a Connection name. It should be something easy to remember.
Enter the Document Intelligence resource Endpoint URL and Account Key that you copied previously. If you skipped this step earlier or lost the strings, you can navigate back to your Document Intelligence resource and copy them again. When you're done, select Create.
Note
If you already logged in with your credentials, the prior step is skipped.
Next, you see the selection parameters window for the Analyze Document for Prebuilt or Custom models (v3.0 API) connector.
Complete the fields as follows:
- Model Identifier. Specify which model you want to call, in this case we're calling the prebuilt invoice model, so enter prebuilt-invoice.
- Document/Image File Content. Select this field. A dynamic content pop-up appears. If it doesn't, select the Add dynamic content button below the field and choose File content. This step is essentially sending the file(s) to be analyzed to the Document Intelligence prebuilt-invoice model. Once you see the File content badge show in the Document /Image file content field, you've completed this step correctly.
- Document/Image URL. Skip this field for this project because we're already pointing to the file content directly from the OneDrive folder.
- Add new parameter. Skip this field for this project.
We need to add a few more steps. Once again, select the ➕ New step button to add another action.
Control and select the Control tile.
Scroll down and select the For each Control tile from the Control list.
In the For each step window, there's a field labeled Select an output from previous steps. Select this field. A dynamic content pop-up appears. If it doesn't, select the Add dynamic content button below the field and choose documents.
Now, select Add an Action from within the For each step window.
In the Choose an operation search bar, enter Outlook and select Outlook.com (personal) or Office 365 Outlook (work).
In the actions list, scroll down until you find Send an email (V2) and select this action.
Sign into your Outlook or Office 365 Outlook account. After doing so, you see a window where we're going to format the email with dynamic content that Document Intelligence extracts from the invoice.
We're going to use the following expression to complete some of the fields:
items('For_each')?['fields']?['FIELD-NAME']?['content']
In order to access a specific field, we select the add the dynamic content button and select the Expression tab.
In the ƒx box, copy and paste the above formula and replace FIELD-NAME with the name of the field we want to extract. For the full list of available fields, refer to the concept page for the given API. In this case, we use the prebuilt-invoice model field extraction values.
We're almost done! Make the following changes to the following fields:
To. Enter your personal or business email address or any other email address you have access to.
Subject. Enter Invoice received from: and leave your cursor positioned after the colon.
Enter the following expression into the Expression field and select OK:
items('For_each')?['fields']?['VendorName']?['content']
- After you enter the expression in the field select the OK button and the formula badge will appear in the place where you left your cursor:
Body. We're going to add specific information about the invoice:
- Type Invoice ID: and, using the same method as before: position your cursor, copy the following expression into the expression field, and select OK the following expression:
items('For_each')?['fields']?['InvoiceId']?['content']
- On a new line type Invoice due date: and append the following expression:
items('For_each')?['fields']?['DueDate']?['content']
- Type Amount due: and append the following expression:
items('For_each')?['fields']?['AmountDue']?['content']
- Lastly, because the amount due is an important number, we also want to send the confidence score for this extraction in the email. To do this type Amount due (confidence): and append the following expression:
items('For_each')?['fields']?['AmountDue']?['confidence']
When you're done, the window looks similar to the following image:
Select Save in the upper left corner.
Note
- This current version only returns a single invoice per PDF.
- The "For each loop" is required around the send email action to enable an output format that may return more than one invoice from PDFs in the future.
After you save your Logic App, if you need to make an update or edit your For each node will look similar to the following image:
Search for and select SharePoint from the search bar once more. Then, select the Get file content action.
Complete the fields as follows:
- Site Address. Select your SharePoint site.
- File Identifier. Select this field. A dynamic content pop-up appears. If it doesn't, select the Add dynamic content button below the field and choose Identifier.
- Infer Content Type. Select Yes.
Next, we're going to add another new step to the workflow. Select the ➕ New step button underneath the newly created SharePoint node.
A new node is added to the Logic App designer view. Search for "Form Recognizer (Document Intelligence forthcoming)" in the Choose an operation search bar and select Analyze invoice from the list.
Now, you see a window where to create your connection. Specifically, you're going to connect your Form Recognizer resource to the Logic Apps Designer Studio:
- Enter a Connection name. It should be something easy to remember.
- Enter the Form Recognizer resource Endpoint URL and Account Key that you copied previously. If you skipped this step earlier or lost the strings, you can navigate back to your Form Recognizer resource and copy them again. When you're done, select Create.
Note
If you already logged in with your credentials, the prior step is skipped. Continue by completing the Analyze Invoice parameters.
Next, you see the selection parameters window for the Analyze Invoice connector.
Complete the fields as follows:
- Document/Image File Content. Select this field. A dynamic content pop-up appears. If it doesn't, select the Add dynamic content button below the field and choose File content. This step is essentially sending the file(s) to be analyzed to the Document Intelligence prebuilt-invoice model. Once you see the File content badge show in the Document /Image file content field, you've completed this step correctly.
- Document/Image URL. Skip this field for this project because we're already pointing to the file content directly from the OneDrive folder.
- Include Text Details. Select Yes.
- Add new parameter. Skip this field for this project.
We need to add the last step. Once again, select the ➕ New step button to add another action.
In the Choose an operation search bar, enter Outlook and select Outlook.com (personal) or Office 365 Outlook (work).
In the actions list, scroll down until you find Send an email (V2) and select this action.
Sign into your Outlook or Office 365 Outlook account. After doing so, you see a window where we're going to format the email to be sent with dynamic content extracted from the invoice.
We're almost done! Type the following entries in the fields:
To. Enter your personal or business email address or any other email address you have access to.
Subject. Enter Invoice received from: and then append dynamic content Vendor name field Vendor name.
Body. We're going to add specific information about the invoice:
Type Invoice ID: and append the dynamic content Invoice ID field Invoice ID.
On a new line type Invoice due date: and append the dynamic content Invoice date field invoice date (date).
Type Amount due: and append the dynamic content Amount due field Amount due (number).
Lastly, because the amount due is an important number we also want to send the confidence score for this extraction in the email. To do this type Amount due (confidence): and add the dynamic content Amount due field confidence of amount due. When you're done, the window looks similar to the following image.
Tip
If you don't see the dynamic content display automatically, use the Search dynamic content bar to find field entries.
Select Save in the upper left corner.
Note
- This current version only returns a single invoice per PDF.
- The "For each loop" around the send email action enables an output format that may return more than one invoice from PDFs in the future.
Test the automation flow
Let's quickly review what we completed before we test our flow:
- We created a trigger—in this scenario. The trigger is activated when a file is created in a pre-specified folder in our OneDrive account.
- We added a Document Intelligence action to our flow. In this scenario, we decided to use the invoice API to automatically analyze an invoice from the OneDrive folder.
- We added an Outlook.com action to our flow. We sent some of the analyzed invoice data to a pre-determined email address.
Now that we created the flow, the last thing to do is to test it and make sure that we're getting the expected behavior.
To test the Logic App, first open a new tab and navigate to the OneDrive folder you set up at the beginning of this tutorial. Add this file to the OneDrive folder Sample invoice.
Return to the Logic App designer tab and select the Run trigger button and select Run from the drop-down menu.
You see a message in the upper=right corner indicating that the trigger was successful:
Navigate to your Logic App overview page by selecting your app name link in the upper-left corner.
Check the status, to see if the run succeeded or failed. You can select the status indicator to check which steps were successful.
If your run failed, check the failed step to ensure that you entered the correct information.
After a workflow run succeeds, check your email. There's a new email with the information we specified.
After you're done, disable or delete your logic app so that usage stops.
Congratulations! You completed this tutorial.