Skip to main content

Notifications

Announcements

No record found.

Small and medium business | Business Central, N...
Unanswered

What is the best approach for managing a POST HTTP API Request FROM Business Central TO an external destination

Posted on by 30

Hi,

A client has a requirement whereby they need to submit a copy of a customers Sales Order, after it's entered in BC (v21.5), to the customer itself, via an POST HTTP API Request to a server hosted by the customer. 

The POST Request needs to be made in Xml format.

The details required within the Xml are fairly basic, eg:

  • Sales Order No., Shipment Date, Location Code from the Sales Header, and
  • Item No. and Quantity from the Sales Line

There are a couple more, but for the sake of simplicity I'll leave it at that.

I have built a fairly basic procedure against the Sales Header table to handle which is ok BUT... It's somewhat hard-coded and I'm sure there's a tidier and more flexible way I could have done. Must be able to use XMLPorts in some way to set-up the XML, rather than hard coding XMLElements and XMLAttributes etc.

I looked at Data Exchange Definitions also, but wasn't quite sure how to feed those into an POST HTTP API Request.

Keen to hear if anyone has some simple examples of setting up a POST HTTP API Request, using existing functionality (XMLPort, Data Exchange Definition, etc.) to build the Xml body, rather than coding as I have done. And maybe calling from a codeunit that could be set-up via Job Queue (currently I'm triggering mine from the Sales Order List page)

Also, does anyone know how to add a prefix to an XmlElement. Need to add "nsO" to the NameSpace element/node (e.g. 

<nsO:Submissiont xmlns:nsO="urn...">
  <Trans>
      ...
   </Trans>
</nsO:Submission>
Again I have achieved through hard code, but what's the proper use of the XmlNameSpace, XmlElement etc. functions to achieve this.
Haven't posted my code purposefully as I'm not looking for feedback on my current solution specifically, just any simple best practice examples people may have.
Thanks in advance.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans