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 AX (Archived)

Consume JSON based web API in AX 2012

(0) ShareShare
ReportReport
Posted on by 40

Hi All,

We have a requirement to consume JSON based Web API in AX 2012 R3. I am new to this requirement and with the help of some posts I tried to use the below sample code by executing in a Job in X++.

RetailWebRequest    request; 
RetailWebResponse   response;
    str                 rawResponse;
    Map                 responseData;
    str                 responseValue;
   
    RetailCommonWebAPI webApi = RetailCommonWebAPI::construct(); 
    request = RetailWebRequest::newUrl("echo.jsontest.com/.../Clark");
    response = webApi.getResponse(request); 
    rawResponse = response.parmData(); 
    responseData = RetailCommonWebAPI::getMapFromJsonString(rawResponse);
    responseValue = responseData.lookup("Kent");
     info(strFmt("Element name: %1", responseValue));

However, I could not get any response. Can anyone please help me on this?  

Regards

Ana

*This post is locked for comments

I have the same question (0)
  • Upgrade from AX 3.0 to AX 2009 Profile Picture
    40 on at
    RE: Consume JSON based web API in AX 2012

    Hi Martin,

    I found why it was not working. I couldn't get the web response due to connectivity issues while accessing the URL. Now, I am able to get the response value.

    And I need to check with the URL provided by the Customer which is a different URL. Will let you know if I face any issues.

    Regards

    Ana

  • Martin Dráb Profile Picture
    235,936 Most Valuable Professional on at
    RE: Consume JSON based web API in AX 2012

    What do you mean by "not executing"? That you call the method, it executes but it gives you an empty result?

    If you get the right data in rawResponse but nothing from getMapFromJsonString(), the bug is in using getMapFromJsonString(). It's not a general-purpose deserializer; I think it can handle only a certain structure.

    You can using Newtonsoft.Json library directly to deserialize JSON. Create a C# class library in AOT, use "Paste JSON as classes" to create classes to deserialize to and use Newtonsoft.Json to do the job. Then you can use these classes in your code, which is even easier than working with maps.

  • Upgrade from AX 3.0 to AX 2009 Profile Picture
    40 on at
    RE: Consume JSON based web API in AX 2012

    Hi Martin,

    Thanks for your reply. While debugging the code, I have observed in RetailCommonWebAPI::getMapFromJsonString method, the line CLRObject dict = ser.DeserializeObject(_jsonString); is not executing. It is not throwing any exception. I am not sure if am missing something in the code?

    In the Url, "Kent" value is available. (echo.jsontest.com/.../Clark)

    Please let me know if any other details I have to share.

    Regards

    Ana

  • Martin Dráb Profile Picture
    235,936 Most Valuable Professional on at
    RE: Consume JSON based web API in AX 2012

    Can you elaborate what exactly happened? Did it throw an exception? If so, where? Did parmData() return nothing? Or did the serialization fail? Or the object didn't have "Kent" property?

    We can't help you unless you collect more information.

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…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Syed Haris Shah Profile Picture

Syed Haris Shah 9

#2
Martin Dráb Profile Picture

Martin Dráb 2 Most Valuable Professional

#2
doninep Profile Picture

doninep 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans