Android™ Jira - Issues: Add a Comment

Back to Index

Adds a new comment to an issue. This example adds a comment for the issue with key = "SCRUM-15".

Documentation: https://developers.atlassian.com/cloud/jira/platform/rest/#api-api-2-issue-issueIdOrKey-comment-post

CURL Command

curl --user jira@example.com:JIRA_API_TOKEN \
  --header 'Accept: application/json' \
  --header 'Content-Type: application/json' \
  --data '
    {
      "body": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque eget venenatis elit. Duis eu justo eget augue iaculis fermentum. Sed semper quam laoreet nisi egestas at posuere augue semper.",
      "visibility": {
        "type": "role",
        "value": "Administrators"
      }
    }' \
  --url 'https://your-domain.atlassian.net/rest/api/2/issue/SCRUM-15/comment'

Android™ Example

// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;

import android.app.Activity;
import com.chilkatsoft.*;

import android.widget.TextView;
import android.os.Bundle;

public class SimpleActivity extends Activity {

  private static final String TAG = "Chilkat";

  // Called when the activity is first created.
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    CkRest rest = new CkRest();
    boolean success;

    //  URL: https://your-domain.atlassian.net/rest/api/2/issue/SCRUM-15/comment
    boolean bTls = true;
    int port = 443;
    boolean bAutoReconnect = true;
    success = rest.Connect("your-domain.atlassian.net",port,bTls,bAutoReconnect);
    if (success != true) {
        Log.i(TAG, "ConnectFailReason: " + String.valueOf(rest.get_ConnectFailReason()));
        Log.i(TAG, rest.lastErrorText());
        return;
        }

    rest.SetAuthBasic("jira@example.com","JIRA_API_TOKEN");

    CkJsonObject json = new CkJsonObject();
    json.UpdateString("body","Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque eget venenatis elit. Duis eu justo eget augue iaculis fermentum. Sed semper quam laoreet nisi egestas at posuere augue semper.");
    json.UpdateString("visibility.type","role");
    json.UpdateString("visibility.value","Administrators");

    rest.AddHeader("Content-Type","application/json");
    rest.AddHeader("Accept","application/json");

    CkStringBuilder sbRequestBody = new CkStringBuilder();
    json.EmitSb(sbRequestBody);
    CkStringBuilder sbResponseBody = new CkStringBuilder();
    success = rest.FullRequestSb("POST","/rest/api/2/issue/SCRUM-15/comment",sbRequestBody,sbResponseBody);
    if (success != true) {
        Log.i(TAG, rest.lastErrorText());
        return;
        }

    int respStatusCode = rest.get_ResponseStatusCode();
    if (respStatusCode >= 400) {
        Log.i(TAG, "Response Status Code = " + String.valueOf(respStatusCode));
        Log.i(TAG, "Response Header:");
        Log.i(TAG, rest.responseHeader());
        Log.i(TAG, "Response Body:");
        Log.i(TAG, sbResponseBody.getAsString());
        return;
        }

    CkJsonObject jsonResponse = new CkJsonObject();
    jsonResponse.LoadSb(sbResponseBody);

    String self;
    String id;
    String authorSelf;
    String authorName;
    String authorKey;
    String authorAccountId;
    String authorEmailAddress;
    String authorAvatarUrls48x48;
    String authorAvatarUrls24x24;
    String authorAvatarUrls16x16;
    String authorAvatarUrls32x32;
    String authorDisplayName;
    boolean authorActive;
    String authorTimeZone;
    String body;
    String updateAuthorSelf;
    String updateAuthorName;
    String updateAuthorKey;
    String updateAuthorAccountId;
    String updateAuthorEmailAddress;
    String updateAuthorAvatarUrls48x48;
    String updateAuthorAvatarUrls24x24;
    String updateAuthorAvatarUrls16x16;
    String updateAuthorAvatarUrls32x32;
    String updateAuthorDisplayName;
    boolean updateAuthorActive;
    String updateAuthorTimeZone;
    String created;
    String updated;
    String visibilityType;
    String visibilityValue;

    self = jsonResponse.stringOf("self");
    id = jsonResponse.stringOf("id");
    authorSelf = jsonResponse.stringOf("author.self");
    authorName = jsonResponse.stringOf("author.name");
    authorKey = jsonResponse.stringOf("author.key");
    authorAccountId = jsonResponse.stringOf("author.accountId");
    authorEmailAddress = jsonResponse.stringOf("author.emailAddress");
    authorAvatarUrls48x48 = jsonResponse.stringOf("author.avatarUrls.48x48");
    authorAvatarUrls24x24 = jsonResponse.stringOf("author.avatarUrls.24x24");
    authorAvatarUrls16x16 = jsonResponse.stringOf("author.avatarUrls.16x16");
    authorAvatarUrls32x32 = jsonResponse.stringOf("author.avatarUrls.32x32");
    authorDisplayName = jsonResponse.stringOf("author.displayName");
    authorActive = jsonResponse.BoolOf("author.active");
    authorTimeZone = jsonResponse.stringOf("author.timeZone");
    body = jsonResponse.stringOf("body");
    updateAuthorSelf = jsonResponse.stringOf("updateAuthor.self");
    updateAuthorName = jsonResponse.stringOf("updateAuthor.name");
    updateAuthorKey = jsonResponse.stringOf("updateAuthor.key");
    updateAuthorAccountId = jsonResponse.stringOf("updateAuthor.accountId");
    updateAuthorEmailAddress = jsonResponse.stringOf("updateAuthor.emailAddress");
    updateAuthorAvatarUrls48x48 = jsonResponse.stringOf("updateAuthor.avatarUrls.48x48");
    updateAuthorAvatarUrls24x24 = jsonResponse.stringOf("updateAuthor.avatarUrls.24x24");
    updateAuthorAvatarUrls16x16 = jsonResponse.stringOf("updateAuthor.avatarUrls.16x16");
    updateAuthorAvatarUrls32x32 = jsonResponse.stringOf("updateAuthor.avatarUrls.32x32");
    updateAuthorDisplayName = jsonResponse.stringOf("updateAuthor.displayName");
    updateAuthorActive = jsonResponse.BoolOf("updateAuthor.active");
    updateAuthorTimeZone = jsonResponse.stringOf("updateAuthor.timeZone");
    created = jsonResponse.stringOf("created");
    updated = jsonResponse.stringOf("updated");
    visibilityType = jsonResponse.stringOf("visibility.type");
    visibilityValue = jsonResponse.stringOf("visibility.value");

  }

  static {
      System.loadLibrary("chilkat");

      // Note: If the incorrect library name is passed to System.loadLibrary,
      // then you will see the following error message at application startup:
      //"The application <your-application-name> has stopped unexpectedly. Please try again."
  }
}

Sample JSON Response Body

{
  "self": "https://chilkat.atlassian.net/rest/api/2/issue/10014/comment/10019",
  "id": "10019",
  "author": {
    "self": "https://chilkat.atlassian.net/rest/api/2/user?username=admin",
    "name": "admin",
    "key": "admin",
    "accountId": "557058:be8b47b5-3bc0-43f6-b6b2-2cca0de12204",
    "emailAddress": "admin@chilkatsoft.com",
    "avatarUrls": {
      "48x48": "https://avatar-cdn.atlassian.com/16d54dcc6d4bef86fd7ee62a7cf6334a?s=48&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2F16d54dcc6d4bef86fd7ee62a7cf6334a%3Fd%3Dmm%26s%3D48%26noRedirect%3Dtrue",
      "24x24": "https://avatar-cdn.atlassian.com/16d54dcc6d4bef86fd7ee62a7cf6334a?s=24&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2F16d54dcc6d4bef86fd7ee62a7cf6334a%3Fd%3Dmm%26s%3D24%26noRedirect%3Dtrue",
      "16x16": "https://avatar-cdn.atlassian.com/16d54dcc6d4bef86fd7ee62a7cf6334a?s=16&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2F16d54dcc6d4bef86fd7ee62a7cf6334a%3Fd%3Dmm%26s%3D16%26noRedirect%3Dtrue",
      "32x32": "https://avatar-cdn.atlassian.com/16d54dcc6d4bef86fd7ee62a7cf6334a?s=32&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2F16d54dcc6d4bef86fd7ee62a7cf6334a%3Fd%3Dmm%26s%3D32%26noRedirect%3Dtrue"
    },
    "displayName": "Chilkat Admin",
    "active": true,
    "timeZone": "America/Chicago"
  },
  "body": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque eget venenatis elit. Duis eu justo eget augue iaculis fermentum. Sed semper quam laoreet nisi egestas at posuere augue semper.",
  "updateAuthor": {
    "self": "https://chilkat.atlassian.net/rest/api/2/user?username=admin",
    "name": "admin",
    "key": "admin",
    "accountId": "557058:be8b47b5-3bc0-43f6-b6b2-2cca0de12204",
    "emailAddress": "admin@chilkatsoft.com",
    "avatarUrls": {
      "48x48": "https://avatar-cdn.atlassian.com/16d54dcc6d4bef86fd7ee62a7cf6334a?s=48&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2F16d54dcc6d4bef86fd7ee62a7cf6334a%3Fd%3Dmm%26s%3D48%26noRedirect%3Dtrue",
      "24x24": "https://avatar-cdn.atlassian.com/16d54dcc6d4bef86fd7ee62a7cf6334a?s=24&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2F16d54dcc6d4bef86fd7ee62a7cf6334a%3Fd%3Dmm%26s%3D24%26noRedirect%3Dtrue",
      "16x16": "https://avatar-cdn.atlassian.com/16d54dcc6d4bef86fd7ee62a7cf6334a?s=16&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2F16d54dcc6d4bef86fd7ee62a7cf6334a%3Fd%3Dmm%26s%3D16%26noRedirect%3Dtrue",
      "32x32": "https://avatar-cdn.atlassian.com/16d54dcc6d4bef86fd7ee62a7cf6334a?s=32&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2F16d54dcc6d4bef86fd7ee62a7cf6334a%3Fd%3Dmm%26s%3D32%26noRedirect%3Dtrue"
    },
    "displayName": "Chilkat Admin",
    "active": true,
    "timeZone": "America/Chicago"
  },
  "created": "2018-04-14T10:14:41.741-0500",
  "updated": "2018-04-14T10:14:41.741-0500",
  "visibility": {
    "type": "role",
    "value": "Administrators"
  }
}