Adding more comments to an existing issue ticket using REST API

How to add more comments to an existing issue ticket using REST API? I could not find a definitive answer that works in the forum.

For Server:
(change the version if you aren’t using latest)

You simply POST a “body” to the endpoint listed. It will be created by the API user with the current time.

Check out the “REST API Browser” (RAB) plugin. It may be installed by default, but be disabled - so, enable it. Visit Administration > System > REST API Browser or go to {base url}/plugins/servlet/restbrowser. You can search through all the endpoints, so search for “comment” and you will get a list of endpoints with Swagger-like documentation. Find the one for issue/{key}/comment and it will look very similar to the link I included above.

They don’t do a good job of distinguishing the query params from the request body, and their examples can be atrocious at times, but the schema is helpful. You’ll get used to it. From the RAB you can even type/paste in the details and send the request, to try it out live.

For Cloud:

I figured out and use the following code to search and get an issue key and update the issue ticket with new comments. The R based solution is as follows if someone in this forum want to use.


# Getting the JIRA Key Value based on some search parameter

url1 <- paste0("[10277]%20~%20%22","ABCDEF01","%22")
res <- GET(url1 , authenticate(userid,passcode, "basic") )
parsed_json <- enframe(unlist(content(res, "parsed"), recursive = TRUE, use.names = TRUE))
jiraKey <- filter(parsed_json, name == "issues.key")

# Posting comments to a particular JIRA ticket

url2 <- paste0("", jiraKey$value, "/comment")
x <- list(body = "Adding a new Comment")
POST(url2,body = toJSON(x), authenticate(userid,passcode, "basic"), add_headers("Content-Type" = "application/json"), verbose())

Your comprehensive reply is highly appreciated.

1 Like