Business Card Importer with Flow & Cognitive Services
Let’s talk about Business Cards. Yes, it is 2018 and we are all still killing trees and carrying around business cards like we’re Don Draper. I for one am tired of junking up my desk with business cards so I decided to do something about it. Wouldn’t it be cool if you could take a picture of a business card and have Microsoft Flow auto-magically OCR the text and add it to your SharePoint List, Outlook Contacts or Mail Chimp list? With the power of Azure Cognitive Services and a little help from an Azure function we can!
Making the App
To make this business card importer I’m going to use a Flow Button with 3 Inputs:
- File Content (File Input Control to upload the business card)
- Add as Outlook Contact? (Yes/No input)
- Add to MailChimp? (Yes/No Input).
If the user selects yes on either one of these there will be an extra step in the Flow to add the contact in Outlook or MailChimp respectively. I’m going to add all business cards to a SharePoint Document library with the associated metadata (Name, Company, Email, Phone). I’ll use the Azure Computer Vision API to OCR the text. There is an OCR to JSON action that we will pass in our business card image to and that will do the work for us of scanning the card for text.
You might be wondering why I said we will have some help from an Azure Function for this, can’t the Cognitive Services OCR do all that for us? Yes it technically can but the problem is the format of the JSON is hard to parse in Flow alone. It wraps the text in boundary boxes then lines and words. It would take a lot of looping to get to the data with the way the JSON is structured. So, I decided it was better to create an Azure function that parses the data and returns it in easy to access name value pairs. Thankfully my husband helped me get the Azure function written pretty quick. I’m not going to go into details on the Azure function itself but if you want to use the code we have it uploaded to GitHub: Azure Function on Github
Here is the Flow Button Configuration:
Next, we’ll insert an OCR to JSON Action. Note: You will need to either do a 7 day trial or set up the Azure Computer Vision API in your environment to use this. You can read more and sign up here: Azure Computer Vision API
Now that we have OCR’d the business card and got the JSON, we need to insert a “Call HTTP” Action and point that to our Azure Function URL. We will pass in the OCR Json and do a POST to the Azure Function
Now we need to parse our Azure Function JSON so we can get the business card information. For the Parse action, you have to put in a sample schema. In this case I just took the JSON output of one of the successful tests from the Azure function and put that in the schema. The content will be the body from the HTTP Post in the previous step.
The next step is to add several “Initialize Variable” Actions and set those to the outputs from the JSON that we want to use. I want to return the following: Name, Company, Email, Phone, Website. So I will add 5 Initialize Variable actions and set those to the appropriate outputs from the Parse JSON action.
Now that we have the data we want to insert a “SharePoint – Create File” action to add the physical scanned business card image. You can’t create a file and add metadata at the same time so we will need to insert a “SharePoint – Update File Properties” Action after this and add in the associated metadata
The next part of this is optional. If you want to utilize the Yes/No boxes I included for Adding to Outlook or MailChimp then you can insert two Conditions to check if those options are set to yes. If the outlook condition is yes then you can insert the “Outlook – Create Contact” action. If the MailChimp condition is yes then you can insert the “MailChimp – Add to List” action.
If you followed the steps above then you have a fully automated Business Card Scanning App in Microsoft Flow! Now lets see it in action!
Great post, thanks a lot!
Can you please let me know how I can use the github project for the function? New to those and looks like I’m not able to do anything with the prebuild JSON or DLL either.
@Tim: As far as I know, you have to set up a azure api web app and insert the github code there. A free public azure api function is not available..