0

当我尝试更新这样的自定义字段时:

@rally.update('defect', 1234567890, {'c_CustomField'=>newValue})

我得到:

Error on request - https://rally1.rallydev.com/slm/webservice/v2.0/defect/1234567890.js - {:errors=>["Not authorized to perform action: Invalid key"]}
4

1 回答 1

1

您收到的错误是特定于 WS API v2.0 的。请参阅WS API 文档中的授权部分。在 v2.0 中,需要一个安全令牌来授权创建和更新请求。

例如,如果您使用更新或创建 URL 更新或创建工件,则必须首先获取安全令牌:

使用此端点获取安全令牌:

`https://rally1.rallydev.com/slm/webservice/v2.0/security/authorize`

回复:

{"OperationResult": {"_rallyAPIMajor": "2", "_rallyAPIMinor": "0", "Errors": [], "Warnings": [], "SecurityToken": "6a4b8....."}}

邮政

`https://rally1.rallydev.com/slm/webservice/v2.0/HierarchicalRequirement/create?key=6a4b8...`.

但是, rally_api gem 0.9.20 使其透明,无需显式请求令牌。

以下是更新自定义字段的示例:

require 'rally_api'

#Setup custom app information
headers = RallyAPI::CustomHttpHeader.new()
headers.name = "edit custom field"
headers.vendor = "Nick M RallyLab"
headers.version = "1.0"

# Connection to Rally
config = {:base_url => "https://rally1.rallydev.com/slm"}
config[:username] = "user"
config[:password] = "secret"
config[:workspace] = "W"
config[:project] = "P"
config[:version] = "v2.0"
config[:headers] = headers #from RallyAPI::CustomHttpHeader.new()

@rally = RallyAPI::RallyRestJson.new(config)

query = RallyAPI::RallyQuery.new()
query.type = :defect
query.fetch = "Name,FormattedID,CreationDate,Owner,UserName,c_MyCustomField"
query.workspace = {"_ref" => "https://rally1.rallydev.com/slm/webservice/v2.0/workspace/1111.js" } 
query.project = {"_ref" => "https://rally1.rallydev.com/slm/webservice/v2.0/project/2222.js" }
query.page_size = 200 #optional - default is 200
query.limit = 1000 #optional - default is 99999
query.project_scope_up = false
query.project_scope_down = true
query.order = "Name Asc"
query.query_string = "(FormattedID = DE13)"

results = @rally.find(query)

results.each do |d|
    puts "MyCustomField: #{d["c_MyCustomField"]}"
    d.read
    field_updates = {"c_MyCustomField" => "new text goes here"}
    d.update(field_updates)
    puts "MyCustomField: #{d["c_MyCustomField"]}"
end
于 2013-09-20T21:04:49.237 回答