Rally(现称为CA Agile Central)是一款敏捷项目管理工具,提供REST API供开发者集成和提取数据。从API中获取特定字段可以减少网络传输数据量,提高效率。
Rally API允许通过fetch
参数指定需要返回的字段:
// 示例:获取缺陷的特定字段
const rally = require('rally');
const queryConfig = {
type: 'defect',
fetch: ['FormattedID', 'Name', 'State', 'Severity', 'Priority'],
limit: 100
};
rally.query(queryConfig, function(error, result) {
if (error) {
console.log('Error:', error);
} else {
console.log('Result:', result.Results);
}
});
直接通过URL请求时,可以在URL中添加fetch
参数:
https://rally1.rallydev.com/slm/webservice/v2.0/defect?fetch=FormattedID,Name,State&query=(State = "Open")
对于更复杂的查询,可以使用WSAPI:
const rallyApi = {
key: 'your_api_key',
workspace: '/workspace/12345',
project: '/project/67890'
};
fetch(`https://rally1.rallydev.com/slm/webservice/v2.0/hierarchicalrequirement?fetch=FormattedID,Name,ScheduleState&query=(Project = "${rallyApi.project}")`, {
headers: {
'ZSESSIONID': rallyApi.key
}
})
.then(response => response.json())
.then(data => console.log(data));
原因:可能字段名拼写错误或该字段不存在于查询对象中
解决:
describe
端点查看对象可用字段https://rally1.rallydev.com/slm/webservice/v2.0/type/defect/describe
原因:Rally API默认不返回嵌套对象的完整信息
解决:使用点符号获取嵌套字段
fetch: ['FormattedID', 'Owner.Name', 'Project.Name']
原因:某些关联字段默认返回引用链接而非值
解决:使用fetch
获取关联对象的特定字段
fetch: ['FormattedID', 'Parent.Name', 'Children[FormattedID,Name]']
start
和pagesize
参数// 综合示例:获取用户故事及其相关任务
const query = {
type: 'hierarchicalrequirement',
fetch: [
'FormattedID',
'Name',
'ScheduleState',
'Tasks[FormattedID,Name,State]',
'Owner.DisplayName'
],
query: '(Project.Name = "My Project")',
order: 'Rank',
start: 1,
pagesize: 20
};
通过合理使用字段过滤,可以显著提高Rally API的使用效率和应用程序性能。
没有搜到相关的沙龙