Azure Cognitive and Business Central : “Form Recognizer” API integration

Easily track employee expenses (Part 2 – Business Central AL code).

How to get the receipt grand total from an image by using Azure Cognitive API and save it Business Central.

HOW TO TEST OUR CUSTOM MODEL WITH INSOMNIA

Let’s have a look on how cognitive requests work by using Insomia.

First of all I make a POST call with a Json with the format:.

https://{ my address }.cognitiveservices.azure.com//formrecognizer/v2.0-preview/custom/models/ { my model id } /analyze

The posted json contains the source URL of the blob image in source.

The header contain the Cognitive Key in “Ocp-Apim-Subscription-Key”.

You should get back a “202 – Accepted” containing Operation-Location which is the URL to be queried to get the result.

The “Operation Location” to be queried to get back the result has the following format.

https://{service name}.cognitiveservices.azure.com/formrecognizer/v2.0-preview/custom/models/{model id}/analyzeresults/{result id}

By calling with a GET the URL we finally get the tags we trained with our custom model.

BUSINESS CENTRAL AL

The codeunit 70659914 “ALV Cognitive Service API” contains the logic to call the azure cognitive API.

GetCognitive() makes the first call to cognitive to start the blob storage image processing by using custom model.

The GetCognitiveResult() queries the Cognitive API waiting for the result to be evaluated.

Source code in AL available here:

https://github.com/avalonit/ExBcCognitiveAzure

CREDITS

AL support for REST Web Services by Kauffmann

AL support for REST Web Services

LAST UPDATED

22st of July, 2020

One thought on “Azure Cognitive and Business Central : “Form Recognizer” API integration

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s