Rally API:将用户添加到项目中

时间:2012-11-05 23:10:19

标签: c# rally

我是Rally世界的新手,我正在努力使用RallyRestAPI。有很多关于如何查询Rally以获取我认为最有帮助的相关信息的示例。我要做的是创建一个C#命令行工具来将用户添加到项目中。看来我使用RallyRestAPI.Create(“projectpermission”,一些动态json对象)接口来完成创建。我的问题是理解“一些动态的json对象”部分。我不确定如何正确设置它。如果某人有一个如何设置它的小例子,我将不胜感激。

2 个答案:

答案 0 :(得分:0)

这里有一些非常基本的CRUD +查询示例:
http://developer.rallydev.com/help/rest-api-net

一般流程将始终是创建一个新的DynamicJsonObject,设置适当的字段,然后将该对象传递给RallyRestApi的Create方法。

答案 1 :(得分:0)

这是一个代码示例,说明了如何执行此操作。请注意:

  • 运行代码以创建权限的UserID必须是工作区或订阅管理员
  • 用户必须已拥有工作区(即工作区用户)的权限才能使ProjectPermission创建成功

    命名空间RestExample_AddUsersToProject {     课程     {         static void Main(string [] args)         {

            String userName = "user@company.com";
            String userPassword = "topsecret";
            String serverUrl = "https://rally1.rallydev.com";
            String wsapiVersion = "1.38";
    
            RallyRestApi restApi = new RallyRestApi(
                userName,
                userPassword,
                serverUrl,
                wsapiVersion
            );
    
            restApi.Headers[RallyRestApi.HeaderType.Vendor] = "Rally Software";
            restApi.Headers[RallyRestApi.HeaderType.Name] = "RestExample_AddUsersToProject";
    
            // Query for Project for which we want to add permissions
            Request projectRequest = new Request("project");
            projectRequest.Fetch = new List<string>()
            {
                "Name",
                "Owner",
                "State",
                "Description"
            };
            String projectName = "Avalanche Hazard Mapping";
    
            projectRequest.Query = new Query("Name", Query.Operator.Equals, projectName);
            QueryResult queryProjectResults = restApi.Query(projectRequest);
            var myProject = queryProjectResults.Results.First();
            String myProjectReference = myProject["_ref"];
    
            Console.WriteLine("Project Name: " + myProject["Name"]);
            Console.WriteLine("State: " + myProject["State"]);
    
            // Query for User for whom we wish to add ProjectPermission
            Request userRequest = new Request("user");
            userRequest.Fetch = new List<string>()
                {
                    "UserName",
                    "Subscription",
                    "DisplayName"
                };
    
    
            // User needing the permissions
            userRequest.Query = new Query("UserName", Query.Operator.Equals, "\"boromir@midearth.com\"");
            QueryResult queryUserResults = restApi.Query(userRequest);
    
            var myUser = queryUserResults.Results.First();
            String myUserReference = myUser["_ref"];
    
            Console.WriteLine("Username: " + myUser["UserName"]);
            Console.WriteLine("Display Name: " + myUser["DisplayName"]);
            Console.WriteLine("Subscription: " + myUser["Subscription"]);
    
            // Setup required ProjectPermission data
            DynamicJsonObject newProjectPermission = new DynamicJsonObject();
    
            newProjectPermission["User"] = myUser;
            newProjectPermission["Project"] = myProject;
            newProjectPermission["Role"] = "Editor";
    
            // Create the permission in Rally
            CreateResult addProjectPermissionResult = restApi.Create("ProjectPermission", newProjectPermission);
    
            DynamicJsonObject fetchedProjectPermission = restApi.GetByReference(addProjectPermissionResult.Reference, "Name");
            Console.WriteLine("Created ProjectPermission with Role: " + fetchedProjectPermission["Name"]);            
        }
    }
    

    }