Delphi ActiveX 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'

Delphi ActiveX Example

var
rest: TChilkatRest;
success: Integer;
bTls: Integer;
port: Integer;
bAutoReconnect: Integer;
json: TChilkatJsonObject;
sbRequestBody: TChilkatStringBuilder;
sbResponseBody: TChilkatStringBuilder;
respStatusCode: Integer;
jsonResponse: TChilkatJsonObject;
self: WideString;
id: WideString;
authorSelf: WideString;
authorName: WideString;
authorKey: WideString;
authorAccountId: WideString;
authorEmailAddress: WideString;
authorAvatarUrls48x48: WideString;
authorAvatarUrls24x24: WideString;
authorAvatarUrls16x16: WideString;
authorAvatarUrls32x32: WideString;
authorDisplayName: WideString;
authorActive: Integer;
authorTimeZone: WideString;
body: WideString;
updateAuthorSelf: WideString;
updateAuthorName: WideString;
updateAuthorKey: WideString;
updateAuthorAccountId: WideString;
updateAuthorEmailAddress: WideString;
updateAuthorAvatarUrls48x48: WideString;
updateAuthorAvatarUrls24x24: WideString;
updateAuthorAvatarUrls16x16: WideString;
updateAuthorAvatarUrls32x32: WideString;
updateAuthorDisplayName: WideString;
updateAuthorActive: Integer;
updateAuthorTimeZone: WideString;
created: WideString;
updated: WideString;
visibilityType: WideString;
visibilityValue: WideString;

begin
rest := TChilkatRest.Create(Self);

//  URL: https://your-domain.atlassian.net/rest/api/2/issue/SCRUM-15/comment
bTls := 1;
port := 443;
bAutoReconnect := 1;
success := rest.Connect('your-domain.atlassian.net',port,bTls,bAutoReconnect);
if (success <> 1) then
  begin
    Memo1.Lines.Add('ConnectFailReason: ' + IntToStr(rest.ConnectFailReason));
    Memo1.Lines.Add(rest.LastErrorText);
    Exit;
  end;

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

json := TChilkatJsonObject.Create(Self);
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');

sbRequestBody := TChilkatStringBuilder.Create(Self);
json.EmitSb(sbRequestBody.ControlInterface);
sbResponseBody := TChilkatStringBuilder.Create(Self);
success := rest.FullRequestSb('POST','/rest/api/2/issue/SCRUM-15/comment',sbRequestBody.ControlInterface,sbResponseBody.ControlInterface);
if (success <> 1) then
  begin
    Memo1.Lines.Add(rest.LastErrorText);
    Exit;
  end;
respStatusCode := rest.ResponseStatusCode;
if (respStatusCode >= 400) then
  begin
    Memo1.Lines.Add('Response Status Code = ' + IntToStr(respStatusCode));
    Memo1.Lines.Add('Response Header:');
    Memo1.Lines.Add(rest.ResponseHeader);
    Memo1.Lines.Add('Response Body:');
    Memo1.Lines.Add(sbResponseBody.GetAsString());
    Exit;
  end;

jsonResponse := TChilkatJsonObject.Create(Self);
jsonResponse.LoadSb(sbResponseBody.ControlInterface);

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');

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