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