AL Coding: consume a web service from Dynamics NAV 2018 with POST and Basic Authentication   August 27th, 2018

During our project with Dynamics NAV 2018, we needed to consume a web service from CleverReach (see documentation of their REST API:, so that we can synchronize the recipients of the newsletters.

Here are now procedures that can be universally useful for using web services from within Dynamics NAV:

See the code at

How to do a simple GET http request:

procedure LoadWebpage(url: Text) result: Text;

How to do a simple POST http request:

procedure PostRequest(url: Text; post_names: List of [Text]; post_values: List of [Text]) result: Text;

And then how to do a POST http request, that is behind Basic Authentication (eg. done with htaccess/htpasswd):

procedure PostRequestWithBasicAuth(
        url: Text;
        post_names: List of [Text];
        post_values: List of [Text];
        username: Text;
        password: Text) result: Text;

I have prepared some web services for testing, see the code in for how to call them.

By the way, this example also shows how to use lists in AL, which is a feature that can hardly be found in the documentation:

    post_names: List of [Text];
    i: Integer;
    for i := 1 to post_names.Count do
Tags: ,
This entry was posted on Monday, August 27th, 2018 at 9:37 pm and is filed under Software Development. You can follow any responses to this entry through the RSS 2.0 feed.Both comments and pings are currently closed.

No Responses