3
votes

I'm pulling data off the Rally server at https://rally1.rallydev.com using C# and the Rally.RestAPI.dll. The server was recently upgraded to webservice v2.0 and I'm having some problems getting tasks for a user story. I know the way child collections are presented were changed in the API with the move to 2.0, but what I'm trying isn't working.

1
And what are you trying? (some code sample?)Gabriel Petrovay

1 Answers

1
votes

v2.0 removed the ability to return child collections in the same response for performance reasons. Now fetching a collection will return an object with the count and the url from which to get the collection data.A separate request is needed to get to the elements of the collection. Here is the code that iterates over user story results, accesses "Tasks" collection on stories and issues a separate request to access individual Task attributes:

using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using Rally.RestApi;
using Rally.RestApi.Response;

namespace aRestApp_CollectionOfTasks
{
    class Program
    {
        static void Main(string[] args)
        {
            //Initialize the REST API
            RallyRestApi restApi;
            restApi = new RallyRestApi("[email protected]", "secret", "https://rally1.rallydev.com", "v2.0");

            //Set our Workspace and Project scopings
            String workspaceRef = "/workspace/11111"; //please replace this OID with an OID of your workspace
            String projectRef = "/project/22222";     //please replace this OID with an OID of your project
            bool projectScopingUp = false;
            bool projectScopingDown = true;

            Request storyRequest = new Request("HierarchicalRequirement");


            storyRequest.Workspace = workspaceRef;
            storyRequest.Project = projectRef;
            storyRequest.ProjectScopeUp = projectScopingUp;
            storyRequest.ProjectScopeDown = projectScopingDown;

            storyRequest.Fetch = new List<string>()
                {
                    "Name",
                    "FormattedID",
                    "Tasks",
                    "Estimate"


                };
            storyRequest.Query = new Query("LastUpdateDate", Query.Operator.GreaterThan, "2013-08-01");      
            QueryResult queryStoryResults = restApi.Query(storyRequest);

            foreach (var s in queryStoryResults.Results)
            {
                Console.WriteLine("----------");
                Console.WriteLine("FormattedID: " + s["FormattedID"] + " Name: " + s["Name"]);
                //Console.WriteLine("Tasks ref: " + s["Tasks"]._ref);
                Request taskRequest = new Request(s["Tasks"]);
                QueryResult queryTaskResult = restApi.Query(taskRequest);
                if (queryTaskResult.TotalResultCount > 0)
                {
                    foreach (var t in queryTaskResult.Results)
                    {
                        var taskEstimate = t["Estimate"];
                        var taskName = t["Name"];
                        Console.WriteLine("Task Name: " + taskName + " Estimate: " + taskEstimate);
                    }
                }
                else
                {
                    Console.WriteLine("no tasks found");
                }
            }
        }
    }
}