I am using the code below to pull items into PowerQuery but I’m only getting project data, not tasks. What needs to be changed to adjust to pull to includes tasks?
let
GetAllTasks = (board as number) =>
let
Key = “KEY”,
Board = Number.ToText(board),
// Function to fetch one page of data
FetchPage = (cursor as nullable text) =>
let
Query = if cursor = null then
// Query to fetch first page of tasks (items) with pagination (100 items at a time)
"{""query"":""query { boards(ids: [" & Board & "]) { items_page (limit: 100) { cursor items { id, name, updated_at, group { title }, column_values { column { title }, text } } } } }""}"
else
// Query for subsequent pages with the cursor for pagination
"{""query"":""query { next_items_page(limit: 100, cursor: \""" & cursor & "\"") { cursor items { id, name, updated_at, group { title }, column_values { column { title }, text } } } }""}",
WebResponse = Web.Contents(
"https://api.monday.com/v2",
[
Headers = [
#"Method" = "POST",
#"Content-Type" = "application/json",
#"Authorization" = "Bearer " & Key,
#"API-Version" = "2025-01"
],
Content = Text.ToBinary(Query)
]
),
JsonResponse = Json.Document(WebResponse),
// Handle different response structure
Data = if cursor = null then JsonResponse[data][boards]{0}[items_page] else JsonResponse[data][next_items_page],
Items = try Data[items] otherwise null,
NextCursor = try Data[cursor] otherwise null,
Result = [Items = Items, Cursor = NextCursor]
in
Result,
// Recursive function to fetch all pages
FetchAllPages = (cursor as nullable text, accumulated as list) =>
let
Page = FetchPage(cursor),
Items = Page[Items],
NextCursor = Page[Cursor],
NewAccumulated = if Items <> null then List.Combine({accumulated, Items}) else accumulated,
Result = if NextCursor <> null then @FetchAllPages(NextCursor, NewAccumulated) else NewAccumulated
in
Result,
// Start fetching from the first page
AllTasks = FetchAllPages(null, {}),
// Convert list of tasks (items) into a table
TaskTable = Table.FromRecords(AllTasks)
in
TaskTable
in
GetAllTasks