Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

List.Generate - Connect to REST API without Total Number of Pages and Total Number of Entries

Hello Guys,

 

I'm trying to get data from a REST API that doesn't have total number of pages or total number of entries.

I have search on internet for answer but none fit for my challenge, so I came here to get sugestions.

So, the first part I got it. I made a funciont name "GetPageClientes",

 

= (page as text) =>
let
Source = try Json.Document(Web.Contents("https://api.mysite.io/v2/customers?page=" & page & "&limit=1000", [Headers=[Authorization="Bearer NTg***********"]])) otherwise [customers=null],
#"Converted to Table" = Table.FromRecords({Source})
in
#"Converted to Table"

 

 

and after some tentatives I got the total number of pages, in the case, 8 pages.

 

In the sequence, I looked for List.Generate

 

= List.Generate(() => [result = try GetPageClientes("1") otherwise null, n=1],
each [result]<>null,
each [result = try GetPageClientes([n] + 1) otherwise null, n=[n]+1],
each [result])

 

to list everypage together, but It's not easy for me and not work as intended as well.

 

So, if anyone could help, I will appreciate.

--

Thank all.

Alexandre.

4 Replies