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

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

How to loop the trestclient to reach the end of the api page

when i start with the url:"https://flow.pluralsight.com/v3/customer/core/repos/?offset=0"

it gives the data of 100 records like

{
     "count" :   1584 ,
     "previous" :   null ,
     "results" :   [
         {
             "id" :   1 ,
             "project_id" :   1 ,
             "added_by" :   {............... and so on
                                }
                       ]
         }
}
 
in this it also gives the next page value as next
untill next page value becomes null i want to loop my trestclient wit the next url
currently i am just incrementing my offset value in the url
like given in the image
0683p000009M9rl.png
Labels (3)
37 Replies
Anonymous
Not applicable
Author

Firstly i thank you for helping me out......

i have tried but also the same error i.e, Duplicate local variable url

String url = row37.next;// next cannot be resolved or is not a field

tjava component code is

globalMap.put("myUrl","https://flow.pluralsight.com/v3/customer/core/repos/?offset=0");

trestClient component URL is with method GET

((String)globalMap.get("myUrl"))

tjavaFlex component is like

0683p000009M9tr.jpg

 

 

tloop is like 

0683p000009M9hN.jpg

 

Anonymous
Not applicable
Author

OK, there needs to be a tJava before the tLoop. This will be joined to the tLoop using an OnSubJobOk link. This is where this code will go....

 

globalMap.put("myUrl","https://flow.pluralsight.com/v3/customer/core/repos/?offset=0");

The tJava after the tLoop should have no code in it. It is a dummy component simply there to allow you to link to the tRestClient using an OnComponentOK link. Please change the row link to an OnComponentOK link.

 

After the tRestClient, you need to add a tExtractJsonField. This is used to extract the values from the JSON that is returned. I assumed that you would be using this as otherwise you cannot extract the values. You need to extract the "next" element to a column called "next". 

 

This is then linked to the tJavaFlex. Your tJavaFlex code can remain the same but it must be moved to the Main Code section.

The Start Code section is triggered before the component is used and the End Code section is triggered after it has finished processing rows. The Main Code section is processed for every row.

 

This should get you a bit further. 

Anonymous
Not applicable
Author

i am unable get the next from the root 

can you help i have tried this one in textractjson component0683p000009M9h1.jpg

Anonymous
Not applicable
Author

I believe your "Loop Jsonpath query" needs to be "$" and your mapping should be "next"

Anonymous
Not applicable
Author

in the trestclient component  and no errors in the code

i have given url as 

((String)globalMap.get("myUrl"))

and i am getting  an error like this

Spoiler
[statistics] connecting to socket on port 3724
[statistics] connected
Exception in component tRESTClient_2 (AAflowData)
java.lang.RuntimeException: java.lang.NullPointerException
at org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean.createWebClient(JAXRSClientFactoryBean.java:233)
at githubrepodata.aaflowdata_0_1.AAflowData.tRESTClient_2Process(AAflowData.java:1152)
at githubrepodata.aaflowdata_0_1.AAflowData.runJobInTOS(AAflowData.java:1817)
at githubrepodata.aaflowdata_0_1.AAflowData.main(AAflowData.java:1666)
Caused by: java.lang.NullPointerException
at org.apache.cxf.jaxrs.client.WebClient.convertStringToURI(WebClient.java:1236)
at org.apache.cxf.jaxrs.client.WebClient.<init>(WebClient.java:89)
at org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean.createWebClient(JAXRSClientFactoryBean.java:223)
... 3 more
[ERROR]: org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean - java.lang.NullPointerException : null
[statistics] disconnected

 if i give the url in trestclient with "https://flow.pluralsight.com/v3/customer/core/?offset=0" i am able to get only one value

Anonymous
Not applicable
Author

Can you show me all the places that you are setting the globalMap value please? There should be a tJava setting this before the tLoop and then it should be set depending on the value of the "next" value.

Anonymous
Not applicable
Author

I am posting all the components details

 

0683p000009M9iO.jpgtextractjsonfield component0683p000009M9RO.jpgtjava component0683p000009M9Hp.jpgtjavaflex component0683p000009M9WT.jpgtloop component0683p000009M9cS.jpgtrestclient component

Anonymous
Not applicable
Author

The tJava where you are setting the globalMap should not have any code in it. It is a dummy component to simply allow you to connect the OnComponentOk link. You need a tJava with that code in it BEFORE the tLoop

Anonymous
Not applicable
Author

Is it like this the component should 0683p000009M97O.jpg

 

and the remaing compnents data is same

Anonymous
Not applicable
Author

Yes, that looks correct. The tJava_1 should have no code in it.The tRestClient_2 should refer to the globalMap value set in tJava_2. The tExtractJsonFields_2 should extract your data. The tJavaFlex will set your url in the globalMap again...IF a new URL is returned