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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

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

Creating XML Soap request in AL

(0) ShareShare
ReportReport
Posted on by 5

Hello,

I have found  articles usefull - how to replace XML DOM management with AL.

https://community.dynamics.com/nav/b/diveshboramsdnavblog/archive/2018/03/05/vs-code-xml-dom-management-part-1

https://community.dynamics.com/nav/b/diveshboramsdnavblog/archive/2018/03/09/vs-code-xml-dom-management-part-2

And how to create SOAP requests - createing the xml files with previous codeunits:

community.dynamics.com/.../creating-soap-request-message-in-al

Just need a little help with getting my xml text completed.

My code looks like below w. use of Divesh post.

CreateSoapDocument(lXmlDocument, 1, lEnvolopeXmlNode, lHeaderXmlNode, lBodyXmlNode);

XMLDomMgt.AddElement(lBodyXmlNode, ‘VerifyToken’, ”, ApiNameSpace, lBodyXmlNode);

XMLDomMgt.AddElement(lBodyXmlNode, 'email', 'some@email.com', '', lTempXmlNode);
XMLDomMgt.AddElement(lBodyXmlNode, 'password', 'password123', '', lTempXmlNode);
XMLDomMgt.AddElement(lBodyXmlNode, 'token', 'token123423434235', '', lTempXmlNode);

This will output xml below.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <Soap:Header />
    <Soap:Body>
        <VerifyToken xmlns="">http://api.url.com">
            <email xmlns="">some@email.com</email>
            <password xmlns="">password123</password>
            <token xmlns="">token123423434235</token>
        </VerifyToken>
    </Soap:Body>
</Soap:Envelope>

I would like it to look like this - how can I acheive that?

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <Soap:Body>
        <VerifyToken xmlns="">http://api.url.com">
            <email>some@email.com</email>
            <password>password123</password>
            <token>token123423434235</token>
        </VerifyToken>
    </Soap:Body>
</Soap:Envelope>

Thanks in advance
I have the same question (0)
  • Verified answer
    Divesh Profile Picture
    327 on at

    Hi Chris,

    Below changes are required to get the desired output.

    procedure CreateSoapMessage()

       var

           lXmlDocument: XmlDocument;

           lEnvolopeXmlNode: XmlNode;

           lHeaderXmlNode: XmlNode;

           lBodyXmlNode: XmlNode;

           lTempXmlNode: XmlNode;

           lXMLText: Text;

           ApiNameSpace: Label 'http://api.url.com';

       begin

           CreateSoapDocument(lXmlDocument, 1, lEnvolopeXmlNode, lHeaderXmlNode, lBodyXmlNode);

           XMLDomMgt.AddElement(lBodyXmlNode, 'VerifyToken', '', ApiNameSpace, lBodyXmlNode);

           XMLDomMgt.AddElement(lBodyXmlNode, 'email', 'some@email.com', ApiNameSpace, lTempXmlNode);

           XMLDomMgt.AddElement(lBodyXmlNode, 'password', 'password123', ApiNameSpace, lTempXmlNode);

           XMLDomMgt.AddElement(lBodyXmlNode, 'token', 'token123423434235', ApiNameSpace, lTempXmlNode);

           lXmlDocument.WriteTo(lXMLText);

           Message(lXMLText);

       end;

    Pass the ApiNameSpace also to email, password & token to get rid of the xmlns. Hope this helps.

    Best Regards,

    Divesh

  • MilesChris Profile Picture
    5 on at

    Thank you Divesh! 
    Just what I was looking for - I hadn't tried to include the namespace to the following elements.

    Have a great weekend!

  • MilesChris Profile Picture
    5 on at

    Divesh, Do you know how come I get this response back.

    Status code: 413

    Description: Request Entity Too Large

    When I just write the text into a variable and send that request it works fine, but when using the XML mgt you made I get this response. I am only sending 10 lines in the XML file, so dont understand why it should be too large.

  • Divesh Profile Picture
    327 on at

    Can you please paste the code here?

  • MilesChris Profile Picture
    5 on at

    thanks

  • Yael Suarez Profile Picture
    131 on at

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 1,857 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,047 Super User 2026 Season 1

#3
Dhiren Nagar Profile Picture

Dhiren Nagar 959 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans