Forum Discussion
REST api request and loop by offset until no further records found
- 6 years ago
First, check the request metadata to see if it tells you how many records there are.
E.g.
let
webData = Web.Contents("https://..."),
webMetadata = Value.Metadata(webData)
in
webMetadata
For doing a while loop in power you can instead use recursive functions like:
let my_func = (startIndex) => let webRequest = Web.Contents(...), ...., results = ..., numRecords = ...., if numRecords = page_size then results & my_func(startIndex + page_size) else results in my_func(0)Note the @ used for recursion
The requests you are making are:
0 - 250
250 - 500
750 - 1000
1500 - 1750
...
Instead of incrementing by 250 each time, you are incrementing by 250, 500, 750, ect...
As I mentioned, you don't need counter, only offset.
Thanks for the feedback artemus!
but it's working as expected. The interface has two additional parameter: limit and offset.
The offset has to increase as the offset number is used to start by each request.
1 request: offset = 0
2 nd request offset =250
3 rd request offset = 500
....
This is woking as the max. limit is 250 by default.
Anyhow, the function is now working as expected and i've compiled a custom function for reuse in other cases.
//joerg