web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested answer

how consume external web service from business central

(0) ShareShare
ReportReport
Posted on by 131

Hello community
First of all thanks for taking the time to read my question

My question is with reference to the consumption of web Services from AL for Business Central, I have knowledge on how to consult a web service and I do it in the following way (Quick Example)


url := 'URL Web Service';

if not PBAHttpClient.Get(url, PBAResponse) then
Error('');
PBAResponse.Content.ReadAs(PBAResultado);
Message(PBAResultado);
end;

The previous example is to consult a web Service which can be accessed without a username and password

My doubt or question would be how to consume a web service that has a username and password in which way these parameters are encoded in AL so that I can get a response from the web service

I hope my question can be solved and thank you very much for the time

nice day

I have the same question (0)
  • Suggested answer
    Suresh Kulla Profile Picture
    50,233 Super User 2025 Season 2 on at
    RE: how consume external web service from business central

    Based on the authentication type, you need to add the headers to the request using HttpRequestHeaders, there is an example in the below link

    demiliani.com/.../

  • Yael Suarez Profile Picture
    131 on at
    RE: how consume external web service from business central

    Hello thanks for your time, currently I built the following code following the example you provided me

            PBAUser := '*********';
            PBAPassWord := '*************';
            url := 'https://uhc.un**********************************';
            PBAHttpClient.DefaultRequestHeaders().Add('Authorization', StrSubstNo('%1%2', PBAUser, PBAPassWord));
            if not PBAHttpClient.Get(url, PBAResponse) then
                Error('');
            PBAResponse.Content.ReadAs(PBAResultado);
            Message(PBAResultado);

    but when executing it in business central I receive the following error message:

    The format of value 'PBAUserValue PBAPassWordValue' is invalid.

    Again I appreciate your time and I am attentive to your answer

  • Suggested answer
    Suresh Kulla Profile Picture
    50,233 Super User 2025 Season 2 on at
    RE: how consume external web service from business central

    It depends on the API you are calling, I just provided an example of how to add the headers, you cannot just use the same for passing username and password. Do you have documentation for your API, what kind of authorization it is looking for? Are they expecting a username and password with an authorization header?

    check this 

    dankinsella.blog/.../

  • Yael Suarez Profile Picture
    131 on at
    RE: how consume external web service from business central

    Unfortunately I do not know any documentation since they did not provide me with any documentation. I share an image of what the web service requires, I hope you can guide me and again I appreciate your time invested in my case

    Image (Link)----->  https://drive.google.com/file/d/1Wu4yWpxxj98a2LD7rgXqRKjWY1p1UOs3/view?usp=sharing

    I hope that with that information you can guide me if it is not so, I am on the lookout

  • Suggested answer
    Suresh Kulla Profile Picture
    50,233 Super User 2025 Season 2 on at
    RE: how consume external web service from business central

    Based on the screenshot it looks like they don't expect anything in the request header and the type is xml, so you need to build the xml as mentioned in the screenshot and post that xml.

    I recommend you first try using Postman and get success then based on that you can easily build the code in AL check the codeunit 1290

  • Yael Suarez Profile Picture
    131 on at
    RE: how consume external web service from business central

    I have already done a test with the SoapUI software and if I have a successful response from the web service data in the image that I attach below, on the left side you can see the XML and on the right side the successful response with the data that I need to have in Business central

    https://drive.google.com/file/d/1psHvL5ZMChRi1y1f9iiFcqwvl_yePDpi/view?usp=sharing

    Would you have to build the XML in AL that is shown on the left side of the image?

    I really appreciate your answers and comments.

  • Suggested answer
    Suresh Kulla Profile Picture
    50,233 Super User 2025 Season 2 on at
    RE: how consume external web service from business central

    Yes, you need to build that XML and post to the url. Check the codeunit I have sent you it has all the functions for you to build. 

  • Yael Suarez Profile Picture
    131 on at
    RE: how consume external web service from business central

    You can recommend me some articles to see how to make the XML document in business central to send it as a parameter in the URL

    Thank you very much for the knowledge

  • Suggested answer
    Steven Renders Profile Picture
    5,668 Moderator on at
    RE: how consume external web service from business central

    Here are some examples:

    docs.microsoft.com/.../

  • Suggested answer
    Suresh Kulla Profile Picture
    50,233 Super User 2025 Season 2 on at
    RE: how consume external web service from business central

    Check this link

    dynamics.is/

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
Rishabh Kanaskar Profile Picture

Rishabh Kanaskar 4,275

#2
Sumit Singh Profile Picture

Sumit Singh 2,677

#3
Nimsara Jayathilaka. Profile Picture

Nimsara Jayathilaka. 2,526

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans