- When you want to update a field with JIRA REST API, first write it i json format. Ex: I want to update the summary of an issue.
- {"fields": {"summary":{"name":"bahar"}}}
- You can try it with curl commant whether it works or not.
- curl -D- -X PUT -H "Authorization: Basic YWRtaW46SDF0MXQ=" --data "{\"fields\":{\"summary\":\"bahar\"}}" -H "Content-Type: application/json" "http://localhost:8080/rest/api/2/issue/TAI-9"
- You should use PUT for updating.
- Don't forget to add "\" backslash before the double quotes.
- You should encode your username:password with base 64 encode.
- encoder
- write your username:password, and the output will be "YWRtaW46SDF0MXQ= " something like this. Write the output to the authorization.
- Ex: "Authorization: Basic YWRtaW46SDF0MXQ="
- "http://localhost:8080/rest/api/2/issue/TAI-9" is the issue that you want to update.
- You can do the same thing with java code.Here is the method:
public static String updateSummary()
throws IOException {
URL url =
new URL("http://localhost:8080/rest/api/2/issue/TAI-9");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(
true);
conn.setDoInput(
true);
String credentials =
"username" +
":" +
"password";
String encoding = Base64Converter.encode(credentials.getBytes(
"UTF-8"));
conn.setRequestProperty(
"Authorization", String.format(
"Basic %s", encoding));
conn.setRequestMethod(
"PUT");
conn.setRequestProperty(
"Content-Type", "application/json");
conn.connect();
String st=
"{\"fields\":{\"summary\":\"bahar\"}}";
byte[] outputBytes = st.getBytes(
"UTF-8");
OutputStream os = conn.getOutputStream();
os.write(outputBytes);
os.flush();
BufferedReader rd =
new BufferedReader(
new InputStreamReader(conn.getInputStream()));
StringBuilder sb =
new StringBuilder();
String line;
while ((line = rd.readLine()) != null) {
sb.append(line);
}
rd.close();
conn.disconnect();
return sb.toString();
}
- you can use Base64Convertor.java class. Download
- Here is the atlassian documentation for updating issue via JIRA REST API. atlassian