用JIRA rest api 4.4更新问题

时间:2012-05-17 16:42:00

标签: jira

我正在尝试通过JIRA rest api更新问题的fixVersion。 JIRA版本是4.4.3#663-r165197。它是由codehaus托管的实例,不确定它是否有所作为。

请求如下:

  curl -u [username]:[password] -X PUT -H 'Content-type: application/json' \
    -d  "http://jira.codehaus.org/rest/api/latest/issue/GEOS-[id]"
{
   "update":{
      "fixVersions":[
         {
            "set":[
               {
                  "name":"2.2-beta3"
               }
            ]
         }
      ]
   }
}

但是我回到405,方法不允许错误。如果我查看该版本的其余api文档,这是有道理的[1]。它们似乎表明无法以这种方式更新问题。如果我查看最新版本的文档[2],他们似乎表明它是可能的。

所以我想问题是如何在JIRA 4.4中以这种方式更新问题?或者是不可能的?

谢谢!

[1] https://developer.atlassian.com/static/rest/jira/4.4.1.html#id151460

[2] http://docs.atlassian.com/jira/REST/latest/#id165544

2 个答案:

答案 0 :(得分:1)

对于4.4,您必须使用SOAP updateIssue方法。 5.0修正了这个。

答案 1 :(得分:0)

Prepare Json data as below(Here java as technology i had used), and pass using put method/API.

public static String generateJson(String customFieldId, Object value,
        String attribute) {

    if (isBlankOrNull(attribute)) {
        return "\"" + customFieldId + "\":" + "\"" + value + "\"";
    } else {
        return "\"" + customFieldId + "\":{\"" + attribute + "\":\"" + ""
                + value + "\"}";
    }
}



    public static int invokePutMethod(String auth, String url, String data) {

            int statusCode = 0;
            try {
                Client client = Client.create();
                WebResource webResource = client.resource(url);
                ClientResponse response = webResource
                        .header("Authorization", "Basic " + auth)
                        .type("application/json").accept("application/json")
                        .put(ClientResponse.class, data);
                statusCode = response.getStatus();
                return statusCode;
            } catch (Exception e) {
                Constants.ERROR.info(Level.INFO, e);
                // vjErrorLog.info(Level.INFO, e);
            }
            return statusCode;
        }

attribute could be key, id, name, value etc,

In case of fix version or components, you may have one more way to prepare json data

    return "\"" + customFieldId + "\":[{\"set\" :[{ \"" + attribute
                        + "\" :" + "\"" + data + "\"}]}]";

and invoke put method with above json data.