In this post we will explore how to add a library which calls the Bing Spell Check API v7.  This post also serves as an example of how to call web services directly from Microsoft Dynamics 365 for Finance and Operations.  The current API documentation is for Visual Studio 2017, however it will work for us with little modification in Visual Studio 2015.

Set up Cognitive Services

1. Open Azure Portal

2. Search for Cognitive Services

3. Click Add

4. Choose “Bing Spell Check v7”

5. Create a new one, there is a free tier

6. Copy the keys from the Keys tab

7. Copy the endpoint address from the Overview tab

Create a Library to Call the API

8. Create a new F&O Project

9. Create a new .NET class library in the same solution

10. Rename Class1 to BingSpellCheckAPIWrapper

11. Use the following code (on GitHub) for the class library.  Fill out the endpoint address and API key with the ones provided by the Azure Portal.

Call the API from F&O

12. Create a new class and use the library (Code on Github).  As a proof of concept we’ll create a class with a main method that can be kicked off using SysClassRunner.

13. Make the class your startup object and start Debug, or navigate to this URL: https://usnconeboxax1aos.cloud.onebox.dynamics.com/?cmp=usmf&mi=SysClassRunner&cls=BingSpellCheckUtil

It should return a list of suggestions.  In our case the suggestion for dynamiacs is dynamics.  Awesome!

For real applications you’ll want to parse the JSON suggestions using JsonConvert class from Newtonsoft.Json.

{“_type”: “SpellCheck”, “flaggedTokens”: [{“offset”: 0, “token”: “Dynamiacs”, “type”: “UnknownToken”, “suggestions”: [{“suggestion”: “dynamics”, “score”: 1}]}], “correctionType”: “High”}

Troubleshooting – Invalid Key or Endpoint

Validate that you are using the correct key and use the endpoint address on the overview tab of the cognitive services card as shown in the Azure Portal.