During our project with Dynamics NAV 2018, we needed to consume a web service from CleverReach (see documentation of their REST API: https://rest.cleverreach.com/howto/), 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 https://github.com/TBits/Al-examples/blob/master/HTTPRequests/cod50131.HttpRequest.al
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 https://github.com/TBits/Al-examples/blob/master/HTTPRequests/pag50130.HttpRequest.al 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:
var post_names: List of [Text]; i: Integer; begin post_names.Add('test1'); post_names.Add('test2'); for i := 1 to post_names.Count do begin message(post_names.Get(i)); end; end;