Search code examples
curldynamics-business-centraldynamics-al

How to use curl within business central (c/AL)


How to post and get data from external url into business central AL codeunit using curl. Any other alternative method/approach is welcomed.


Solution

  • In AL the HttpClient Data Type is what you are looking for when communicating between external systems, see: Call external services with the HttpClient data type

        local procedure GetRequest() ResponseText: Text
        var
            Client: HttpClient;
            IsSuccessful: Boolean;
        begin
            IsSuccessful := Client.Get('https://httpcats.com/418.json', HttpResponseMessage);
    
            // error handling
    
            HttpResponseMessage.Content().ReadAs(ResponseText);
        end;
    

    Modify the above example to your own needs. It's also a good practice to save URLs into their own variable with Locked = true and maybe even a placeholder:

    var
        httpCatsUrl: Label 'https://httpcats.com/%1.json', Locked = true, Comment = '%1=http status code';