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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With