Forum Discussion
REST API Paging Power Query
- 5 years ago
Based on the information you provided here is one possible implementation. It is not optimized (page 1 is fetched twice) but it works.
You need two parameters - APIKey and Limit . The Limit parameter allows you to control how many items you want to retrieve in each web call.
let Source = Json.Document(Web.Contents("https://api.weasy.io/v1/catalog?X-API-KEY=" & APIKey & "&limit=" & Limit)), pages = {1..Source[paging][totalpages]}, #"Converted to Table" = Table.FromList(pages, Splitter.SplitByNothing(), null, null, ExtraValues.Error), #"Changed Type" = Table.TransformColumnTypes(#"Converted to Table",{{"Column1", type text}}), #"Added Custom" = Table.AddColumn(#"Changed Type", "Data", each Json.Document(Web.Contents("https://api.weasy.io/v1/catalog?X-API-KEY=" & APIKey & "&limit=" & Limit & "&page=" & [Column1]))), #"Expanded Data" = Table.ExpandRecordColumn(#"Added Custom", "Data", {"items"}, {"items"}), #"Expanded items" = Table.ExpandListColumn(#"Expanded Data", "items") in #"Expanded items"
This line
Result = Table.RemoveLastN(ToTable,1),
is not used subsequently. Is that intentional?
Without details on how your API's pagination works it is hard to give you advice.
- lbendlin5 years agoSuper User
One (or all) of these:
- the API's documentation
- the output of the first call
- a sample API key
- lbendlin5 years agoSuper User
Based on the information you provided here is one possible implementation. It is not optimized (page 1 is fetched twice) but it works.
You need two parameters - APIKey and Limit . The Limit parameter allows you to control how many items you want to retrieve in each web call.
let Source = Json.Document(Web.Contents("https://api.weasy.io/v1/catalog?X-API-KEY=" & APIKey & "&limit=" & Limit)), pages = {1..Source[paging][totalpages]}, #"Converted to Table" = Table.FromList(pages, Splitter.SplitByNothing(), null, null, ExtraValues.Error), #"Changed Type" = Table.TransformColumnTypes(#"Converted to Table",{{"Column1", type text}}), #"Added Custom" = Table.AddColumn(#"Changed Type", "Data", each Json.Document(Web.Contents("https://api.weasy.io/v1/catalog?X-API-KEY=" & APIKey & "&limit=" & Limit & "&page=" & [Column1]))), #"Expanded Data" = Table.ExpandRecordColumn(#"Added Custom", "Data", {"items"}, {"items"}), #"Expanded items" = Table.ExpandListColumn(#"Expanded Data", "items") in #"Expanded items"- HugoAPereira5 years agoHelper I
Is perfect! It worked the first time, it has no errors and it was extraordinary support. Thank you very much.