Reputation: 5213
According to documentation you can get work items as following:
GET https://dev.azure.com/{organization}/{project}/_apis/wit/workitems?ids={ids}&api-version=5.1
However you need to provide ids for all the workitems you want. What if you just want all workitems? If I skip Ids I get following:
Response status code does not indicate success: 404 (Not Found).
OK I am getting a little closer thanks to some of the repsonses:
var uri = "https://dev.azure.com/xx";
var personalAccessToken = "xx";
var project = "GAC";
VssBasicCredential credentials = new VssBasicCredential("", personalAccessToken);
Wiql wiql = new Wiql()
{
Query = "Select [State], [Title],[Remaining Work] From WorkItems Where [Work Item Type] = 'Bug' OR [Work Item Type] = 'Task' And [System.TeamProject] = '" + project+"'"
};
//create instance of work item tracking http client
using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(new Uri(uri), credentials))
{
//execute the query to get the list of work items in the results
WorkItemQueryResult workItemQueryResult = workItemTrackingHttpClient.QueryByWiqlAsync(wiql).Result;
//some error handling
if (workItemQueryResult.WorkItems.Count() != 0)
{
foreach (IEnumerable<WorkItemReference> batch in workItemQueryResult.WorkItems.Batch(100))
{
var workItemIds = batch.Select(p => p.Id).ToArray();
var workItems = workItemTrackingHttpClient.GetWorkItemsAsync(workItemIds, expand: WorkItemExpand.All).Result;
}
}
}
However I dont get information around what I am primary looking for like Completed, Remaining works etc. Any pointers?
Upvotes: 2
Views: 8903
Reputation: 314
you need to create a query to fetch work items programmatically.
Apart from the core system fields, the fields are very dependent from the process template (Agile, Scrum,...) used. You can even have custom fields. So how to find out the name, or more specific, the ReferenceName, in order to query it?
using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(uri, credentials))
{
List<WorkItemField> fieldsQuery = await workItemTrackingHttpClient.GetFieldsAsync(_project, null, null, System.Threading.CancellationToken.None);
if (fieldsQuery.Count() != 0)
{
foreach (var fieldItem in fieldsQuery)
{
Console.WriteLine("{0} / {1}", fieldItem.Name, fieldItem.ReferenceName);
}
}
}
Upvotes: 1
Reputation: 41545
You don't write correctly the "Remaining Work" field, you should give the field reference name and not the label.
The reference name for Remaining Work is: Microsoft.VSTS.Scheduling.RemainingWork
.
So in your query use it:
Query = "Select [System.Id], [System.State]. [System.Title], [Microsofy.VSTS.Scheduling.RemainingWork] FROM ..."
You can see all the fields with their reference name in this url (api):
https://dev.azure.com/{your-organization-name}/_apis/wit/fields
Upvotes: 0