REST Web Services using Json and requiring authentication

But first…

Registration for NAV TechDays 2017 have been opened.  I will do a workshop on web services and json.  I will be using both C/AL and AL with VS Code in this workshop.

Make sure to register for the conference and if possible go to one or two of the workshops.

Now to the topic.  Yesterday I started to develop an integration solution for bokun.io.  Their API is RESTful and uses Json file formats.  It also requires authentication.

In a project like this I usually start by using the OCR Service Setup from standard NAV.  Create a Setup table and a page.

Looking at the API documentation we can see that we need to use HmacSHA1 with both Access Key and Secret Key to authenticate.  In other project I used HmacSHA256 with the Access Key for the Azure API.

First part of the authentication is the time stamp created in UTC.  I find it easy to use the DateTime DotNet variable to solve this.  There are two different formatting I needed to use.

REST service normally just use GET or POST http methods.  The authentication is usually in the request headers.  This is an example from bokun.is

The GetSignature function is

The Secret Key string and the Signature is converted to a byte array.  The Crypto class is constructed with the Secret Key Byte Array and used to compute hash for the Signature Byte Array. That hash is also a byte array that must be converted to a base64 string.  This will give you the HmacSHA1 signature to use in the request header.

My Azure project is using HmacSHA256 but the code is similar.

Azure displays the Access Keys in base64 format while bokun.is has a normal string.

A little further down the line I choose not to use XML Ports, like I did here, but still convert Json to Xml or Xml to Json.

I use the functions from Codeunit “XML DOM Management” to handle the Xml.  This code should give you the general idea.

 

 

My first Dynamics 365 Extension – In maintenance mode

This morning I got this email:

Hi Gunnar,

I just wanted to inform you that your extension passed validation on US, CA, and GB. We will now get your extension checked in and it will go into the June (Update 7) release.

I am excited to see if users will start to install my app.  As more markets will open for Dynamics 365 for Financials (D365) I will need to support more languages to my App.

If you can help me with your local language please ping me.  The App is available on my GitHub site; https://github.com/gunnargestsson/nav2017/tree/GLSourceNames.  If you would like to install this extension or merge the deltas into your solution, again just ping me.

If you are in the process of creating an Extension for Dynamics 365 for Financials you can now request a Financials sandbox environment.  I installed this on my local virtual machine and this was an essential part of validating the extension.  You will need to sign up for the CTP program, which provides you with a prerelease version of Dynamics 365 for Financials. After you have signed the CTP Agreement, you are directed to a page that contains information about how to download the latest builds and configure a local computer or a Microsoft Azure VM for Dynamics 365 for Financials. If you have questions or feedback regarding this, please send an e-mail to: d365-smb@microsoft.com.

Also, take a look at the updated aka.ms/AppsForFinancials page for more information.

Finally, if you take a look at the source for G/L Source Names you will find a setup.json file.  This file has all the information needed for my GIT Source Control.  As promised in NAV TechDays 2016 I am releasing the AdvaniaGIT to be community project.  Stay tuned to Dynamics.is as I will be writing blogs about this project in the coming days and weeks.