Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Can you update comments using API for server-hosted JIRA?

romakarol January 20, 2022

 

I want to update an existing comment. The below example works for making a NEW comment.

curl -u $AUTH_USR:$AUTH_PSW -X POST -H "Content-Type: application/json" --data "{ \\"body\\":\\"jenkins: ${COMMENT} -build ${BUILD_NUMBER}\\" }" $SERVER/rest/api/latest/issue/${TICKET_ID}/comment

I tried the below code for updating an EXISTING comment but getting 405 response:

curl -u $AUTH_USR:$AUTH_PSW -X PUT -H "Content-Type: application/json" --data "{ \\"body\\":\\"jenkins: updated! -build ${BUILD_NUMBER}\\" }" http://jira-hur-spm.fyre.ibm.com:8080/rest/api/3/issue/${TICKET_ID}/comment/1

As you can see I am using "1" for the comment ID as in 'comment number 1'. But this might be completely wrong - I actually cannot find docs on how to get a comment ID or what kind of format they are in.

If anyone can help - thank you!

1 answer

1 accepted

3 votes
Answer accepted
Vishwas
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 20, 2022

Hi there once again !!

Yes it is possible.

Let me list out the steps:

First key thing here is to get the commentId of the comment you are editing. To get that we have to do one round of Get method API for issue 

curl -u username:pwd -X GET -H "Content-Type: application/json" http://localhost:8080/rest/api/2/issue/{issueKey}

in the JSON output format you have to search for the comment section and there comments will be there with comment id. Like this

API_Comment_list.png

Next is use the below API:

curl -D- -u username:pwd -X PUT --data @data.txt -H "Content-Type: application/json" http://localhost:8080/rest/api/2/issue/{issueKey}/comment/{CommentId}
 

in data.txt provide like this

{
"body": "This is a comment regarding the quality of the response but edited from API."
}

 

Check this and let me know.

 

Regards,

Vishwas

romakarol January 21, 2022

Thanks again for your help and walking me through those steps.

I was close the second example I gave worked once I provided the proper comment ID and changed the api to 2 instead of 3 as per your example (don't know if that last part was relevant).

bonus question:
JIRA examples are very fond of using "-D-". Im actually struggling to get an answer as to why that is. From experimentation it just results in more verbose output is there any particular reason to use it? Is there a name for this flag I can google?

The format is strange (Most commands dont have an option requiring a closing "-").

Vishwas
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 21, 2022

If it's working , well and fine, I usually take the examples from doc and change them as required.

Regarding bonus question:

I never though about this, yes most of the examples I see have -D- in the command.

that's correct it's giving verbose mode output.

Suggest an answer

Log in or Sign up to answer