Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
See why IDC MarketScape names Qlik a 2025 Leader! Read more
cancel
Showing results for 
Search instead for 
Did you mean: 
SR2210
Contributor
Contributor

loop variables in tREST POST method

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\"}"

 

0683p000009MZk3.jpg

 

 

 

 

 

 

 

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!

 

 

Labels (5)
1 Solution

Accepted Solutions
manodwhb
Champion II
Champion II

@SR2210 , your job design should be like below.

0683p000009MZpX.png

View solution in original post

19 Replies
manodwhb
Champion II
Champion II

@SR2210 , you can use in tfixedflow have all three body and iterate by using tFlowtoIterate and use tjava component to print that body using a global variable and call the tRest component.

 

tfixedflowInput>>Main>>tFlowtoIterate>>Iterate>>tjava>>on component Ok>>tRest

SR2210
Contributor
Contributor
Author

Hi @manodwhb, thank you for your reply.

 

This is my first time using tfixedflowinput, can you help to explain which mode should i select here and how do i define all three body in the component? Also, how do i call that in tREST HTTP Body section?

 

 

0683p000009Ma5O.jpg

 

 

 

 

 

 

 

really appreciate your help, thank you in advance

manodwhb
Champion II
Champion II

@SR2210 , use Inline content and check the below link to more about this component.

https://help.talend.com/reader/mjoDghHoMPI0yuyZ83a13Q/1UUiC6QzuUN4eQE4niDz4w

manodwhb
Champion II
Champion II

@SR2210 , your job design should be like below.

0683p000009MZpX.png

SR2210
Contributor
Contributor
Author

Hi @manodwhb,

 

i'm not sure if i'm doing this correctly.  I managed to print the body in tJava component and link it to tREST as below;

 

0683p000009Ma67.jpg

 

 

 

 

 

 

 

 

is that how i should call the body in HTTP Body section in tREST? If yes, when i run the job i got a "204" error that means no content. I'm sure that the data is there as i have tried to define the body directly in tREST and the data is shown correctly. 

 

Please assist, thank you

SR2210
Contributor
Contributor
Author

@manodwhb, i've tried as below but got the same "204" error.

 

tJava component

0683p000009Ma1X.jpg

 

 

 

 

 

 

 

 

tRest component

0683p000009Ma6C.jpg

manodwhb
Champion II
Champion II

@SR2210 , print the body in java and check that is that correct on or not which you were passing. bypassing same body from postman is it working?

SR2210
Contributor
Contributor
Author

Hi @manodwhb, I've print the body and it's showing correct as what i defined in tfixedflowinput. i tried to use the same body in tREST and postman and it's working

manodwhb
Champion II
Champion II

@SR2210 ,then it could be a body that you need to pass in ", please check.