How to get a list from all work items from a specific board in TFS API without ID? - rest

I'm using TFS and I would like to get all work items from a specific board. This is how I'm getting the board atm: https://myTFSLink.com/tfs/TPC/ProjectName/MY-BOARD-NAME/_apis/work/boards?api-version=5.1
But nothing about stories/workItems are present in this API request. I know I can get all workItemsRevisions using
GET https://dev.azure.com/{organization}/{project}/_apis/wit/reporting/workitemrevisions?api-version=5.0
but I don't know how I can target this to a specific board :(
I also know that I can get multiple workItems by ID with
GET https://dev.azure.com/fabrikam/_apis/wit/workitems?ids=297,299,300&$expand=all&api-version=5.1
but the ideal would be get all workItems from a specific board as I said in the beginning. Is there any way to do it?

A specific board is corresponding to a Team/Area Path, so you can try to query the work items By Wiql. For example,
POST https://dev.azure.com/{organization}/{project}/{team}/_apis/wit/wiql?api-version=5.1
Request Body:
{
"query": "Select [System.Id], [System.Title], [System.State] From WorkItems Where [System.WorkItemType] = 'PRODUCT BACKLOG ITEM' AND [Area Path] = 'TestCase\\Team1' order by [System.CreatedDate] desc"
}

Related

Query for lastChanged Work Items across several projects

I'm trying to create query that gives me all user stories that has been updated within the last two days, which should be pretty basic within a project with the WorkItem Batch Query.
https://[TENNANT].analytics.visualstudio.com/[PROJECT]/_odata/v1.0/WorkItems
I will need to do an update back on some of the user stories where a certain set of criteria are set (calculations of estimations that I cannot do with the rules in DevOps as they are now)
My challenge is that we have 200 projects, and I need to get the last changed user stories across all these projects. So my current solution is as following:
Do a query for projects with paging of 100 (3 queries as it is now)
Do a query for User Stories with paging of 200 (207 queries as it is now)
Run through all User Stories and update calculations on the once that need (average about 20 per day)
All in all the query will run for about 11 minutes, and then fail due to throttling thresholds on Azure DevOps REST Api.
Is there a way I can query User Stories across all projects in our tenant, or query projects where user stories have been changed since?
LastChanged for projects are not related to underlaying elements, but the project meta data.
Would appreciate every hint there is to find a solution to this :)
Is there a way I can query User Stories across all projects in our
tenant, or query projects where user stories have been changed since?
You can try Azure Devops Rest Api Query By Wiql, so that you can customize the logic via WIQL syntax.
A simple request to return the User Stories which have been changed within the last two days in specific projects:
Post https://dev.azure.com/{OrgName}/_apis/wit/wiql?api-version=6.1-preview.2
Request body if you're querying all projects within the organization:
{
"query": "Select [System.Id] From WorkItems WHERE [System.WorkItemType]='User Story' AND [System.ChangedDate] >= #today-2 ORDER BY [System.ChangedDate] DESC"
}
Request body if you're querying specific projects within the organization:
{
"query": "Select [System.Id] From WorkItems WHERE [System.WorkItemType]='User Story' AND [System.ChangedDate] >= #today-2 And ([System.TeamProject] = 'ProjectName1' OR [System.TeamProject] ='ProjectName2') ORDER BY [System.ChangedDate] DESC"
}

Get all work items from a project azure devops REST API

I'm using Azure devops API to create a notification bot with AWS Lambda node.js. At this moment i need to check if each task work item is attached to a parent user story.
The first step will be to get all the task work items on "given" project, for this step i was reading azure devops api documentation and found this: Work Items - List
The API is asking for the id of the workitem that i want to get, but what if i need all the workitems from "given" project?
GET https://dev.azure.com/{organization}/{project}/_apis/wit/workitems?ids={ids}&api-version=5.1
Or is there any other way to get all the workitem ids from a given project?
You can use Work Items - Get Work Items Batch API that doesn't require ids but the maximum work items in the results are 200.
But, if you need to check Tasks, why you need get all the work items in the project? you can get only the Tasks, with Wiql - Query By Wiql API:
POST https://dev.azure.com/{organization}/{project}/{team}/_apis/wit/wiql?api-version=5.1
In the body make the query:
{
"query": "Select [System.Id], [System.Title], [System.State] From WorkItems Where [System.WorkItemType] = 'Task'"
}
Furthering Shayki's response regarding using a WIQL query, I'd suggest that you can have two birds with one stone here by doing a work item links query that looks for Tasks without a parent User Story:
POST https://dev.azure.com/{organization}/{project}/{team}/_apis/wit/wiql?api-version=5.1
request payload:
{
"query": "SELECT [System.Id] FROM workitemLinks WHERE ([Source].[System.WorkItemType] = 'Task') AND ([System.Links.LinkType] = 'System.LinkTypes.Hierarchy-Reverse') AND ([Target].[System.WorkItemType] = 'User Story') MODE (DoesNotContain)"
}
This way, you won't have to loop through each work item to then check if it has a parent.
Note: the WIQL query limits the results returned to 20K and returns an error if the query results in more work items than that. Further reason to use a query like the above, if applicable.
There is a client for C#:
public IEnumerable<int> GetIdList()
{
var connection = new VssConnection(new Uri("http://yourazuredevopsurl/"), new VssBasicCredential(string.Empty, personalAccessToken));
var workItemTrackingHttpClient = connection.GetClient<WorkItemTrackingHttpClient>();
var wiql = new Wiql
{
Query = $#"Select [System.Id] From WorkItems Where [System.WorkItemType] = 'Test Case'"
};
var worItemsIds = workItemTrackingHttpClient.QueryByWiqlAsync(wiql, "Project name").Result;
return worItemsIds.WorkItems.Select(reference => reference.Id);

Get all items from iteration

I am trying to get all work items from a given iteration. I can filter on TaskType on other fields. But not iteration paths. Am I missing something here?
var body = "{\"query\": \"Select [System.Id], [System.Title], [System.State],[System.IterationPath] From WorkItems Where [System.IterationPath] = 'GAC\\Sprint 10'\"}";
var json = await HTTP.POST("https://xxx.visualstudio.com/_apis/wit/wiql?api-version=5.1", body, personalaccesstoken);
return JsonConvert.DeserializeObject<WorkItemIdList>(json);
I can filter on TaskType on other fields. But not iteration paths.
Does below scripts is what you want?
SELECT [System.Id], [System.Title], [System.WorkItemType], [System.State], [System.IterationPath] FROM workitems WHERE [System.IterationPath] = 'MerConsoleApp\Q4' AND [system.WorkItemType] = 'Bug'
This WIQL can filter the Bug work items which located IterationPath is MerConsoleApp\Q4.
In addition, I saw you are applying this WIQL from api. There's one thing you need pay attention, you may not get exactly work item data if you run WIQL from rest api.
For example, since we specify fields in select, here we can get below data format while we run this WIQL from UI:
But for rest api, we defined and fixed the data structure of the work item as id + url. This means you can only get the satisfied work item id and its url, even if you has specified the [System.Id], [System.Title], [System.WorkItemType], [System.State] in it.

how to get all the Work item for a Iteration path by TFS API?

I am currently using TFS API who's link is https://www.visualstudio.com/en-us/docs/integrate/api/wit/work-items#byids
currently, in my project I want to access all the Workitems who's iteration path= MRI_SCRUM_GIT http://apactfs.cbre.com:8080/tfs/CBRE.APAC.Applications/MRI_SCRUM_GIT/_workitems?_a=edit&id=61092
currently, i am finding a workitem number 6109 by this in postman GET
http://apactfs.cbre.com:8080/tfs/cbre.apac.applications/_apis/wit/workitems/61092?$expand=all&api-version=1.0
You need to execute a query to get all the Work item for a particular Iteration path. After executing a query, get the work items using the IDs that are returned in the query results response. You can get up to 200 work items at a time. Please refer to this article:
https://www.visualstudio.com/en-us/docs/integrate/api/wit/wiql#get-work-items
The sample is as below:
POST http://apactfs.cbre.com:8080/tfs/cbre.apac.applications/_apis/wit/wiql?api-version=1.0
Content-Type: application/json
{
"query": "Select [System.Id], [System.Title], [System.State] From WorkItems Where [System.IterationPath] under 'MRI_SCRUM_GIT'"
}

Creating a VSTS Extension, using WIQL query to grab work item data, can I grab Activity field data?

I'm creating a Visual Studio Team Services extension that in it's current iteration is supposed to display child tasks for development, testing, etc. that were added to a work item. I build a WIQL query to get these tasks and some data about them.
In VSTS (and TFS), tasks have an Activity field, which I want, to differentiate between the different types of tasks (development, testing, etc.). However, I'm finding with the below WIQL query I create, I get the following error: TF51005: The query references a field that does not exist. The error is caused by «[System.Activity]». Is there a way I can get access to the Activity field for those tasks? Or is it just not supported currently?
SELECT [System.Id], [System.WorkItemType], [System.Title],
[System.Activity], [System.State]
FROM WorkItemLinks
WHERE (Source.[System.TeamProject] = 'someProjectID'
AND Source.[System.Id] = someWorkItemID
AND Source.[System.State] <> 'Removed')
AND ([System.Links.LinkType] = 'System.LinkTypes.Hierarchy-Forward')
AND (Target.[System.WorkItemType] = 'Task')
MODE(Recursive)
Working through this I discovered https://marketplace.visualstudio.com/items?itemName=ottostreifel.wiql-editor, which has helped make it alot easier debugging my WIQL query. I highly recommend it to anyone who is new to working with WIQL.
You can create a query with necessary fields in web access, then get detail wiql by using Get a query or folder REST API (add $expand=wiql parameter).
I looked some more and discovered my answer, apparently Microsoft.VSTS.Common.Activity is the field you want to reference to get the activity for the task. I found it here: https://www.visualstudio.com/en-us/docs/work/track/query-numeric. Looks like there's some more information there about some data you can grab, like Microsoft.VSTS.Scheduling.StoryPoints. However it's definitely not a complete list, and I wasn't able to find one. Feel free to comment on this if you know of a complete list of references to use to grab anything you want about a work item!