How can WSAPI be used to return the user stories of a milestone and in-general to explore the Milestone <-> User Story relationship ?
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.
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:
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: