Forum Discussion

arvindnsn's avatar
arvindnsn
Contributor
7 years ago

How to loop thru a REST snap

Hello,

I am trying to load transaction data from a REST API end point. The API has pagination as required Input parameter. I am using the REST GET to fetch the data and the Https URL should be as below.

https://xxxxxx–xxx/transactions?datestart=2018-11-19T00:00:00&dateend=2018-11-20T00:00:00&pageSize=1000&pageNo=1.

I am trying to design a process which loops thru till the REST API call returns null data set.

For example, if the above REST URL gives output, I have to call the same URL again with the pageNo input parameter as 2 and if it provides a data set, then 3 and on and on. The loop has to end when the REST API comes out with a null data.

Any help to solve this would be highly appreciated and also would like to know if looping is the only option and right approach.

Thanks
Aravind N

26 Replies

  • Thanks Alan for helping me solve the issue. I really appreciate you taking time to help me solve this.

    • arvindnsn's avatar
      arvindnsn
      Contributor

      It’s in the line of same Topic. But i was trying to see if i can loop thru the REST GET Snap (even using any external code like python).

      • aleung's avatar
        aleung
        Contributor III

        The REST GET have a build in pagination feature. Please review Example #4, 5 & 6 in the REST GET documentation.

  • TimBurns's avatar
    TimBurns
    New Contributor III

    This is interesting, but how is it useful if you need to write the results of a REST call out using another Snap?

    • tlikarish's avatar
      tlikarish
      Employee

      The REST Get snap will output documents, which downstream you could write out to a database, another web service, etc… Could you talk more about what you’re trying to do?

      • sanjaynayak's avatar
        sanjaynayak
        New Contributor III

        Do we have any option to stop iteration after some time to process less volume rather too much.

        Example
        Assume Api has 1000 pages and 1000 times has next = true and Next URL is running.
        it is too much collecting 1000 pages document in rest get and processing next snap and we are getting Snap was aborted and java util concurrent issues etc…
        Is there any option to set “has next”= false explicitly, though API is returning true after 10 iteration so that we can process only 10 pages rather than 1000 pages.

  • TimBurns's avatar
    TimBurns
    New Contributor III

    It looks like the Snap just swallows the errors on the callback URL, so it wasn’t creating documents every time it ran. I fixed the URL and now it is.