1
votes

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}

The example given was

https://fabrikam.visualstudio.com/DefaultCollection/Fabrikam-Fiber-Git/_apis/wit/wiql?api-version=1.0

But this doesn't show how or where to store the query.

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.

1

1 Answers

2
votes

The rest endpoint for executing query is a POST method and expects a JSON body to contain a key query.

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/jsonand the body of the request in the below format.

{
  "query": string
}

Example:

POST https://fabrikam.visualstudio.com/DefaultCollection/Fabrikam-Fiber-Git/_apis/wit/wiql?api-version=1.0
Content-Type: application/json

Body:

{
  "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)"
}