简体   繁体   中英

How to Get User Story for a Task Using Visual Studio REST API

I'm trying to use Visual Studio's API to gather information about work items for a Visual Studio Online team into an Excel doc. I can get the work items' information as well as whether each item is a User Story, Task, or Bug by using API calls to extract its json fields. However, I can't figure out how to get the "parent" User Story for a Task or a Bug. Eg a task will be within a User Story section on my work board, but I don't see any field that corresponds to that story within the work item's possible json keys.

The keys I can see for a work item are these:

['System.AuthorizedDate',
 'System.WorkItemType',
 'System.Title',
 'System.IterationLevel1',
 'System.IterationLevel2',
 'System.History',
 'System.AreaId',
 'System.NodeName',
 'Microsoft.VSTS.Common.ActivatedDate',
 'System.IterationId',
 'System.IterationPath',
 'System.PersonId',
 'System.AssignedTo',
 'System.AuthorizedAs',
 'System.Id',
 'System.Reason',
 'System.CreatedBy',
 'Microsoft.VSTS.Common.StateChangeDate',
 'Microsoft.VSTS.Common.Priority',
 'System.Watermark',
 'Microsoft.VSTS.Common.ActivatedBy',
 'System.AreaPath',
 'System.State',
 'System.ChangedDate',
 'System.AreaLevel1',
 'System.CreatedDate',
 'System.TeamProject',
 'System.Rev',
 'System.ChangedBy',
 'System.RevisedDate']

None of their values corresponds to anything that matches a User Story's text or provides a url to a User Story's json.

Does anyone know how to get parent (User Story) of a task or a bug using API calls?

Add "expand=all" or "expand=relations" in your request url will show the linked work items and "System.LinkTypes.Hierarchy-Reverse" type point to the Parent work item.

Example:

https://xxxxx.visualstudio.com/defaultcollection/_apis/wit/workitems?ids=47&$expand=relations&api-version=1.0

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM