TFS Rest api - 通过单个查询展开所有相关数据

TFS Rest api - Expand all the related data by a single query

我正在尝试从 TFS rest api 获取所有错误报告(不仅是我的所有其他错误报告)。我通过 GET 操作获取数据,但它只显示分配给我。所以,现在我在查询中使用 post 操作。出于身份验证目的,我使用的是 ntlm 插件。以下是我的代码

 var ntlm = require('ntlm')
   , ntlmrequest = require('request').defaults({
     agentClass: require('agentkeepalive').HttpsAgent
   });
    var url = "https://{instance}/tfs/DefaultCollection/{project}/_apis/wit/wiql?$expand=clauses&api-version=1.0"
      , domain = 'myDomain'
      , username = 'userName'
      , password = 'pwd'
      , hostname ='host';

    var query = "Select [State], [Title] From WorkItems Where [System.WorkItemType] = 'Bug' AND [System.State] <> 'Closed' AND [System.State] <> 'Removed' Order By [State] Asc";


    ntlmrequest(url, {
            headers: {
                'Authorization': ntlm.challengeHeader(hostname, domain)
            }
        }, function(err, ntlmres) {
                var options = {
                    method: 'post',
                    body: {query:query},
                    json: true,
                    url: url,
                    headers: {
                        'Authorization': ntlm.responseHeader(ntlmres, url, domain, username, password),
                        'Content-Type': 'application/json'
                    }
                }
                ntlmrequest(options, function (err, ntlmres, body) {
                    if(err)
                    res.json({result:'failed',message:err.message});

                    res.json({result: "success", data: ntlmres.body.workItems});
            });
    });

上面的代码return下面的结果

{
    "result": "success",
    "data": [
        {
            "id": 8254,
            "url": "https://{instance}/tfs/DefaultCollection/_apis/wit/workItems/8254"
        },
        {
            "id": 8375,
            "url": "https://{instance}/tfs/DefaultCollection/_apis/wit/workItems/8375"
        } ]
}       

我的要求是 get/expand 结果中可用的 url 的数据,而不是 url。是否可以从单个查询中获取所有这些数据。

终于找到解决办法了。我刚刚将 url 更改为

var url="https://{instance}/tfs/DefaultCollection/{project}/_api/_wit/query?__v=1"

并如下所示编辑正文参数

body: {wiql:query}

它也在加载相关数据。数据格式如下图

"body"{
    "payload" : {
        "columns" : [
                        System.Id,
                        System.State,
                        System.WorkItemType
                    ],
        "rows" :    [
                        [
                            8050,
                            Resolved,
                            Bug
                        ],
                        [
                            8051,
                            Resolved,
                            Bug
                        ]
                    ]
                }
}