如何使用 VSO/VSTS Rest API 执行自定义查询? [英] How to execute Custom Query using VSO/VSTS Rest API?
问题描述
我希望在使用 REST API 执行自定义 VSO 查询时得到一些帮助.但是我在构建 URL 时遇到了问题.我一直在使用以下文档来构建我想要的.
I was hoping for some help executing a Custom VSO query using the REST API. But I am having trouble constructing the URL. I have been using the Following Documentation to construct what I want.
https://www.visualstudio.com/en-us/integrate/api/wit/wiql
我的问题是我不确定如何或在哪里存储查询本身.
My issue is that I am not sure how or where to store the query it self.
https://{instance}/defaultcollection/[{project}/]_apis/wit/wiql?api-version={version}
https://{instance}/defaultcollection/[{project}/]_apis/wit/wiql?api-version={version}
给出的例子是
但这并没有显示如何或在哪里存储查询.
But this doesn't show how or where to store the query.
我已经能够使用存储查询执行相同的查询,但是,结果不会返回我在 VSO 中的查询中设置的列.
I have been able to perform the same query using a stored query, however, the results don't return the columns I set up in the query in VSO.
推荐答案
执行查询的其余端点是一个 POST 方法,并期望 JSON 正文包含一个键 query
.
The rest endpoint for executing query is a POST method and expects a JSON body to contain a key query
.
因此要执行自定义查询,您将对 https://{instance}/defaultcollection/[{project}/]_apis/wit/wiql?api-version={version}<进行 POST 调用/code> 将
content-type
标头设置为 application/json
和以下格式的请求正文.
So to execute a custom query, you will do a POST call to https://{instance}/defaultcollection/[{project}/]_apis/wit/wiql?api-version={version}
with content-type
header set to application/json
and the body of the request in the below format.
{
"query": string
}
示例:
POST https://fabrikam.visualstudio.com/DefaultCollection/Fabrikam-Fiber-Git/_apis/wit/wiql?api-version=1.0
Content-Type: application/json
身体:
{
"query": "Select [System.WorkItemType],[System.Title],[System.State],[Microsoft.VSTS.Scheduling.Effort],[System.IterationPath] FROM WorkItemLinks WHERE Source.[System.WorkItemType] IN GROUP 'Microsoft.RequirementCategory' AND Target.[System.WorkItemType] IN GROUP 'Microsoft.RequirementCategory' AND Target.[System.State] IN ('New','Approved','Committed') AND [System.Links.LinkType] = 'System.LinkTypes.Hierarchy-Forward' ORDER BY [Microsoft.VSTS.Common.BacklogPriority] ASC,[System.Id] ASC MODE (Recursive, ReturnMatchingChildren)"
}
这篇关于如何使用 VSO/VSTS Rest API 执行自定义查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!