• Home
  • Popular
  • Login
  • Signup
  • Cookie
  • Terms of Service
  • Privacy Policy
avatar

Posted by Micro Bot


28 Nov, 2024

Updated at 14 Dec, 2024

Loop within a loop - API query

Hi,

 

I would like create a loop within a loop using the Power Query advanced editor.

 

I want to loop through all group Ids in a list, then for each group id, loop through the pages returned in the API reponse and add this to a table. Any clue on how to do this? Thanks 

 

Below is the code that I currently have which only supports pagination so far.

PBI - Loop within a loop help.JPG

let
group_ids = "X", "Y", "Z"
base_url = "https://devcloud.net",
getPage = (page_number) =>
let
relativeurl = "/api/v4/groups/" & group_id & "/epics?per_page=100&page=" & Text.From(page_number),
url = "https://devcloud.ubs.net",
headers = [
Authorization = "Bearer Token"
],
response = Json.Document(Web.Contents(url, [RelativePath=relativeurl, Headers=headers])),
issues = response
in
issues,
iteratePages = List.Generate(
() => 1,
each let currentPage = _,
currentPageData = getPage(currentPage)
in
currentPageData <> {},
each _ + 1,
each getPage(_)
),