Talend Connect
Virtual Summit
JOIN US!
And visit the Customer
& Community Lounge.
May 27-28, wherever you are.

tRestClient - GET - using parameters

Highlighted
Four Stars

tRestClient - GET - using parameters

Hello All,

I am stuck with a scenario where I use Talend rest API [ POST ] to run a different job and in response it gets 2 attributes in json  run_id and number_in_job.

 

Now, I need to take the run_id number and invoke a API GET call to see the job result [ Success or Failure ] .

 

I know the URL for POST and GET.

 

How can I integrate API request [POST} and API [GET] to see the final output.

 

Thanks

Sathya

 

Highlighted
Forteen Stars

Re: tRestClient - GET - using parameters

Hi Sathya

 

call the first API, use tExtractJSONFields  to extract values from response JSON, store it to variable

use this variable in 2nd subjob to 2nd API call

-----------
Highlighted
Four Stars

Re: tRestClient - GET - using parameters

Hi Vapukov,

 

Thanks for your response. Can you please explain me a bit as I am very new to ETL  world.

 

I am trying as in the attached pic.

 

I a using tRest with POST to trigger a job and in response I am getting {"run_id":96,"number_in_job":20}

 

I need to use the "run_id":96 in another GET API to see the result.

 

GET API :- https://abc.net/api/2.0/job/runs/get?run_id=96

Thanks for helping

Sathya

Highlighted
Community Manager

Re: tRestClient - GET - using parameters

Given the JSON you are receiving back, you need to configure your tExtractJsonFields component as in this image....

 

Screenshot 2019-03-07 at 10.50.55.png

Your "JSON Field" value will be the output String column of your tRest component. If you configure the tExtractJsonFields component as above, it will output the values held in the JSON. Then you need to create your URL for your next API call using String concatenation.

Highlighted
Forteen Stars

Re: tRestClient - GET - using parameters


@thinksathya wrote:

Hi Vapukov,

 

Thanks for your response. Can you please explain me a bit as I am very new to ETL  world.

 

I am trying as in the attached pic.

 

I a using tRest with POST to trigger a job and in response I am getting {"run_id":96,"number_in_job":20}

 

I need to use the "run_id":96 in another GET API to see the result.

 

GET API :- https://abc.net/api/2.0/job/runs/get?run_id=96

Thanks for helping

Sathya


as showing by @rhall_2_0 

 

first, you need to extract JSON

then you could use this column value in next component

-----------
Highlighted
Community Manager

Re: tRestClient - GET - using parameters

Sorry @vapukov, I wasn't meaning to steal your thunder. I thought you might be asleep now :-)

Highlighted
Forteen Stars

Re: tRestClient - GET - using parameters

this is global resource - "The early bird catches the worm" :-)

-----------
Highlighted
Four Stars

Re: tRestClient - GET - using parameters

Hi,

 

Thanks for your response. I tried the same but couldn't achieve what I need. Attached the snapshot of what I have done in the name 1,2 and 3.png.

 

I can see the job is running but I can't see the output from the GET API.

 

Thanks

Sathya

Highlighted
Forteen Stars

Re: tRestClient - GET - using parameters

you need to use different connections between components 

Screen Shot 2019-03-08 at 5.14.56 PM.png

Iterate in your case does not transfer the value but do the loop only

 

and in 2nd tRESTClient, you need variable stored by iFlowToIterate, by default, it will be 

(String)globalMap.get("row2.run_id")

row2 - it is name of input connection line for tFlowToIterate, 

 

 

tJavaFlex - do nothing, empty

-----------

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

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog