Last updated Mar 22, 2024

JIRA Developer Documentation : JIRA REST API Example - Add Comment

Applicable:

JIRA 5.0 and later.

 

The Rest API allows you to add edit and remove issue comments.

Comments may be added either via the rest/api/2/issue/{issuekey}/comment resource or as part of editing an issue.

The examples shown here use curl with an input file denoted by the "--data @filename" syntax and the file data is shown separately

Adding a comment with the "comment" resource.

This resource simply adds a comment and nothing else. (It is also possible to add a comment as a side-effect of another operation like "edit issue" or "transition issue"). This resource is particularly useful if the logged in user may not have "edit" permission for the issue, but does have the "add comment" permission.

Basic example

Request
1
2
curl -D- -u fred:fred -X POST --data {see below} -H "Content-Type: application/json" http://kelpie9:8081/rest/api/2/issue/QA-31/comment

example input data

1
2
{
    "body": "This is a comment regarding the quality of the response."
}
Response

You should just receive a response with a status of "201" with the full json representation of the added comment

Example also setting the security level

Request
1
2
curl -D- -u fred:fred -X POST --data {see below} -H "Content-Type: application/json" http://kelpie9:8081/rest/api/2/issue/QA-31/comment

example input data

1
2
{
    "body": "This is a comment that only administrators can see.",
    "visibility": {
        "type": "role",
        "value": "Administrators"
    }
}

Adding a comment when editing an issue

Comments can also be added using the normal edit operations

Basic example using Edit Issue

Here we update the description and add a comment saying why.

Only one comment can be added at a time when updating an issue via this resource.

Request
1
2
curl -D- -u fred:fred -X PUT --data {see below} -H "Content-Type: application/json" http://kelpie9:8081/rest/api/2/issue/QA-31

example input data

1
2
{
   "update": {
      "comment": [
         {
            "add": {
               "body": "It is time to finish this task"
            }
         }
      ]
   }
}

Example setting the description and also adding a comment using Edit Issue

Here we update the description and add a comment saying why.

Request
1
2
curl -D- -u fred:fred -X PUT --data {see below} -H "Content-Type: application/json" http://kelpie9:8081/rest/api/2/issue/QA-31

example input data

1
2
{
   "update": {
   "description": [
         {
            "set": "JIRA should also come with a free pony"
         }
      ],
      "comment": [
         {
            "add": {
               "body": "This request was originally written in French, which most of our developers can't read"
            }
         }
      ]
   }
}

Rate this page: