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

PowerBuilder Example

integer li_rc
oleobject loo_Rest
integer li_Success
integer li_BTls
integer li_Port
integer li_BAutoReconnect
oleobject loo_Json
oleobject loo_SbRequestBody
oleobject loo_SbResponseBody
integer li_RespStatusCode
oleobject loo_JsonResponse
string ls_Self
string ls_Id
string ls_AuthorSelf
string ls_AuthorName
string ls_AuthorKey
string ls_AuthorAccountId
string ls_AuthorEmailAddress
string ls_AuthorAvatarUrls48x48
string ls_AuthorAvatarUrls24x24
string ls_AuthorAvatarUrls16x16
string ls_AuthorAvatarUrls32x32
string ls_AuthorDisplayName
integer li_AuthorActive
string ls_AuthorTimeZone
string ls_Body
string ls_UpdateAuthorSelf
string ls_UpdateAuthorName
string ls_UpdateAuthorKey
string ls_UpdateAuthorAccountId
string ls_UpdateAuthorEmailAddress
string ls_UpdateAuthorAvatarUrls48x48
string ls_UpdateAuthorAvatarUrls24x24
string ls_UpdateAuthorAvatarUrls16x16
string ls_UpdateAuthorAvatarUrls32x32
string ls_UpdateAuthorDisplayName
integer li_UpdateAuthorActive
string ls_UpdateAuthorTimeZone
string ls_Created
string ls_Updated
string ls_VisibilityType
string ls_VisibilityValue

loo_Rest = create oleobject
li_rc = loo_Rest.ConnectToNewObject("Chilkat_9_5_0.Rest")
if li_rc < 0 then
    destroy loo_Rest
    MessageBox("Error","Connecting to COM object failed")
    return
end if

//  URL: https://your-domain.atlassian.net/rest/api/2/issue/SCRUM-15/comment
li_BTls = 1
li_Port = 443
li_BAutoReconnect = 1
li_Success = loo_Rest.Connect("your-domain.atlassian.net",li_Port,li_BTls,li_BAutoReconnect)
if li_Success <> 1 then
    Write-Debug "ConnectFailReason: " + string(loo_Rest.ConnectFailReason)
    Write-Debug loo_Rest.LastErrorText
    destroy loo_Rest
    return
end if

loo_Rest.SetAuthBasic("jira@example.com","JIRA_API_TOKEN")

loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat_9_5_0.JsonObject")

loo_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.")
loo_Json.UpdateString("visibility.type","role")
loo_Json.UpdateString("visibility.value","Administrators")

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

loo_SbRequestBody = create oleobject
li_rc = loo_SbRequestBody.ConnectToNewObject("Chilkat_9_5_0.StringBuilder")

loo_Json.EmitSb(loo_SbRequestBody)
loo_SbResponseBody = create oleobject
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat_9_5_0.StringBuilder")

li_Success = loo_Rest.FullRequestSb("POST","/rest/api/2/issue/SCRUM-15/comment",loo_SbRequestBody,loo_SbResponseBody)
if li_Success <> 1 then
    Write-Debug loo_Rest.LastErrorText
    destroy loo_Rest
    destroy loo_Json
    destroy loo_SbRequestBody
    destroy loo_SbResponseBody
    return
end if

li_RespStatusCode = loo_Rest.ResponseStatusCode
if li_RespStatusCode >= 400 then
    Write-Debug "Response Status Code = " + string(li_RespStatusCode)
    Write-Debug "Response Header:"
    Write-Debug loo_Rest.ResponseHeader
    Write-Debug "Response Body:"
    Write-Debug loo_SbResponseBody.GetAsString()
    destroy loo_Rest
    destroy loo_Json
    destroy loo_SbRequestBody
    destroy loo_SbResponseBody
    return
end if

loo_JsonResponse = create oleobject
li_rc = loo_JsonResponse.ConnectToNewObject("Chilkat_9_5_0.JsonObject")

loo_JsonResponse.LoadSb(loo_SbResponseBody)

ls_Self = loo_JsonResponse.StringOf("self")
ls_Id = loo_JsonResponse.StringOf("id")
ls_AuthorSelf = loo_JsonResponse.StringOf("author.self")
ls_AuthorName = loo_JsonResponse.StringOf("author.name")
ls_AuthorKey = loo_JsonResponse.StringOf("author.key")
ls_AuthorAccountId = loo_JsonResponse.StringOf("author.accountId")
ls_AuthorEmailAddress = loo_JsonResponse.StringOf("author.emailAddress")
ls_AuthorAvatarUrls48x48 = loo_JsonResponse.StringOf("author.avatarUrls.48x48")
ls_AuthorAvatarUrls24x24 = loo_JsonResponse.StringOf("author.avatarUrls.24x24")
ls_AuthorAvatarUrls16x16 = loo_JsonResponse.StringOf("author.avatarUrls.16x16")
ls_AuthorAvatarUrls32x32 = loo_JsonResponse.StringOf("author.avatarUrls.32x32")
ls_AuthorDisplayName = loo_JsonResponse.StringOf("author.displayName")
li_AuthorActive = loo_JsonResponse.BoolOf("author.active")
ls_AuthorTimeZone = loo_JsonResponse.StringOf("author.timeZone")
ls_Body = loo_JsonResponse.StringOf("body")
ls_UpdateAuthorSelf = loo_JsonResponse.StringOf("updateAuthor.self")
ls_UpdateAuthorName = loo_JsonResponse.StringOf("updateAuthor.name")
ls_UpdateAuthorKey = loo_JsonResponse.StringOf("updateAuthor.key")
ls_UpdateAuthorAccountId = loo_JsonResponse.StringOf("updateAuthor.accountId")
ls_UpdateAuthorEmailAddress = loo_JsonResponse.StringOf("updateAuthor.emailAddress")
ls_UpdateAuthorAvatarUrls48x48 = loo_JsonResponse.StringOf("updateAuthor.avatarUrls.48x48")
ls_UpdateAuthorAvatarUrls24x24 = loo_JsonResponse.StringOf("updateAuthor.avatarUrls.24x24")
ls_UpdateAuthorAvatarUrls16x16 = loo_JsonResponse.StringOf("updateAuthor.avatarUrls.16x16")
ls_UpdateAuthorAvatarUrls32x32 = loo_JsonResponse.StringOf("updateAuthor.avatarUrls.32x32")
ls_UpdateAuthorDisplayName = loo_JsonResponse.StringOf("updateAuthor.displayName")
li_UpdateAuthorActive = loo_JsonResponse.BoolOf("updateAuthor.active")
ls_UpdateAuthorTimeZone = loo_JsonResponse.StringOf("updateAuthor.timeZone")
ls_Created = loo_JsonResponse.StringOf("created")
ls_Updated = loo_JsonResponse.StringOf("updated")
ls_VisibilityType = loo_JsonResponse.StringOf("visibility.type")
ls_VisibilityValue = loo_JsonResponse.StringOf("visibility.value")


destroy loo_Rest
destroy loo_Json
destroy loo_SbRequestBody
destroy loo_SbResponseBody
destroy loo_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"
  }
}