apirestrallycode-rally

How to fetch a userstory's Actuals,Todo,Estimate fields from detail page of rally using RallyrestApi


enter image description hereI am able to take userstory actual, estimate and Values from its Task.But when tasks are not there for an user story i have to take values from the userstories detail page from rally.

Ex:(i need to fetch as like below from rallyrestapi c# toolkit) https://rally1.rallydev.com/#/262768386856d/detail/defect/161729744764

Currently i tried as below , but its not working out

// Query for UserStories

    [![Request storyRequest = new Rally.RestApi.Request("hierarchicalrequirement");
                storyRequest.Workspace = workspaceRef;
                // storyRequest.Project = projectRef;
                storyRequest.ProjectScopeUp = projectScopingUp;
                storyRequest.ProjectScopeDown = projectScopingDown;
                storyRequest.Fetch = new List<string>()
                {
                    "Name",
                    "ObjectID",
                    "ScheduleState",
                    "State",
                    "FormattedID",
                    "CreationDate",
                    "ReleaseDate",
                    "PlanEstimate",
                    "Iteration",
                    "StartDate",
                    "EndDate",
                    "Release",
                    "ScheduleState",
                    "Tasks",                    
                };
                string userstoryId = "";
                long userstoryObjId ;
                storyRequest.Query = new Query("Iteration.Name", Query.Operator.Equals, myIterationName);
                QueryResult queryStoryResults = rallyRestApi.Query(storyRequest);
                ConvertToJSon(queryStoryResults);
                // Fetch Actual and Estimated Time request for task
                foreach (var userstory in queryStoryResults.Results)
                {                                  
                    Rally.RestApi.Request tasksRequest = new Rally.RestApi.Request(userstory\["Tasks"\]);
                    QueryResult queryTaskResult = rallyRestApi.Query(tasksRequest);                 
                }

Request details = new Rally.RestApi.Request("details");
                details.Workspace = workspaceRef;
                // storyRequest.Project = projectRef;
                details.ProjectScopeUp = projectScopingUp;
                details.ProjectScopeDown = projectScopingDown;
                details.Fetch = new List<string>()
                {
                    "Estimate",
                    "Actuals",
                    "ToDo"
                };
                storyRequest.Query = new Query("Defect.ObjectID", Query.Operator.Equals, "298510499032");
                QueryResult detailsdata = rallyRestApi.Query(details);][1]][1]

Unauthorized 401 error it gives. Please guide me how to fetch the above fields from rally details page.


Solution

  • I have the same example in Java but it may help you:

    import com.google.gson.JsonObject;
    import com.rallydev.rest.RallyRestApi;
    import com.rallydev.rest.request.QueryRequest;
    import com.rallydev.rest.response.QueryResponse;
    import com.rallydev.rest.util.Fetch;
    import com.rallydev.rest.util.QueryFilter;
    import java.io.IOException;
    import java.net.URI;
    
    public class FindUserStoryByID {
    
      public static void main(String[] args) throws IOException {
        String host = "https://rally1.rallydev.com";
        String apiKey = "YOUR_API_KEY"; #or you may use login/password
    
        RallyRestApi rallyRestApi = null;
    
        try {
          rallyRestApi = new RallyRestApi(URI.create(host), apiKey);
    
          QueryRequest query = new QueryRequest("HierarchicalRequirement");
          query.setFetch(new Fetch("FormattedID", "Name", "TaskEstimateTotal", "TaskRemainingTotal",
              "TaskActualTotal"));
          query.setLimit(1000);
          query.setScopedDown(true);
          query.setQueryFilter(new QueryFilter("FormattedID", "=", "US11111"));
    
          QueryResponse response = rallyRestApi.query(query);
    
          if (response.wasSuccessful()) {
            for (int i = 0; i < response.getTotalResultCount(); i++) {
              JsonObject jsonObject = response.getResults().get(i).getAsJsonObject();
              System.out.println("FormattedID: " + jsonObject.get("FormattedID"));
              System.out.println("Name: " + jsonObject.get("Name"));
              System.out.println("TaskEstimateTotal: " + jsonObject.get("TaskEstimateTotal"));
              System.out.println("TaskRemainingTotal: " + jsonObject.get("TaskRemainingTotal"));
              System.out.println("TaskActualTotal: " + jsonObject.get("TaskActualTotal"));
            }
          }
        } finally {
          if (rallyRestApi != null) {
            rallyRestApi.close();
          }
        }
      }
    
    }
    

    Output will be like this:

    FormattedID: "US11111"
    Name: "My cool user story"
    TaskEstimateTotal: 29.0
    TaskRemainingTotal: 29.0
    TaskActualTotal: 0.0