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

Notifications

Announcements

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)
  • Yael Suarez Profile Picture
    131 on at

    Thanks for taking the time

    I have managed to build the XML in AL which looks like this:

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

    Now I store the XML in a Text Type variable and execute the following Code

            PBADOCUMENTXML.WriteTo(PBAXML);
            //Message(PBAXML);
           
                if not PBAHttpClient.Get(PBAXML, PBAResponse) then
                Error('');
            PBAResponse.Content.ReadAs(PBAResultado);
            Message(PBAResultado);

    But my code cannot make the call to the web service and enters the line of code "ERROR ('')
    My question is if now that I want to make a call to the web service with xml and not with a URL link, the way of consuming the Web Service changes.

    I hope and can receive your knowledge and again thank you for your attention


    good day

  • Suggested answer
    Suresh Kulla Profile Picture
    50,251 Super User 2025 Season 2 on at

    Check this link

    dynamics.is/

  • Suggested answer
    Steven Renders Profile Picture
    5,672 Moderator on at

    Here are some examples:

    docs.microsoft.com/.../

  • Yael Suarez Profile Picture
    131 on at

    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
    Suresh Kulla Profile Picture
    50,251 Super User 2025 Season 2 on at

    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

    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,251 Super User 2025 Season 2 on at

    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

    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,251 Super User 2025 Season 2 on at

    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

    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

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

News and Announcements

Season of Giving Solutions is Here!

Quick Links

Responsible AI policies

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

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 1,532

#2
Khushbu Rajvi. Profile Picture

Khushbu Rajvi. 768 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 724 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans