cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

How to loop thru a REST snap

arvindnsn
Contributor

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 26

I tried constructing the URL in the mapper snap next to REST snap and got the Dynamic URL as $original.original.urlโ€ฆ I also tried using the actual URL (without using any variables, just plain URL as โ€œhttps://example-api.com/transactions?datemin=โ€ฆโ€

Both failed to fetch data from subsequent pages except the first page. The API for the given input parameters fetches close to 2000 records. i tried setting the page size to 10, 50, 100 and 200. But in all the cases, its fetching the data from the first page for whatever the size i set and comes out and finishes the process.

Here is the output structure

{
โ€œPageNoโ€: 5,
โ€œPageSizeโ€: 200,
โ€œItemsโ€: [
{
โ€œTransactionIdโ€: 000000,
โ€œReceiptNoโ€: 000,
โ€œTerminalNameโ€: โ€œxxxxxโ€,
โ€œTerminalNoโ€: 00000,
โ€œDateโ€: โ€œ2018-12-16T18:07:03โ€,
โ€œTaxTotalโ€: 999,
โ€œTransactionItemsโ€: [
{
โ€œItemIDโ€: 999,
โ€œProductIDโ€: 999,
โ€œQuantityโ€: 1,
โ€œTotalโ€: 5,
โ€œTotalGrossโ€: 4.55,
โ€œTotalTaxโ€: 0.45
}
],
โ€œOrderTypeIDโ€: 0
}

arvindnsn
Contributor

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

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?

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?