Jira REST API - 如何将新成员发布到项目角色?

时间:2014-04-23 16:54:30

标签: jira

我正在尝试使用REST Api来管理JIRA中的项目角色。我已经能够获得角色和“演员”的列表并删除角色成员。但是我无法正确地发布新的角色成员。我一直收到400或405的错误。我正在使用HttpClient 4.3.2和Jira 6.0.2。这是我的代码:

// Set up ssl configuration as a user in JIRA instance

HttpClient client = HttpClientBuilder.create().build();
HttpPost post = new HttpPost("https://jira.install/rest/api/2/project/KEY/role/10000");

StringEntity input = new StringEntity("{\"group\":\"jira-users\" }");
input.setContentType("Application/json");
post.setEntity(input);

client.execute(post);

有没有人能够成功进行类似的通话?

1 个答案:

答案 0 :(得分:1)

其余的api需要对组角色进行POST的基本授权,但API文档中没有明确说明。所以我的工作方式如下:

String auth = "username:password";
byte[] encodedAuth = Base64.encodeBase64(auth.getBytes(Charset.forName("US_ASCII")));
String authHeader = "Basic " + new String(encodedAuth);

HttpClient client = HttpClientBuilder.create().build();
HttpPost post = new HttpPost(url);
StringEntity input;

try {
    input = new StringEntity("{\"group\":\"your-jira-group\"}");
    input.setContentType("Application/json");
    post.setEntity(input);
    post.setHeader(HttpHeaders.AUTHORIZATION, authHeader);

    HttpResponse response = client.execute(post);
} catch (Exception ex) {
}

有两件事搞砸了我...... Application / json中的“A”需要大写,你需要授权会话。我选择了基本身份验证,并在使用curl进行测试后使用了HttpClient。