devops-rest APi-$ expand不适用于“工作项-批量获取工作项”

问题描述 投票:1回答:1

我想访问选定工作项中的一些数据。下面是我的工作代码。

function postApiData(ApiUrl, responseBody, token) {
            var res = '';
            $.ajax({
                type: 'POST',
                async: false,
                url: ApiUrl,
                contentType: 'application/json',
                data: JSON.stringify(responseBody),
                cache: false,
                dataType: 'json',
                beforeSend: function (xhr) {
                    xhr.setRequestHeader("Authorization", "Basic " + btoa("" + ":" + _token));
                },
            }).done(function (data) {
                res = data;
            });
        return res;
    };

 var d = {
                    "ids": itemlist,
                    "fields": ["System.Id", "System.WorkItemType", "System.Title", "System.AssignedTo", "System.State", "System.Tags", "cust.PID", "cust.Product", "cust.ReleasedToProduction"]
                };
                var itemdata = postApiData('https://dev.azure.com/COMP/products/_apis/wit/workitemsbatch?$expand=relations&api-version=5.1', d, '');

但是,$ expand不能在这里建立关系。查询给出结果,并且始终忽略$ expand。

我也曾尝试在请求正文中传递$ expand,但它也不起作用。有人可以在这里指导吗?

javascript ajax azure-devops devops azure-devops-rest-api
1个回答
0
投票

这是因为如果expand值为fields,则expand参数不能与relations参数一起使用。

您可以在Postman中使用您的请求正文执行此api。您会清楚地知道为什么不能应用它。

enter image description here


要使用您的API,如果您在请求正文中指定fields,则不应再使用expand,反之亦然。这是设计好的,已经被hardcoded到我们的脚本中。如果不是$expandNone,则不允许另一个Links值。

对于$expand的5个值(NoneRelationsFieldsLinksAll),只有NoneLinks可以在API中成功使用fields。这是一条通用规则,适用于所有API,包括此one

© www.soinside.com 2019 - 2024. All rights reserved.