Agile Central - Queries: How to query a milestone's work items using WSAPI

Document ID : KB000098898
Last Modified Date : 31/05/2018
Show Technical Document Details
How can WSAPI be used to return the work items (for example, user stories) of a milestone and in-general to explore the Milestone <-> Work Item relationship ?
Let's use User Stories as an example:

The relationship between Milestones and User Stories is stored on both end points. Hence, there are a couple of ways you can go about exploring it:
1. Use the HierarchicalRequirement endpoint.
2. Use the Milestone endpoint.
Using the HierarchicalRequirement endpoint.
Below is an example of a query that is going to return all user stories which have a milestone and also that the milestone’s name is “milestone_2”. The first part of the query is ensuring there is a milestone that’s linked with the user story. The second part is filtering by the name of the milestone.
User-added image
Using the Milestone endpoint.
The Artifacts field is the one that has all the artifacts linked to that milestone. In order to find milestones that have any artifact (in other words , to exclude those which don’t) then you can use (Artifacts.ObjectID > 0).

You should call the Artifacts collection such as in:
User-added image

The above query returns the count of the Artifacts of that Milestone, in this case: 4.

To further know which are User Stories out of these 4 you will need to look into both the _type and _ref of each of the collection's objects. The _type field will have "Hierarchical Requirement" when the object is a User Story. The _ref will have an object id of the Hierarchical Requirement endpoint. Here is an example of one of the Artifacts collection objects:

User-added image

User-added image

Similarly, you can leverage the same process to query any work item type. 
Additional Information:
Related articles:
How to query Milestones by Artifacts and Artifacts by Milestones
Querying Milestones and their RevisionHistory by Project in WS API
How to search for a Milestone using the WebServices API In Agile Central