One Star

Iterate over nested REST API Queries

I have a system that I am trying to interact with that provides a set of nested entities through JSON. I have my top level REST queries working correctly (tREST component, feeding into a tExtractJSONFields - the fields are showing up correctly.)
For the next part of my process, I need to extract a single field from the tExtractJSONFields result, and send that query back to my parent system (https://api.system.com/getSubEntities?id=JSONID), so that I can iterate over those results. This process should continue down until I no longer receive sub entities. What is the best way to feed that result back into a REST query and iterate down?
Thank you!
1 REPLY
Community Manager

Re: Iterate over nested REST API Queries

Hi
Use a tLoop to make a loop exectuion for the processing until it return no sub-entities, the job design looks like:
tLoop--iterate--tRest--main--tExtractJSONFields--main--tJavaRow
Define a context variable, boolean type, let's call it condition and set its default value as true, and another context variable, name it as url and set a default value for it.
on tLoop, set the Condition field as: context.condition
on tRest, set the URL field as: context.url
on tJavaRow:
change the url based on the return field, for example:
context.url="https://api.system.com/getSubEntities?id="+input_row.fieldName
check the return field and determine to stop the loop or not, for example:
if(input_row.fieldName==null){ //or other condition according to your real case.
context.condition=false;
}else{
context.condition=true;
}
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business