From Thursday, July, 9, 3:00 PM Pacific,
our Community site will be in
read-only mode
through Sunday, July 12th.
Thank you for your patience.

Iterate over nested REST API Queries

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

Best Practices for Using Context Variables with Talend – Part 2

Part 2 of a series on Context Variables

Blog

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog