โ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