cancel
Showing results for 
Search instead for 
Did you mean: 

Pass the json input request payload to REST GET

arunnp
New Contributor II

Hello,
I am new to Snap logic, I am trying to create a pipeline where I need to pass the json input request payload. based on the input I have to check for condition and then route to TWO different REST GET calls.
my input json is like this
{
“state”: “sample_state”,
“count”: “sample_count”,
“Caller”: “sample_caller”,
“fromDate”: “sample_fromdate”,
“toDate”: “sample_todate”,
“SysId”: “sample_sysid”
}
how to pass this from external app. And how to read the values to pass to REST GET call.
Answer will help a lot. Thanks

12 REPLIES 12

arunnp
New Contributor II

@viktor_n replacing the field value using Expression Builder worked, but I guess my Service URL is long
I got error Invalid URI.
Later I tried with Query Parameters suggested by @angie it worked well
Thanks a lot for the your help.

arunnp
New Contributor II

Hi @viktor_n, @angie

The response from REST GET I am mapping to a ‘result’ object but I am getting this inside array like below
[
{
“result”: [
{
“number”: “INC0029337”,
“short_description”: “test”,
“sys_id”: “90a4a74e1be97010ef9f6208b04bcb96”,
“comments”: “”,
“state”: “2”,
“sys_updated_on”: “2021-07-26 10:53:28”
},
{
“number”: “INC0029347”,
“short_description”: “test”,
“sys_id”: “90a4a74e1be97010ef9f6208b04bcb96”,
“comments”: “”,
“state”: “2”,
“sys_updated_on”: “2021-07-26 10:53:28”
}

    ]
}

]

but I need only the object inside. Ex
{
“result”: [
{
“number”: “INC0029337”,
“short_description”: “test”,
“sys_id”: “90a4a74e1be97010ef9f6208b04bcb96”,
“comments”: “”,
“state”: “2”,
“sys_updated_on”: “2021-07-26 10:53:28”
},
{
“number”: “INC0029347”,
“short_description”: “test”,
“sys_id”: “90a4a74e1be97010ef9f6208b04bcb96”,
“comments”: “”,
“state”: “2”,
“sys_updated_on”: “2021-07-26 10:53:28”
}

    ]
}

I tried some expressions in the mapper it is not working can you pls let me know how to get object as response. The below expression not giving desired oupput.
image

thanks
arun

viktor_n
Contributor II

Hi @arunnp,

Take one Splitter snap after the REST GET. In Json Path field which is in Splitter snap set the path of the result($entity.result)

Regards,
Viktor

arunnp
New Contributor II

Hi @viktor_n , thanks for reply
The Json Spliter splits the array, but it removes the array name in the output like below.
[{
“number”: “INC0029337”,
“short_description”: “test”,
“sys_id”: “erewrwer”,
“comments”: “”,
“state”: “2”,
“sys_updated_on”: “2021-07-26 10:53:28”
},
{
“number”: “INC0029336”,
“short_description”: “testing 2nd incident”,
“sys_id”: “dfdsg”,
“comments”: “”,
“state”: “2”,
“sys_updated_on”: “2021-07-26 10:52:34”
}]
But the expected response should be like
{
“result”: [{
“number”: “INC0029337”,
“short_description”: “test”,
“sys_id”: “fsdfsdgsdg”,
“comments”: “”,
“state”: “2”,
“sys_updated_on”: “2021-07-26 10:53:28”
},
{
“number”: “INC0029336”,
“short_description”: “testing 2nd incident”,
“sys_id”: “sdgssf”,
“comments”: “”,
“state”: “2”,
“sys_updated_on”: “2021-07-26 10:52:34”
}
]
}
I tried to rap this using toObject but did not work. I guess snaplogic removing array name, but our backend code is expecting the response as “result” array of objects.

thanks
arun

viktor_n
Contributor II

There is one solution for this.

If you have one document that you are working with, then at the end of the pipeline, in the JSON Formatter just check the “Format each document”.
image

But if you have more than one document at the input of the JSON Formatter, in that case, first you will need to group the data with Group By snap(group size need to be 0) into one document and pass into the formatter.

Regards,
Viktor