Forum Discussion
jtpiazzamn
2 years agoHelper I
Power BI rest API pagination error in query
I'm trying to figure out why pagination is not working - I copied this from another environment. Its getting stopped in the page # In Power Query I have the following setup API Qu...
amitchandak
2 years agoSuper User
jtpiazzamn , refer if these two can help
https://medium.com/@marktiedemann/how-to-do-pagination-in-power-query-430460c17c78
https://datachant.com/2016/06/27/cursor-based-pagination-power-query/
jtpiazzamn
2 years agoHelper I
Thank you for your response.
The one that seemed like it would work for me is the Facebook example (the site medium.com site won't work because my site doesn't support $stop etc). However, I don't know how to incorporate the page number into the URL using the facebook example.
the format for my API has the page # within the URL ie:
https://website.com/api/v4/?limit=1000&page=1&include=id,name
========================
let
fbPage = "MicrosoftBI", // You can type your facebook page here
iterations = 10, // Number of iterations
url =
fbPage &
"/posts?limit=100&fields=message,created_time" &
"&access_token=[<strong>Your access token here</strong>]",
// FnGetPage is the function that performs an import of single page.
// The page consists of a record with the data and the URL in the
// fields data and next. Other Web APIs hold the data and cursor in different formats
// but the principle is the same.
FnGetOnePage =
(url) as record =>
let
Source = Json.Document(Web.Contents(url)),
data = try Source[data] otherwise null,
next = try Source[paging][next] otherwise null,
res = [Data=data, Next=next]
in
res,
GeneratedList =
List.Generate(
()=>[i=0, res = FnGetOnePage(url)],
each [i]<iterations and [res][Data]<>null,
each [i=[i]+1, res = FnGetOnePage([res][Next])],
each [res][Data]),
#"Converted to Table" = Table.FromList(GeneratedList, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Expanded Column2" = Table.ExpandListColumn(#"Converted to Table", "Column1"),
#"Expanded Column3" = Table.ExpandRecordColumn(#"Expanded Column2", "Column1", {"message", "created_time", "id"}, {"message", "created_time", "id"})
in
#"Expanded Column3"