Iterate over nested REST API Queries

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!
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

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog

How Media Organizations Achieved Success with Data Integration

Learn how media organizations have achieved success with Data Integration

Read

Why Companies Move to the Cloud: 7 Success Stories

Learn how and why companies are moving to the Cloud

Read Now