SQL Server 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'

SQL Server Example

CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    DECLARE @sTmp0 nvarchar(4000)
    DECLARE @rest int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.Rest', @rest OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

    --  URL: https://your-domain.atlassian.net/rest/api/2/issue/SCRUM-15/comment
    DECLARE @bTls int
    SELECT @bTls = 1
    DECLARE @port int
    SELECT @port = 443
    DECLARE @bAutoReconnect int
    SELECT @bAutoReconnect = 1
    EXEC sp_OAMethod @rest, 'Connect', @success OUT, 'your-domain.atlassian.net', STR(@port), STR(@bTls), STR(@bAutoReconnect)
    IF STR(@success) <> 1
      BEGIN

        EXEC sp_OAGetProperty @rest, 'ConnectFailReason', @iTmp0 OUT
        PRINT 'ConnectFailReason: ' + @iTmp0
        EXEC sp_OAGetProperty @rest, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @rest
        RETURN
      END

    EXEC sp_OAMethod @rest, 'SetAuthBasic', @success OUT, 'jira@example.com', 'JIRA_API_TOKEN'

    DECLARE @json int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @json OUT

    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, '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.'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'visibility.type', 'role'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'visibility.value', 'Administrators'

    EXEC sp_OAMethod @rest, 'AddHeader', @success OUT, 'Content-Type', 'application/json'
    EXEC sp_OAMethod @rest, 'AddHeader', @success OUT, 'Accept', 'application/json'

    DECLARE @sbRequestBody int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.StringBuilder', @sbRequestBody OUT

    EXEC sp_OAMethod @json, 'EmitSb', @success OUT, STR(@sbRequestBody)
    DECLARE @sbResponseBody int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.StringBuilder', @sbResponseBody OUT

    EXEC sp_OAMethod @rest, 'FullRequestSb', @success OUT, 'POST', '/rest/api/2/issue/SCRUM-15/comment', STR(@sbRequestBody), STR(@sbResponseBody)
    IF STR(@success) <> 1
      BEGIN
        EXEC sp_OAGetProperty @rest, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @json
        EXEC @hr = sp_OADestroy @sbRequestBody
        EXEC @hr = sp_OADestroy @sbResponseBody
        RETURN
      END
    DECLARE @respStatusCode int
    EXEC sp_OAGetProperty @rest, 'ResponseStatusCode', @respStatusCode OUT
    IF STR(@respStatusCode) >= 400
      BEGIN

        PRINT 'Response Status Code = ' + STR(@respStatusCode)

        PRINT 'Response Header:'
        EXEC sp_OAGetProperty @rest, 'ResponseHeader', @sTmp0 OUT
        PRINT @sTmp0

        PRINT 'Response Body:'
        EXEC sp_OAMethod @sbResponseBody, 'GetAsString', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @json
        EXEC @hr = sp_OADestroy @sbRequestBody
        EXEC @hr = sp_OADestroy @sbResponseBody
        RETURN
      END

    DECLARE @jsonResponse int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @jsonResponse OUT

    EXEC sp_OAMethod @jsonResponse, 'LoadSb', @success OUT, STR(@sbResponseBody)

    DECLARE @self nvarchar(4000)

    DECLARE @id nvarchar(4000)

    DECLARE @authorSelf nvarchar(4000)

    DECLARE @authorName nvarchar(4000)

    DECLARE @authorKey nvarchar(4000)

    DECLARE @authorAccountId nvarchar(4000)

    DECLARE @authorEmailAddress nvarchar(4000)

    DECLARE @authorAvatarUrls48x48 nvarchar(4000)

    DECLARE @authorAvatarUrls24x24 nvarchar(4000)

    DECLARE @authorAvatarUrls16x16 nvarchar(4000)

    DECLARE @authorAvatarUrls32x32 nvarchar(4000)

    DECLARE @authorDisplayName nvarchar(4000)

    DECLARE @authorActive int

    DECLARE @authorTimeZone nvarchar(4000)

    DECLARE @body nvarchar(4000)

    DECLARE @updateAuthorSelf nvarchar(4000)

    DECLARE @updateAuthorName nvarchar(4000)

    DECLARE @updateAuthorKey nvarchar(4000)

    DECLARE @updateAuthorAccountId nvarchar(4000)

    DECLARE @updateAuthorEmailAddress nvarchar(4000)

    DECLARE @updateAuthorAvatarUrls48x48 nvarchar(4000)

    DECLARE @updateAuthorAvatarUrls24x24 nvarchar(4000)

    DECLARE @updateAuthorAvatarUrls16x16 nvarchar(4000)

    DECLARE @updateAuthorAvatarUrls32x32 nvarchar(4000)

    DECLARE @updateAuthorDisplayName nvarchar(4000)

    DECLARE @updateAuthorActive int

    DECLARE @updateAuthorTimeZone nvarchar(4000)

    DECLARE @created nvarchar(4000)

    DECLARE @updated nvarchar(4000)

    DECLARE @visibilityType nvarchar(4000)

    DECLARE @visibilityValue nvarchar(4000)

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

    EXEC @hr = sp_OADestroy @rest
    EXEC @hr = sp_OADestroy @json
    EXEC @hr = sp_OADestroy @sbRequestBody
    EXEC @hr = sp_OADestroy @sbResponseBody
    EXEC @hr = sp_OADestroy @jsonResponse


END
GO

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