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?