Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi,
I have a job to extract data from an API and i'm using tREST component with a POST method.
These are the sample data from my API;
{ "data": [ { "name": "Lisa", "product": "product1", "unit": "unit1", },
{ "name": "Lisa", "product": "product1", "unit": "unit2", },
{ "name": "Lisa", "product": "product1", "unit": "unit3", }
] }
so currently what i'm doing is i have 3 tREST component in my job to call all the data, each component has different value in the HTTP Body as below;
tREST_1 : "{\"name\":\"Lisa\",\"product\":\"P1\",\"unit\":\"unit1\"}"
tREST_2: "{\"name\":\"Lisa\",\"product\":\"P1\",\"unit\":\"unit2\"}"
tREST_3: "{\"name\":\"Lisa\",\"product\":\"P1\",\"unit\":\"unit3\"}"
my question is, is it possible to loop the unit instead of defining one by one unit in 3 different tREST component? is there any way that i can only use 1 tREST component but able to extract data for all units?
please let me know if i need to explain in detail, thanks!
@SR2210 , if you have access to the API, you can check payload has passed from Talend in the backend.
@manodwhb it's not working..
@SR2210, Great.
@manodwhb sorry if you missed my message, i was saying it is not working. i think that the ((String)globalMap.get("body")) in my tREST fails to get the value from tJava. i have tried with "" and without still it's showing the same error
@SR2210 , can you check in the backend to that API what json payload coming to API?
@SR2210, is that api can be tested with any bodayone? and what was payload you set in tfixedflow input?show that payload.
@SR2210 , when you pass below body it was working right in trest component? if yes you need to check that in tfixedflow are you passing the same way or not if yes you are passing you need to check the api url is the same are you using.
"{\"name\":\"Lisa\",\"product\":\"P1\",\"unit\":\"unit1\"}"
@manodwhb okay it's working now. what i did was remove all the \ in the body and remove tJava component. tFlowToIterate is linked directly to tREST.
in tfixedflowinput i define it like this;
{"name":"Lisa","product":"P1","unit":"unit1"} instead of "{\"name\":\"Lisa\",\"product\":\"P1\",\"unit\":\"unit1\"}"
@manodwhb wrote:
@SR2210 , when you pass below body it was working right in trest component? if yes you need to check that in tfixedflow are you passing the same way or not if yes you are passing you need to check the api url is the same are you using.
"{\"name\":\"Lisa\",\"product\":\"P1\",\"unit\":\"unit1\"}"
Thank you for your help
@SR2210 , i have asked to use tjava to print the payload before passing to api to know that are you passing correctly or not.