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 :
Microsoft Dynamics NAV (Archived)

How to call REST api from NAV 2013

(0) ShareShare
ReportReport
Posted on by 39

Let's understand the scenario, 

I have a xmlport and I have to use that in a code unit to call REST api and need to submit xml data as body content of the api and it will have few headers too.

But I am unable to post data in content as there is no Codeunit 1297 Http Web Request Mgt. in NAV 2013.

Unable to perform operations on Stream writer.

NAV is completely new for me, I am trying to learn it and improving myself day by day. But still thrs a lot to learn.

Is there any one who can help me with that? 

(Please suggest me a better resource to learn NAV too if possible.)

Thank you !

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at
    RE: How to call REST api from NAV 2013

    You can use DotNet variables by referencing classes in System.Net, like for example here:

    [View:http://www.kauffmann.nl/2015/11/26/web-services-examples-part-1-the-basic-pattern/]

    My suggestion is however to create an addin (C# dll) and here create methods for handling the WS communication. Much better and more powerful in many cases.

  • Krish Roy Profile Picture
    39 on at
    RE: How to call REST api from NAV 2013

    Thanks a lot to respond on the same.

    That is what I did at last moment , created a dll and using that in nav with input params.

    But I was not ready to involve c# I was looking for  something to use in NAV only.

    Thank you !!

  • ManishS Profile Picture
    86 on at
    RE: How to call REST api from NAV 2013

    Then in that case you need to upgrade you NAV version to lasted one, so you get the standard functionality.

  • Krish Roy Profile Picture
    39 on at
    RE: How to call REST api from NAV 2013

    I am shocked.

    Really? There is no way to do the same in NAV2013?

  • Hannes Holst Profile Picture
    5,767 on at
    RE: How to call REST api from NAV 2013

    Check this Blog here: http://www.dynamics.is/?p=2303

    The download contains a DLL called "NAVWebRequest.dll".

    Should work with NAV2013. I think this DLL is explained in more detail somewhere on this blog.

  • Krish Roy Profile Picture
    39 on at
    RE: How to call REST api from NAV 2013

    Thank you EveryOne.

  • Krish Roy Profile Picture
    39 on at
    RE: How to call REST api from NAV 2013

    "Failure is the best Teacher "

    Finally I have created a Code unit to call API from NAV without using Dot net dll.

  • Community Member Profile Picture
    on at
    RE: How to call REST api from NAV 2013

    Would be nice if you share it with us here for the next person..

  • Alessandro Isola Profile Picture
    5 on at
    RE: How to call REST api from NAV 2013

    Hi Krish,

    I have the same problem that You solved, please can You explain the way You followed to reach your goal?

    Thank You in advance

  • Krish Roy Profile Picture
    39 on at
    RE: How to call REST api from NAV 2013

    Hi,

    In Navision 2013 there is no unbuilt codeunit to call API (http web management) you have to use dotnet variables and write it in the same way in Navision.

    Here is the code.

    VAR
    HttpWebRequest@1000000001 : DotNet "'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Net.HttpWebRequest" RUNONCLIENT;
    HttpWebResponse@1000000004 : DotNet "'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Net.HttpWebResponse" RUNONCLIENT;
    HttpStatusCode@1000000005 : DotNet "'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Net.HttpStatusCode" RUNONCLIENT;
    Stream@1000000014 : DotNet "'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.IO.Stream" RUNONCLIENT;
    TextEncoding@1000000004 : DotNet "'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Text.Encoding" RUNONCLIENT;
    ResStreamReader@1000000010 : DotNet "'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.IO.StreamReader" RUNONCLIENT;
    ResStream@1000000012 : DotNet "'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.IO.Stream" RUNONCLIENT;
    Response@1000000015 : Text;
    RequestData@1000000006 : Text;

    HttpWebRequest:=HttpWebRequest.HttpWebRequest;
    HttpWebRequest:=WebRequest.Create('http://API_URL');
    HttpWebRequest.ContentType:='application/xml';
    HttpWebRequest.Method:='POST';
    Stream:=HttpWebRequest.GetRequestStream();
    Stream.Write(TextEncoding.ASCII.GetBytes(RequestData),0,TextEncoding.ASCII.GetBytes(RequestData).Length);
    Stream.Close();

    HttpWebResponse:=HttpWebResponse.HttpWebResponse;
    HttpWebResponse:=HttpWebRequest.GetResponse();
    HttpResStatus:=HttpWebResponse.StatusCode();
    CLEAR(Response);
    IF HttpResStatus=200 THEN BEGIN
    ResStream:=HttpWebResponse.GetResponseStream();
    ResStreamReader:=ResStreamReader.StreamReader(ResStream,TextEncoding.Unicode);
    Response:=ResStreamReader.ReadToEnd();
    END ELSE BEGIN
    ResStream:=HttpWebResponse.GetResponseStream();
    ResStreamReader:=ResStreamReader.StreamReader(ResStream,TextEncoding.Unicode);
    Response:=HttpWebResponse.StatusDescription;
    END;

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 > 🔒一 Microsoft Dynamics NAV (Archived)

#1
Saurav.Dhyani Profile Picture

Saurav.Dhyani 2 Super User 2025 Season 2

#2
RK-25090803-0 Profile Picture

RK-25090803-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans