I'm looking to build some tools to query a team's sprint's current work items. I'm not sure how to do that given an organization, project, and team. I can seem to get the current iteration by making this call:
https://dev.azure.com/{org}/{project}/{{team}/_apis/work/teamsettings/iterations?$timeframe=current&api-version=5.1
it returns something like this:
{
"count": 1,
"value": [
{
"id": "8c15e886-ece7-49ce-ab5a-4090aefb5ce2",
"name": "Sprint 1",
"path": "Red Kitten Matrix\\Sprint 1",
"attributes": {
"startDate": null,
"finishDate": null,
"timeFrame": "current"
},
"url": "https://dev.azure.com/chrisdevopsprojects/e8d05711-3014-4ba7-82b7-ab6829c455dc/aed68f47-9035-4af5-9b0d-b0c19b4e9e9e/_apis/work/teamsettings/iterations/8c15e886-ece7-49ce-ab5a-4090aefb5ce2"
}
]
}
So i can get pointer to the current team's sprint but how do you return all of a sprints work items and tasks within them?
I'm not seeing any information here:
Thanks!
EDIT:
So I've found a Work Item Query Language (WIQL... cause why not guess) query that works when I invoke it in devops in the UI, and will kind of work through the rest APIs but it will cause me to make a bunch of ajax requests to pull everything back. Please let me know if there is a simpler way to get this.
Here is my WIQL:
SELECT
[System.Id],
[System.WorkItemType],
[System.Title],
[System.AssignedTo],
[System.State],
[System.Tags]
FROM workitemLinks
WHERE
(
[Source].[System.TeamProject] = @project
AND [Source].[System.WorkItemType] <> 'Task'
AND [Source].[System.State] <> ''
AND [Source].[System.IterationPath] = @currentIteration('[Red Kitten Matrix]\Red Kitten Matrix Team <id:aed68f47-9035-4af5-9b0d-b0c19b4e9e9e>')
)
AND (
[Target].[System.TeamProject] = @project
AND [Target].[System.WorkItemType] <> ''
)
ORDER BY [System.Id]
MODE (MayContain)
It returns this pretty result in the UI:
But when i try to do that through the apis via this endpoint: https://dev.azure.com/chrisdevopsprojects/Red%20Kitten%20Matrix/Red%20Kitten%20Matrix%20Team/_apis/wit/wiql?api-version=5.1
posting this body:
{
"query": "SELECT [System.Id], [System.WorkItemType], [System.Title], [System.AssignedTo], [System.State], [System.Tags] FROM workitemLinks WHERE ( [Source].[System.TeamProject] = @project AND [Source].[System.WorkItemType] <> 'Task' AND [Source].[System.State] <> '' AND [Source].[System.IterationPath] = @currentIteration('[Red Kitten Matrix]\\Red Kitten Matrix Team')) AND ([Target].[System.TeamProject] = @project AND [Target].[System.WorkItemType] <> '' ) ORDER BY [System.Id] MODE (MayContain)"
}
I get the response shaped like this:
{
"queryType": "oneHop",
"queryResultType": "workItemLink",
"asOf": "2020-04-28T03:00:48.353Z",
"columns": [
{
"referenceName": "System.Id",
"name": "ID",
"url": "https://dev.azure.com/chrisdevopsprojects/_apis/wit/fields/System.Id"
},
{
"referenceName": "System.WorkItemType",
"name": "Work Item Type",
"url": "https://dev.azure.com/chrisdevopsprojects/_apis/wit/fields/System.WorkItemType"
},
{
"referenceName": "System.Title",
"name": "Title",
"url": "https://dev.azure.com/chrisdevopsprojects/_apis/wit/fields/System.Title"
},
{
"referenceName": "System.AssignedTo",
"name": "Assigned To",
"url": "https://dev.azure.com/chrisdevopsprojects/_apis/wit/fields/System.AssignedTo"
},
{
"referenceName": "System.State",
"name": "State",
"url": "https://dev.azure.com/chrisdevopsprojects/_apis/wit/fields/System.State"
},
{
"referenceName": "System.Tags",
"name": "Tags",
"url": "https://dev.azure.com/chrisdevopsprojects/_apis/wit/fields/System.Tags"
}
],
"sortColumns": [
{
"field": {
"referenceName": "System.Id",
"name": "ID",
"url": "https://dev.azure.com/chrisdevopsprojects/_apis/wit/fields/System.Id"
},
"descending": false
},
{
"field": {
"referenceName": "System.Id",
"name": "ID",
"url": "https://dev.azure.com/chrisdevopsprojects/_apis/wit/fields/System.Id"
},
"descending": false
}
],
"workItemRelations": [
{
"rel": null,
"source": null,
"target": {
"id": 6,
"url": "https://dev.azure.com/chrisdevopsprojects/_apis/wit/workItems/6"
}
},
{
"rel": "System.LinkTypes.Hierarchy-Forward",
"source": {
"id": 6,
"url": "https://dev.azure.com/chrisdevopsprojects/_apis/wit/workItems/6"
},
"target": {
"id": 10,
"url": "https://dev.azure.com/chrisdevopsprojects/_apis/wit/workItems/10"
}
},
...
So it looks like it's not returning the columns I'm specifying in my WIQL, and I'll have to turn around and query the work items api for each work item id returned from this query. I'd like to avoid making 20+ rest calls to resolve the data I want. Is there a better approach?
Thanks