如何使用 Rally REST API 检索某些用户字段? [英] How to retrieve certain user fields using Rally REST API?
问题描述
当我查询 Rally REST API (.net) 时,我能够获取除以下字段之外的所有用户值:
When I query Rally REST API (.net) I am able to get all the user values except the following fields:
- 角色
- 成本中心
- 上次登录日期
- 办公地点
- c_RoleType
- 创建日期
当我打开一个 url "https://rally1.rallydev.com/slm/webservice/v2.0/user/xxxxxxxxxx" 在浏览器中,我可以访问上述所有字段.
When I fire up a url "https://rally1.rallydev.com/slm/webservice/v2.0/user/xxxxxxxxxx" in a browser I am able to access all the above fields.
但是,当我使用 REST API 时,结果集不包含上述任何字段.
However, when I use REST API the result set doesn't include any of the above fields.
不确定我是否需要做一些不同的事情.
Not sure if I need to do anything differently.
request = new Request("user");
request.Fetch = fetchList;
request.Workspace = RallyInterface.workspaceRef;
QueryResult queryResult = restApi.Query(request);
附注.在上面的示例中,提取字符串为空,目的是提取所有可能的用户字段.当我调试时,我只能得到以下 18 个字段
PS. In above example Fetch string is empty and the aim is to fetch all the possible user fields. When I debug I am only able to get the following 18 fields
[0] "_rallyAPIMajor" string
[1] "_rallyAPIMinor" string
[2] "_ref" string
[3] "_refObjectUUID" string
[4] "_objectVersion" string
[5] "_refObjectName" string
[6] "ObjectID" string
[7] "Department" string
[8] "Disabled" string
[9] "DisplayName" string
[10] "EmailAddress" string
[11] "FirstName" string
[12] "LastName" string
[13] "MiddleName" string
[14] "Phone" string
[15] "Role" string
[16] "UserName" string
[17] "_type" string
此外,当我使用 GetByReference() 时,我能够获取角色"的值,但不能获取以下任何字段的值:
Also, when I use GetByReference(), I am able to get the value for "Role" but not for any of the following fields:
- 成本中心
- 上次登录日期
- 办公地点
- c_RoleType
- 创建日期
GetByReference() 响应返回字段未找到消息.
GetByReference() response returns with field not found message.
推荐答案
fetchList
应该包含这些字段,或者应该完全省略.下面的代码示例在两种情况下都返回这些字段.这意味着如果我在下面的代码中注释掉 userRequest.Fetch
,这些字段仍将被返回.如果存在提取,但不包括这些字段,则不会返回它们.
The fetchList
should include those fields, or should be entirely omitted. The code example below returns those fields in both cases. It means if I comment out userRequest.Fetch
in the code below, those fields will still be returned. If a fetch is present, but does not include those fields, they will not be returned.
userRequest.Fetch = new List<string>()
{
"Role",
"CostCenter",
"LastLoginDate",
"OfficeLocation",
"CreationDate"
};
userRequest.Query = new Query("UserName", Query.Operator.Equals, "user@co.com");
QueryResult userResults = restApi.Query(userRequest);
foreach (var u in userResults.Results)
{
Console.WriteLine("Role: " + u["Role"] + " CostCenter: " + u["CostCenter"] + " LastLoginDate: " + u["LastLoginDate"] + " OfficeLocation: " + u["OfficeLocation"] + " CreationDate: " + u["CreationDate"]);
}
这是使用 GetByReference
时此代码的另一种变体:
Here is another variation of this code when GetByReference
is used:
userRequest.Query = new Query("UserName", Query.Operator.Equals, "user@co.com");
QueryResult userResults = restApi.Query(userRequest);
String userRef = userResults.Results.First()._ref;
DynamicJsonObject user = restApi.GetByReference(userRef, "Name", "Role", "CostCenter", "LastLoginDate", "OfficeLocation", "CreationDate");
String role = user["Role"];
String costCenter = user["CostCenter"];
String lastLoginDate = user["LastLoginDate"];
String officeLocation = user["OfficeLocation"];
String creationDate = user["CreationDate"];
Console.WriteLine("Role: " + role + " CostCenter: " + costCenter + " LastLoginDate: " + lastLoginDate + " OfficeLocation: " + officeLocation + " CreationDate: " + creationDate);
完整代码可在 这个 github 仓库.
这篇关于如何使用 Rally REST API 检索某些用户字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!