3

I'm using TFS REST API and am trying to retrieve work items & their child items by title (parent's title is the parameter). I can't find a way to retrieve these linked items using TFS REST API.

This is what I've tried. First I query for the work items by title:

URI = http://[tfspath]/_apis/wit/wiql?api-version=1.0
query = SELECT * FROM WorkItem WHERE [System.Title] = 'some title'

The above returns me an object WorkItems which has only the ID/URL of the matching work item. Then, I use the returned ID on the query below (lets say the id is 1234):

URI = http://[tfspath]/_apis/wit/workitems/1234?fields=System.Title&api-version=1.0

This returns the title of the item & other fields I might include on the fields list. However, I cannot find a way to include the child items in the returns. I've tried including System.RelatedLinks but this does not change the returned fields. Example:

URI = http://[tfspath]/_apis/wit/workitems/1234?fields=System.Title,System.RelatedLinkCount,System.RelatedLinks&api-version=1.0

Returns

"fields":{"System.RelatedLinkCount":4,"System.Title":"some title"}

Which means there are 4 related links to the work item "some title", but they are not being returned. What am I missing here? How do I get these related links/child items?

Community
  • 1
  • 1
YuriW
  • 869
  • 1
  • 11
  • 22

1 Answers1

7

Append &$expand=relations to the querystring to fetch the links collection of a workitem:

$expand enum { all, relations, none }   none    
Gets work item relationships (work item links, hyperlinks, file attachements, etc.).

To get a work item with all details as well as the links with details, you'll need to use the APIs that are intended for reporting purposes. Due to the possible shear size of the returned document, it will be chunked and you will be given a watermark. You may need to do multiple requests.

jessehouwing
  • 106,458
  • 22
  • 256
  • 341
  • That did the trick! Is it also possible to retrieve the title/state of these linked items in the same query or I will have to check each one individually? Couldn't find that on the linked page. – YuriW Dec 22 '16 at 12:10
  • @YuriW how to get all the details of Child task's of each Workitem expand=all and relation not solving the purpose !! – Deepak Jain Feb 14 '18 at 04:14
  • @jessehouwing how to get all the details of Child task's of each Workitem expand=all and relation not solving the purpose !! – –  Feb 14 '18 at 05:15
  • 1
    For the details of the work item and its children, use the for reporting API: https://www.visualstudio.com/en-us/docs/integrate/api/wit/reporting-work-item-links – jessehouwing Feb 14 '18 at 10:40