简体   繁体   English

如何通过 REST API 更新 Rally 项目的状态?

[英]How do you update a Rally Project's State via the REST API?

We have created and closed a large number of Projects in Rally over the years.多年来,我们在 Rally 中创建并关闭了大量项目。 Because you can't actually delete Projects entirely, I've found the need to re-open the closed Projects, modify some artifacts, and reclose the project.因为您实际上无法完全删除项目,所以我发现需要重新打开关闭的项目、修改一些工件并重新关闭项目。 A simple example of what I'm trying to do is reflected in this bit of Python:我正在尝试做的一个简单示例反映在 Python 的这一部分中:

resp = session.get('https://rally1.rallydev.com/slm/webservice/v2.0/project/' + ObjectID, auth=HTTPBasicAuth(user, password))
state = resp.json()["Project"]["State"]
if state == "Closed":
    info = { "State": "Open" }
    resp = session.post('https://rally1.rallydev.com/slm/webservice/v2.0/project/' + ObjectID + '?key=' + token, auth=HTTPBasicAuth(user, password), data=json.dumps(info))
    print resp.content

So if a project's "State" is "Closed", POST a JSON object to the API URL of the Project setting it to "Open".因此,如果项目的“状态”为“关闭”,请将 JSON 对象发布到项目的 API URL,将其设置为“打开”。

It doesn't work.它不起作用。 I get this response:我得到这个回应:

{
    "OperationResult": {
        "Errors": [
            "Cannot set attribute on a com.rallydev.webservice.json.JSONSingleProperty"
        ],
        "Warnings": [],
        "_rallyAPIMajor": "2",
        "_rallyAPIMinor": "0"
    }
}

Is there another way to open/close a Project via the Rally WS API?是否有另一种方法通过 Rally WS API 打开/关闭项目?

There may be two issues.可能有两个问题。

First, there was a performance optimization made a couple of years ago that limited queries to open projects.首先,几年前进行了性能优化,限制了对打开项目的查询。 At this point, the only way to get a list of closed projects is on the Projects page for a given workspace, in the UI.此时,获取已关闭项目列表的唯一方法是在 UI 中给定工作区的“项目”页面上。 When we query for projects, WS API returns only open projects.当我们查询项目时,WS API 只返回打开的项目。 Try without checking for this condition state == "Closed"尝试不检查此条件state == "Closed"

However as long as the project endpoint is accessed directly, it should be possible to reopen a project.但是,只要直接访问项目端点,就应该可以重新打开项目。 I did not try it with Python, but using a browser REST Client I re-opened a project as follows:我没有用 Python 尝试过,但是使用浏览器 REST Client 我重新打开了一个项目,如下所示:

a) got security token from security endpoint: a) 从安全端点获得安全令牌:

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

b) appended the token to the request: b) 将令牌附加到请求中:

Endpoint:端点:

https://rally1.rallydev.com/slm/webservice/v2.0/project/14304671845?key=b2c8aa01-...

Payload:有效载荷:

{"Project":{
"State":"Open"
}}

This works.这有效。

Second, security token has to be appended to the post request, but it is not enough.其次, 安全令牌必须附加到发布请求,但这还不够。 Please make sure that you maintain the session cookie, since unlike the scenario in the browser REST client, where the browser maintains the session automatically, in your scenario this is not the case.请确保您维护会话 cookie,因为与浏览器 REST 客户端中浏览器自动维护会话的场景不同,在您的场景中并非如此。 See this StackOverflow post .请参阅此 StackOverflow 帖子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM