C 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'

C Example

#include <C_CkRest.h>
#include <C_CkJsonObject.h>
#include <C_CkStringBuilder.h>

void ChilkatSample(void)
    {
    HCkRest rest;
    BOOL success;
    BOOL bTls;
    int port;
    BOOL bAutoReconnect;
    HCkJsonObject json;
    HCkStringBuilder sbRequestBody;
    HCkStringBuilder sbResponseBody;
    int respStatusCode;
    HCkJsonObject jsonResponse;
    const char *self;
    const char *id;
    const char *authorSelf;
    const char *authorName;
    const char *authorKey;
    const char *authorAccountId;
    const char *authorEmailAddress;
    const char *authorAvatarUrls48x48;
    const char *authorAvatarUrls24x24;
    const char *authorAvatarUrls16x16;
    const char *authorAvatarUrls32x32;
    const char *authorDisplayName;
    BOOL authorActive;
    const char *authorTimeZone;
    const char *body;
    const char *updateAuthorSelf;
    const char *updateAuthorName;
    const char *updateAuthorKey;
    const char *updateAuthorAccountId;
    const char *updateAuthorEmailAddress;
    const char *updateAuthorAvatarUrls48x48;
    const char *updateAuthorAvatarUrls24x24;
    const char *updateAuthorAvatarUrls16x16;
    const char *updateAuthorAvatarUrls32x32;
    const char *updateAuthorDisplayName;
    BOOL updateAuthorActive;
    const char *updateAuthorTimeZone;
    const char *created;
    const char *updated;
    const char *visibilityType;
    const char *visibilityValue;

    rest = CkRest_Create();

    //  URL: https://your-domain.atlassian.net/rest/api/2/issue/SCRUM-15/comment
    bTls = TRUE;
    port = 443;
    bAutoReconnect = TRUE;
    success = CkRest_Connect(rest,"your-domain.atlassian.net",port,bTls,bAutoReconnect);
    if (success != TRUE) {
        printf("ConnectFailReason: %d\n",CkRest_getConnectFailReason(rest));
        printf("%s\n",CkRest_lastErrorText(rest));
        CkRest_Dispose(rest);
        return;
    }

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

    json = CkJsonObject_Create();
    CkJsonObject_UpdateString(json,"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.");
    CkJsonObject_UpdateString(json,"visibility.type","role");
    CkJsonObject_UpdateString(json,"visibility.value","Administrators");

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

    sbRequestBody = CkStringBuilder_Create();
    CkJsonObject_EmitSb(json,sbRequestBody);
    sbResponseBody = CkStringBuilder_Create();
    success = CkRest_FullRequestSb(rest,"POST","/rest/api/2/issue/SCRUM-15/comment",sbRequestBody,sbResponseBody);
    if (success != TRUE) {
        printf("%s\n",CkRest_lastErrorText(rest));
        CkRest_Dispose(rest);
        CkJsonObject_Dispose(json);
        CkStringBuilder_Dispose(sbRequestBody);
        CkStringBuilder_Dispose(sbResponseBody);
        return;
    }

    respStatusCode = CkRest_getResponseStatusCode(rest);
    if (respStatusCode >= 400) {
        printf("Response Status Code = %d\n",respStatusCode);
        printf("Response Header:\n");
        printf("%s\n",CkRest_responseHeader(rest));
        printf("Response Body:\n");
        printf("%s\n",CkStringBuilder_getAsString(sbResponseBody));
        CkRest_Dispose(rest);
        CkJsonObject_Dispose(json);
        CkStringBuilder_Dispose(sbRequestBody);
        CkStringBuilder_Dispose(sbResponseBody);
        return;
    }

    jsonResponse = CkJsonObject_Create();
    CkJsonObject_LoadSb(jsonResponse,sbResponseBody);

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


    CkRest_Dispose(rest);
    CkJsonObject_Dispose(json);
    CkStringBuilder_Dispose(sbRequestBody);
    CkStringBuilder_Dispose(sbResponseBody);
    CkJsonObject_Dispose(jsonResponse);

    }

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"
  }
}