Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Web API Loop
- (FinalUrl as text) = >
- let
- GetTotalPages = () =>
- let
- Source = Xml.Tables(Web.Contents(FinalUrl & ".xml")),
- #"Attribute:per_page" = Number.From(Source{0}[#"Attribute:per_page"]),
- #"Attribute:per_entries" = Number.From(Source{0}[#"Attribute:total_entries"]),
- Count = Number.RoundUp(#"Attribute:per_entries" / #"Attribute:per_page")
- in Count,
- // Pagination of API Results
- GetJson = (Url as text, Page as number) =>
- let
- RawData = Web.Contents(FinalUrl & ".json",
- [RelativePath="?page=" & Text.From(Page)]),
- Json = Json.Document(Binary.Buffer(RawData))
- in Json,
- GetPage = (Index) =>
- let
- Json = GetJson(FinalUrl, Index)
- in Json,
- Page_Count = GetTotalPages(),
- PageIndices = {1 .. Page_Count},
- Pages = List.Transform(PageIndices, each GetPage(_)),
- Records = List.Union(Pages),
- #"Converted to Table" = Table.FromList(Records, Splitter.SplitByNothing(), null, null, ExtraValues.Error)
- in
- #"Converted to Table"
Advertisement
Add Comment
Please, Sign In to add comment