Nintex Workflow – How to handle the JSON Response from REST API

Sathish Nadarajan
 
Solution Architect
April 10, 2019
 
Rate this article
 
Views
4514

Recently, I met with an interesting scenario that, from a Nintex Workflow, I am making a REST API, which returns a JSON object and the API is capable to return only JSON. I need to process result from my Workflow. When I was searching for a JSON Parser action in the Nintex, Unfortunately, there is no action like that in Nintex. And this has been raised in the Nintex User Voice as well. Hence, they may include this action in the upcoming releases I guess.

But, we must find a work around for that and the workaround is also very simple. We have a Data Type called Collection and Dictionary on the Nintex. By that, we can easily process the JSON. But, we have to use the foreach at least once, to actual processing.

The Set Workflow Variable Action configuration is like below.

Always the APIResonse will be Text and we need to create a Collection Variable and assign the Text to the Collection. Then the collection can be manipulated.

The Sample JSON Object, which I am getting from the API is as follows.

 {
   "Entry": [
     {
       "Employee_ID": "10001",
       "LeaveDetails": [
         {
           "LeaveType": "Casual",
           "Date": "2016-11-05",
           "ApprovedDate": "2018-10-31T22:15:44.112-07:00",
           "Unit": "Days",
           "Units": "1"
         },
         {
           "LeaveType": "Casual",
           "Date": "2016-11-05",
           "ApprovedDate": "2018-10-31T22:15:44.112-07:00",
           "Unit": "Days",
           "Units": "1"
         },
  {
           "LeaveType": "Casual",
           "Date": "2016-11-05",
           "ApprovedDate": "2018-10-31T22:15:44.112-07:00",
           "Unit": "Days",
           "Units": "1"
          
       ],
       "Employee Name": "Sathish Nadarajan"
     }
   ]
 }
 

I have a parent entry called “Entry” which has the childs, EmpID, EmployeeName, LeaveDetails. The Leave Details is again an Array. Hence, that can be treated as a Dictionary. The EmpID, we need to get the “Entry” Collection.

Save that on the Output Variable “ReportEntry” as Collection.

From the “ReportEntry”, Now, let us get the “LeaveDetails” collection.

Now, we can do the ForEach loop and manipulate the details.

The Output Value TimeOffDetail is nothing but a Dictionary Variable. From that dictionary, we can access the appropriate variable like Date, Units etc.,

We can manipulate any tags by giving the appropriate index and tag names as below.

By this way, we can manipulate the JSON objects in the Nintex Workflows.

 

Happy Coding,

Sathish Nadarajan.

Category : Nintex, RestAPI

Author Info

Sathish Nadarajan
 
Solution Architect
 
Rate this article
 
Sathish is a Microsoft MVP for SharePoint (Office Servers and Services) having 15+ years of experience in Microsoft Technologies. He holds a Masters Degree in Computer Aided Design and Business ...read more
 

Leave a comment