JiraRestClient for Java does not support edits or updates

Continuing from my last post on using Jira’s REST client for Java, it seems the version I am using, 2.0.0-m2, does not actually support updates.  It is read only.

Because it’s not like you’d ever want to update JIRA through its API, obviously :O

However the basic REST api does support updates.  To use this you need to authenticate and do an HTTP PUT which contains a JSON message with the update details.  Here I am going to post the code to update a custom field referenced by name.  Took me all afternoon.  Atlassian suck.

public class JiraRestAPITest {
  private static final String JIRA_USERNAME = "admin";
  private static final String JIRA_PASSWORD = "password";
  private static final String JIRA_URL = "http://localhost:8091/";
  private static final String CUSTOM_FIELD_NAME = "AosCustom1";
  private static final String JIRA_FILTER_BY_STATUS = "Open";
  private static final String JIRA_PROJECT_NAME = "aosdemo";
  private static final String ISSUE_ID = "DEMO-3";

  public void testSomething() throws URISyntaxException {

    JiraRestClient restClient = login(JIRA_USERNAME, JIRA_PASSWORD);
    String jsql = filterByProject(JIRA_PROJECT_NAME);

    SearchResult results = restClient.getSearchClient().searchJql(jsql).claim();
    for (BasicIssue i : results.getIssues()) {
       String key = i.getKey();

       Issue issue = restClient.getIssueClient().getIssue(key).claim();
       Field customField = issue.getFieldByName(CUSTOM_FIELD_NAME);

       if (ISSUE_ID.equals(key)){
          String newValue = "Edited by AdrianOS at " + new Date();
          update(issue, customField, newValue);



  private static String filterByProject(String projectName) {
    return String.format("project = '%s' AND status = '%s' ORDER BY priority DESC", projectName, JIRA_FILTER_BY_STATUS);

  private static void update(Issue issue, Field field, String value) {

     try {
       HttpURLConnection connection = urlConnection(forIssue(issue), withEncoding());


       writeData(connection, jsonEditIssue(field, value));

    } catch (IOException e) {
       throw new RuntimeException(e);


 private static void writeData(HttpURLConnection connection, JSONObject fields) throws IOException {
    OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream());

 private static String withEncoding() {
    String userPassword = JIRA_USERNAME + ":" + JIRA_PASSWORD;
    return encodeBase64String(userPassword.getBytes());

 private static void checkResponse(HttpURLConnection connection)
 throws IOException {

    if (HttpURLConnection.HTTP_NO_CONTENT != connection.getResponseCode()) {

    BufferedReader reader = new BufferedReader(new InputStreamReader(
    StringBuilder stringBuilder = new StringBuilder();

    String line = null;
    while ((line = reader.readLine()) != null) {
       stringBuilder.append(line + "\n");


 private static URL forIssue(Issue issue) throws MalformedURLException {
    return issue.getSelf().toURL();

 private static HttpURLConnection urlConnection(URL url, String encoding) throws IOException {
    HttpURLConnection connection = (HttpURLConnection)url.openConnection();
    connection.setRequestProperty("Content-Type", "application/json");
    connection.setRequestProperty("Authorization", "Basic " + encoding);
    return connection;

 private static JSONObject jsonEditIssue(Field field, String value) {
    JSONObject summary = new JSONObject()
      .accumulate(field.getId(), value);

    JSONObject fields = new JSONObject().accumulate("fields", summary);
      return fields;

 private static JiraRestClient login(String admin, String password) throws URISyntaxException {
    final URI jiraServerUri = new URI(JIRA_URL);
    final JiraRestClientFactory factory = new AsynchronousJiraRestClientFactory();
    return factory.createWithBasicHttpAuthentication(jiraServerUri, admin, password);


Here are the dependencies:





8 thoughts on “JiraRestClient for Java does not support edits or updates

  1. Hey. I am trying to login to Jira using jira client version 2.0.0-m7 but it is giving noclassdeffounderror. Here is my code

    import java.net.URI;

    import com.atlassian.jira.rest.client.api.JiraRestClient;
    import com.atlassian.jira.rest.client.api.JiraRestClientFactory;
    import com.atlassian.jira.rest.client.internal.async.*;

    public class Example1 {

    private static String BASE_URL = “https://localhost:8080/jira”;

    public static void main(String[] args) throws Exception {


    final JiraRestClientFactory factory = new AsynchronousJiraRestClientFactory();
    final URI jiraServerUri = new URI(BASE_URL);

    final JiraRestClient restClient = factory.createWithBasicHttpAuthentication(jiraServerUri, “admin”, “123”);


    This is the error.

    Exception in thread “main” java.lang.NoClassDefFoundError: com/atlassian/sal/api/ApplicationProperties
    at com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory.create

    How to resolve this

  2. Client client = Client.create();
    client.addFilter(new HTTPBasicAuthFilter(jiraUserName, jiraPassword));

    WebResource resource = client.resource(jiraUri + “/rest/api/2/issue/” + resourcePath);

    try {
    ClientResponse clientResponse = resource.type(“application/json”).put(ClientResponse.class, restInput);
    String response = clientResponse.getEntity(String.class);
    if (response != null) {
    log.info(“response={}”, response);

    } catch (UniformInterfaceException e) {
    if (e.getResponse() != null) {
    if (e.getResponse().getStatus() != 204) {
    // If the response code is different than 204 (which is OK) throw the exception
    throw e;

  3. Hi,,,I am trying to use to update my issues status in JIRA using this code,My code is executing successfully,But it is not updating the status of my issue

    Please suggest me.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s