I’ve recently had a requirement to integrate an external system (Toggl http://www.toggl.com) with Dynamics AX 2012’s Timesheet system. However the external system only provided a JSON API which isn’t supported natively by the Dynamics AX AIF system. After some research and trial and error (using various DLL’s) I eventually stumbled across some really useful classes provided by the Retail module in Dynamics AX2012. These classes (although named “Retail…”) provide a really easy and elegant JSON interaction for any use. Here is a very basic code sample of how to consume JSON using these classes in Dynamics AX 2012.
static void myJob(Args _args) { RetailWebRequest request; RetailWebResponse response; str rawResponse, value; Map data; RetailCommonWebAPI webApi = RetailCommonWebAPI::construct(); request = RetailWebRequest::newUrl("http://mysite.com/jsonaction"); response = webApi.getResponse(request); rawResponse = response.parmData(); data = RetailCommonWebAPI::getMapFromJsonString(rawResponse); value = data.lookup("elementname"); info(strFmt("Element name: %1",value)); }
If you are interested in some more advanced examples of using JSON in AX (e.g. using authentication, retrieving subsets of info or arrays) or doing some of your own integration into Toggl timekeeping please let me know and I’ll post some more info.
Thanks for interesting post!!! I’m very interesting about of advanced using JSON in AX 2012. Please send me examples of usage. Thanks!!!
Hi,
I’m interested in making by sending json object as input. Is this possible? If you could you please send me some example, that would be great! Thanks!
making requests*
[…] my previous post on using JSON in Dynamics AX2012 I have received a number of requests for some slightly more […]
We are interested in Dynamics AX but what is holding us back is an elegant time tracking component like toggl or harvest. Does someone know one out there that natively integrates or can you share what you did with toggl.
[…] Repost from: https://workflowax.wordpress.com/2013/10/22/using-json-in-dynamics-ax/ […]
I am getting an error when I use this code. Clr object could not be created. Pls help.
Thank you for this excellent article. I have used your example for a few other examples at my blog post: http://www.agermark.com/2014/12/testing-json-from-ax-2012.html (artcicle gets published January 1st. 2015)
[…] 31 Dec 2014 5:00 PM I wanted to see how JSON could be consumed from AX, and found this great article from Jonathan.Then I needed something to test with and found the site jsontest.com.And so, here are […]
Hey
Do you happen to have an example with authentication?
Thanks for this great post!
I have managed to get JSON string in AX using .net dlls and Newtonsoft. Now I don’t know how to desalinize. Hep will be appreciated.
If you use Newtonsoft … Here is a sample of my code:
str postData;
JsonWebResponse response;
EmarsysJson.WebResponse.GetContactResponse getContactResponse;
postData = Newtonsoft.Json.JsonConvert::SerializeObject(contactData, Newtonsoft.Json.Formatting::Indented);
response = this.makePostRequest(jsonUriTable.URI, postData);
getContactResponse = new EmarsysJson.WebResponse.GetContactResponse();
getContactResponse = Newtonsoft.Json.JsonConvert::DeserializeObject(response.parmData(), getContactResponse.GetType());
Hi there to every body, it’s my first visit of
this blog; this weblog includes awesome and genuinely excellent stuff
in favor of readers.