let // Define the function to accept an optional nextPageToken. fnGetAllJiraIssuesWithAllFields = (optional nextPageToken as text) as list => let // Construct the query parameters record dynamically. // We only add the nextPageToken field if it is not null. QueryOptions = [ jql = "project=PROJECTNAME", fields = "*all", maxResults = "1000" ] & (if nextPageToken <> null then [nextPageToken = nextPageToken] else []), // Call the Web.Contents function with the dynamically built query options. Source = Web.Contents( "https://SERVERNAME.atlassian.net", [ RelativePath = "/rest/api/3/search/jql", Query = QueryOptions ] ), // Process the JSON response. Json = Json.Document(Source), Issues = Json[issues], // Check if there is a next page token. // Record.HasFields is a safe way to check for the field's existence. NextPageToken = if Record.HasFields(Json, "nextPageToken") then Json[nextPageToken] else null, // Perform the recursion if a next page token exists. NextPageIssues = if NextPageToken <> null then @fnGetAllJiraIssuesWithAllFields(NextPageToken) else {}, // Combine the results. AllIssues = Issues & NextPageIssues in AllIssues in fnGetAllJiraIssuesWithAllFields |