Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics NAV forum
Suggested answer

Receive Data via Http and Respond using Webservice

Posted on by 5

Hey NAV Users/Devs,

I got a little stuck with webservices. We never had to use one before so I am pretty new to this topic.

So, a third party software calls my NAV Webservice and sends JSON or XML data via HttpPost. The data contains an e-mail address, which i have to look for in our Customer Table and respond with let's say the customer name and address, also in JSON or XML.

I know this will involve Codeunit 1297 or 1237 but as simple as that, there are so many confusing articles and posts out there, so i got lost in all the information.

I would be really glad if one of you guys could help me out here with a simple explanation or even some examples.

Thanks and best regards from Austria,
Daniel

  • Bodhi Profile Picture
    Bodhi 554 on at
    RE: Receive Data via Http and Respond using Webservice

    1, create a codeunit, write a funtion in the codeunit

      jason file as a parameter variable

      use a .net addin to parse the Jason file

      use the field name to get data from Jason file and assign to fieldref

      the value will be in table

     we can return a jason as return value

    2, post this codeunit in the Webservices in NAV

    3, the third party software calls the Webservices( like postman)

  • RE: Receive Data via Http and Respond using Webservice

    Hello just change the json body

    uri := FakturaBoksSetup."Base URL" + 'api/Kreditorer/';
    RequestHeaders := Client.DefaultRequestHeaders();
    RequestContent.WriteFrom('[{"Cvr": "' + VatNo + '", "Leverandoernavn": "' + vendor.Name + '","Leverandoernummer": "' + Vendor."No." + '", "Regnr_kontonr": "' + vendor."Preferred Bank Account Code" + '","Regnskab": "' + FakturaBoksSetup."Company Name" + '"}]');
    RequestContent.GetHeaders(contentHeaders);
    contentHeaders.Clear();
    vHttpRequestMessage.Method := ('POST');
    RequestHeaders.Add('Authorization', CreateBasicAuthHeader());
    contentHeaders.Add('API_KEY', FakturaBoksSetup."Access Key");
    contentHeaders.Add('Content-Type', 'application/json');
    vHttpRequestMessage.SetRequestUri(uri);
    vHttpRequestMessage.Content := RequestContent;
    Client.Send(vHttpRequestMessage, ResponseMessage);
    ResponseMessage.Content().ReadAs(ResponseText);

  • THE Italian Profile Picture
    THE Italian on at
    RE: Receive Data via Http and Respond using Webservice

    That is great to hear :-) 

    You could always any time blog it or put your cod on GitHub to empower the whole community. 

    Well done.

  • _daru Profile Picture
    _daru 5 on at
    RE: Receive Data via Http and Respond using Webservice

    Hi Duilio,

    thanks a lot for your response. As your latter solution is not an option for the moment, I ended up writing an Asp.net core Wep Api, handling all incoming Requests and responding with the desired Json String. The Asp.net Core solution is way more flexible imo.

    If someone is interested in the source code, feel free to message me.

    Cheers,

    Daniel

  • Suggested answer
    THE Italian Profile Picture
    THE Italian on at
    RE: Receive Data via Http and Respond using Webservice

    You might find some sample for this old version all over internet and mibuso. Here is one example

    navfreak.com/.../

    The best solution, in this case, would be to upgrade to Dynamics 365 Business Central and use HttpClient datatype that does all of your are in need natively and in a more robust way.

    docs.microsoft.com/.../httpclient-data-type

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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,558 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,645 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans