08-02-2021 02:37 AM
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
08-03-2021 05:19 AM
08-06-2021 02:31 AM
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.
thanks
arun
08-06-2021 03:17 AM
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
08-06-2021 05:10 AM
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
08-06-2021 07:35 AM
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”.
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