You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Jira Atlassian API分页实现求助:需获取1500条结果

在Power Query中实现Jira API分页获取1500条结果

要在你的Power Query代码中实现分页,核心逻辑是循环调用API,每次更新startAt参数,直到获取到目标条数或所有结果。以下是具体实现:

核心思路

  • 设定每页最大请求条数(Jira API默认上限为100,用这个值能减少请求次数)
  • 编写递归函数,每次请求后检查isLast字段或已获取的结果总数,决定是否继续请求下一页
  • 合并所有分页返回的values数据,再进行后续的表转换和类型定义

完整代码

let
    // 配置基础参数
    baseUrl = "*你的API连接URL*",
    maxPerPage = 100,
    targetTotal = 1500,
    headers = [Accept="application/json"],

    // 定义递归分页函数
    GetPages = (startAt as number, accumulated as list) as list =>
        let
            // 拼接带分页参数的请求URL
            url = baseUrl & "&startAt=" & Text.From(startAt) & "&maxResults=" & Text.From(maxPerPage),
            // 发起API请求
            response = Json.Document(Web.Contents(url, [Headers=headers])),
            // 提取当前页的数据列表
            currentValues = response[values],
            // 累计已获取的数据
            newAccumulated = accumulated & currentValues,
            // 计算已获取的总条数
            totalCollected = List.Count(newAccumulated),
            // 判断是否需要继续请求:未达目标条数且不是最后一页
            shouldContinue = not response[isLast] and totalCollected < targetTotal
        in
            if shouldContinue then
                GetPages(startAt + maxPerPage, newAccumulated)
            else
                newAccumulated,

    // 初始调用:从第0条开始,累计列表为空
    allData = GetPages(0, {}),

    // 将合并后的列表转换为表格
    #"Converted to Table" = Table.FromList(allData, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    // 展开记录字段(根据实际返回的字段结构调整)
    #"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", 
        Record.FieldNames(allData{0}), 
        Record.FieldNames(allData{0})),
    // 定义字段数据类型(按需调整)
    #"Changed Type" = Table.TransformColumnTypes(#"Expanded Column1", {
        {"id", Int64.Type},
        {"key", type text},
        {"fields", type record}
    })
in
    #"Changed Type"

注意事项

  • 替换代码中的*你的API连接URL*为实际的Jira API查询地址(比如搜索问题的/rest/api/3/search接口,需带上jql等必要查询参数)
  • 展开字段时,可根据实际需求手动指定要展开的字段名,替代Record.FieldNames(allData{0})
  • 如果Jira返回的总结果数不足1500,代码会自动在最后一页停止请求

内容的提问来源于stack exchange,提问作者Rebecca

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 10:20:25