如何使用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/zh-CN/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}
,其中 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屋!