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

Azure DevOps getWorkItems API无法返回全部工作项字段求助

Azure DevOps扩展调用getWorkItems无法获取完整字段,指定字段返回空值

我的问题和某旧帖情况类似,但旧方案无效,且帖子已发布2.5年,推测API已更新,故重新提问。

我的manifest配置

{
  "targets": [
    {
      "id": "Microsoft.VisualStudio.Services"
    }
  ],
  "scopes": [
    "vso.work_full",
    "vso.project_manage",
    "vso.profile",
    "vso.graph",
    "vso.identity"
  ],
  "categories": [
    "Azure Boards"
  ],
  "demands": [
    "api-version/6.0"
  ],
...
  "contributions": [
    {
      "id": "",
      "type": "ms.vss-web.hub",
      "targets": [
        "ms.vss-work-web.work-hub-group"
      ]
    }
  ]
}

代码实现

import { getClient } from 'azure-devops-extension-api';
import { WorkItem, WorkItemExpand, WorkItemTrackingRestClient } from 'azure-devops-extension-api/WorkItemTracking';

export class WorkItemsService {
  ...
  static async getWorkItems(ids: number[], projectId: string): Promise<WorkItem[]> {
    const client = getClient(WorkItemTrackingRestClient);
    ...
    client.getWorkItems(ids.slice(...), projectId, undefined, undefined, WorkItemExpand.All));
    ...
  }
}

已执行的操作

  • 使用WorkItemTrackingRestClient的getWorkItems方法
  • 请求中设置WorkItemExpand.All
  • 请求未指定任何字段名
  • manifest中配置了vso.work_full权限

问题现象

调用后仅返回以下字段:

"System.Id": "",
"System.AreaId": "",
"System.AreaPath": "",
"System.TeamProject": "",
"System.NodeName": "",
"System.AreaLevel1": "",
"System.Rev": "",
"System.AuthorizedDate": "",
"System.RevisedDate": "",
"System.IterationId": "",
"System.IterationPath": "",
"System.IterationLevel1": "",
"System.IterationLevel2": "",
"System.WorkItemType": "",
"System.State": "",
"System.Reason": "",
"System.AssignedTo": "",
"System.CreatedDate": "",
"System.CreatedBy": "",
"System.ChangedDate": "",
"System.ChangedBy": "",
"System.AuthorizedAs": "",
"System.PersonId": "",
"System.Watermark": "",
"System.CommentCount": "",
"System.Title": "",
"Microsoft.VSTS.Common.StateChangeDate": "",
"Microsoft.VSTS.Common.ActivatedDate": "",
"Microsoft.VSTS.Common.ActivatedBy": "",
"Microsoft.VSTS.Common.Priority": "",
"System.Parent": ""

但发现一个奇怪的现象:把返回结果中ApiWorkItem._links.fields对应的URL在浏览器打开,能拿到包含所有需要字段(比如Microsoft.VSTS.Scheduling.xxxx系列字段)的完整数据。

尝试将字段参数从undefined改为指定字段(比如Microsoft.VSTS.Scheduling.Effort),代码如下:

client.getWorkItems(ids.slice(...), projectId, ['Effort']);

但返回结果中该字段为空。

我不想通过数百次单独API调用去获取每个工作项的完整数据,请问我到底遗漏了什么配置或操作?

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.20 11:54:25