How to add comment of issue during transition using cloud jira REST API
Asked by jay:

How to add comment of issue during the isssue transition from one state to another. Eg: in progress to resolved. For issue transition i am using below rest url .But I am unable to add comment on it.

<br />

/rest/api/2/issue/{issueIdOrKey}/transitions


Answers:
author: Pears Whims
body: [@jay](/t5/user/viewprofilepage/user-id/5564623), hey.

The question has been answered here <https://community.atlassian.com/t5/Jira-questions/add-a-comment-while-changing-issue-status-by-REST/qaq-p/590930>

Cheers,  
Pears.

comments: author: Robert DaSilva - Adaptavist
body: Great option if comment details need to be provided as part of the REST request.


author: jay
body: Thanks [@Pears Whims](/t5/user/viewprofilepage/user-id/5578779) it worked. I have a small question to you. Now I am able to save comment on the issue transition. In my case it is from 'in-progress' to 'resolved'. Is there any way to find the exact comment which was saved during this transition. Because the comment which saved during transition also saved as a normal comment. So is there any way to find whether it is a comment added during transition time.


author: Pears Whims
body: Hey [@jay](/t5/user/viewprofilepage/user-id/5564623)

Glad it did work!

**User Interface Solution - Activity Tabs**

In the Activity tab, you may find transitions and comments displayed together.

Mind there might be a pitfall with this approach: Jira may group actions that occur close together in the activity stream, making it difficult to isolate comments added during a transition. They might appear bundled with other actions.

**API Solution - REST**

If you're looking for a more API-focused approach, you can use the Jira REST API to retrieve the current status of an issue. This might assist in tracking transitions:

```
/rest/api/2/issue/{issueIdOrKey}/?fields=status
```

Beware this might have similar issue as with UI if Jira decides to aggregate actions.

**Special Cases**

In case You have those apps as **Jira Misc Workflow Extensions (JMWE)** they introduce special Transitions tabs that display detailed transition history.

Previously Jira Cloud UI also had Transition tab, yet this UI may not be longer available. Sharing this just if some dark feature flags can activate this. <https://community.atlassian.com/t5/Jira-questions/JIRA-Issue-Transition-view/qaq-p/1026872>

Let me please know if this helps.

Pears.


author: jay
body: [@Pears Whims](/t5/user/viewprofilepage/user-id/5578779) I am looking for REST API approach. I will give you a detailed explanation. I have an issue and I added 5 comments already in it. After that I moved the issue from "in-progress " to "resolved" and along with that I added a resolved comment too using REST API. But now when I fetch the issue details I am getting these 6 comments(old 5 comments + Resolved comment) together. What I want is I am looking for a solution to find the comment which I added during the transition(Resolved comment) using REST API only. is there any way?


author: Pears Whims
body: Hi [@jay](/t5/user/viewprofilepage/user-id/5564623) ,

I spent some time working on a solution, and unfortunately, I can't provide an out-of-the-box answer. It seems this may not be directly supported by Jira.

You might need to work with the changelog entries for the issue, which you can retrieve via the REST API:

```
GET rest/api/3/issue/ISSUE-KEY?expand=changelog
```

**Key Paths in the JSON Response**

* Transitions: result.changelog.histories\[\].items\[\]
* Comments: result.fields.comment.comments\[\]

In my setup, I couldn't verify if the histories array entries contain comments, but it's worth looking closely in your case.

**Worse Case - Changelog Histories Don't Contain Comments**

If your setup doesn't include comments in the changelog histories, here's what you can do:

* Fetch the changelog object.
* Manually match the timestamps from the status transitions in the changelog with the created timestamps in the comment objects.

Let me please know if you find this helpful.

Cheers.


author: jay
body: Thank you [@Pears Whims](/t5/user/viewprofilepage/user-id/5578779) . Thank you for your effort and help.


author: jay
body: [@Pears Whims](/t5/user/viewprofilepage/user-id/5578779) One more question to you.. Now I am able to save the comment .. But I am not able to save the comment's author name in that api. is there any way to save the author of the comment using jira rest api?


author: Pears Whims
body: Hi [@jay](/t5/user/viewprofilepage/user-id/5564623) ,

Great You are making progress!

Let me try to capture how I understand the follow-up question.

You are able to use Transitions: result.changelog.histories\[\].items\[\]

* You may capture transition
* content of the comment

But the comment author is missing there.

If this is the case, I can see that result.fields.comment.comments\[\] does contain author in my instance:

```
"comment": {
   "comments": [
       {
          "author": {
             "displayName": "Pears Whims",
             "emailAddress": "XXXXXXXXXX"
          },
          "body": "A test comment"
       }
   ]
}
```

<br />

How does this work for Your case?

Pears.


author: jay
body: [@Pears Whims](/t5/user/viewprofilepage/user-id/5578779) Thanks and But not like this. When I add a comment to issue using the REST API i am bot able to add the author tag. I am getting error. So what happened is when I add comment without the 'Author' tag it is fetching the author name from my Jira API's credentials.

I am using the below api to add comment to issue

url:/rest/api/3/issue/{issueIdOrKey}/comment


author: Pears Whims
body: [@jay](/t5/user/viewprofilepage/user-id/5564623),

If I understand You may seek ways to impersonate another user via API. I am afraid this is not supported. Please check these posts and feature requests linked:

* <https://community.atlassian.com/t5/Jira-questions/How-to-add-a-comment-in-jira-as-another-user-through-jira-api/qaq-p/2550536>
* <https://community.atlassian.com/t5/Jira-Service-Management/Is-it-possible-to-create-a-comment-as-another-user-with-the-role/qaq-p/2284298>

Let me please know if that answers.

Pears.


author: jay
body: [@Pears Whims](/t5/user/viewprofilepage/user-id/5578779) This is what I was looking. Now I got the answer that it is not possible to save another username when I add the comment. Got it. Thank you so much for your effort.


author: Pears Whims
body: I am happy to help ??.


author: jay
body: [@Pears Whims](/t5/user/viewprofilepage/user-id/5578779) I forgot to update you one thing regarding your previous answer. <https://community.atlassian.com/t5/Jira-questions/Re-Re-How-to-add-comment-of-issue-during-transition-usi/qaq-p/2798728/comment-id/1047677#M1047677>

```
GET rest/api/3/issue/ISSUE-KEY?expand=changelog
```

**Key Paths in the JSON Response**

* Transitions: result.changelog.histories\[\].items\[\]
* Comments: result.fields.comment.comments\[\]

In my setup, I couldn't verify if the histories array entries contain comments, but it's worth looking closely in your case.

I checked in the changelog of an issue using the REST API. But I couldn't find the the comments in the histories items. I can see attachments and some other data but comments are not present there. Do you know why this is not coming? Do we have to do any extra settings


author: Pears Whims
body: I took a guess that the ability to leave a comment during a transition might be tied to the presence of certain fields in the transition screen, such as whether or not it includes comments. In my environment, I couldn't verify this quickly - yet that's why I did mention the environment.

As for the output of histories and changelog items, it shall be environment independent.

Cheers.


author: jay
body: [@Pears Whims](/t5/user/viewprofilepage/user-id/5578779) Now I understood What you said. Thank you so much.


author: jay
body: [@Pears Whims](/t5/user/viewprofilepage/user-id/5578779) if you don't mind can I ask one more question.

When I create a comment using the REST API, I must include attachment information. So I included the attachment id (10050), which I obtained from the upload attachment response. But when I enter this value, Jira reports a "attachment validation error".  
Then I created a comment on Jira and used the REST API to retrieve all of the comment details, returning a lengthy result as attachment id. That's ""16ffe152-698f-5ed8-aa8a-f04b90f0c748." Next, I created a comment using this attachment id, which succeeded. However, I'm not sure what this attachment id is or how to retrieve it.

"content": \[  
{  
"type": "media",  
"attrs": {  
"type": "file",  
"id": "10050",  
"collection": "",  
"height": 183,  
"width": 200  
}  
}


author: Pears Whims
body: Hey [@jay](/t5/user/viewprofilepage/user-id/5564623) ,

Thanks for reaching out.

**World of the IDs**

**Attachment ID** (10050): This is the ID you get when you upload an attachment via the Jira REST API. It's used within Jira for referencing attachments within the issue itself.

**Media ID** (16ffe152-698f-5ed8-aa8a-f04b90f0c748): This longer, GUID-style ID is used within the Atlassian Document Format (ADF), particularly when embedding media in comments or descriptions.

**Attachment Validation Error**

This may be due to the fact, that the REST API, Jira could expect the Media ID, not the Attachment ID.

This would make sense because the content in comments uses the ADF format, which requires the Media ID for embedded files.

**Obtaining the Media ID**

To retrieve the Media ID after uploading an attachment:

1. Use the Attachment Endpoint: After uploading an attachment, use the endpoint /rest/api/3/attachment/content/{id} to get the media ID. This endpoint will return a 3xx status, redirecting you to a URL that contains the media ID.

2. Fetch the Media ID from the Redirect URL: The redirected URL you receive from the attachment content endpoint will include the media ID as part of the URL. You can extract this ID to use in your comment.

Example:

```
curl --head --request GET "https://your-domain.atlassian.net/rest/api/3/attachment/content/217145"
```

The Location header in the response will contain the Media ID.

3. Use the Media ID in Your Comment: Once you have the Media ID, you can embed it in your comment's content when using the REST API to create or update a comment.

**To wrap this up**

* Step 1: Upload the attachment and get the attachment ID.
* Step 2: Use the attachment ID with /rest/api/3/attachment/content/{id} to fetch the Media ID.
* Step 3: Use the Media ID to embed the attachment in a comment using the ADF format.

**References**

* <https://community.developer.atlassian.com/t/how-to-work-with-attachments-in-comments-media-vs-attachments-nightmare/74338/4>
* <https://community.atlassian.com/t5/Jira-questions/How-to-get-filename-from-media-node-id/qaq-p/1046066>
* <https://community.developer.atlassian.com/t/fetching-media-from-atlassian-document-format/31587>

**P.S. New Questions**

You may consider a separate threads for those follow-up questions, like this one.

Otherwise only few people in the discussion got the notification, thus You are limiting Yourself to getting answer from just 2 people instead of whole awesome community.

Please let me know if that's help!

Best of luck,  
Pears.


author: jay
body: [@Pears Whims](/t5/user/viewprofilepage/user-id/5578779) Thank you it worked for me, I will create new thread for new questions . Thank you.


author: Pears Whims
body: Thank You jay!  
Great it did help!


author: Robert DaSilva - Adaptavist
body: Hi [@jay](/t5/user/viewprofilepage/user-id/5564623) , if you want the same comment added to the Jira Issues after the transition is complete, I would recommend creating a Jira Automation routine to handle this.

You can do this in two ways, either on a per-project basis, or as a global rule on the entire Cloud site. I would recommend starting on a per-project basis and getting help from your organization's administrators to elevate this to a global rule if that's deemed necessary.

The rule should look something like below.

Trigger: Issue Transitioned

* You are able to specify the "From Status" and "To Status" optionally, to have this rule apply to whichever transitions you need.

Action: Comment on Issue

* Here you are able to add the details of the comment you want added. You have the ability to use "Smart Values" too, if you need some level of dynamic data.

![Screenshot 2024-08-29 at 10.40.45?AM.png](https://community.atlassian.com/t5/image/serverpage/image-id/344580i3C06D72A1E45A8D3/image-size/large?v=v2&px=999 "Screenshot 2024-08-29 at 10.40.45?AM.png")

This rule should apply to individual issues as they transition from one status to another in your chosen project. As always, I would recommend testing this in a test environment before creating it in your Live Production environment.

comments: author: jay
body: thank you [@Robert DaSilva - Adaptavist](/t5/user/viewprofilepage/user-id/3984541)

I will check this and update you. I have a small question to you. Now I am able to save comment on the issue transition. In my case it is from 'in-progress' to 'resolved'. Is there any way to find the exact comment which was saved during this transition. Because the comment which saved during transition also saved as a normal comment. So is there any way to find whether it is a comment added during transition time.


author: Robert DaSilva - Adaptavist
body: [@jay](/t5/user/viewprofilepage/user-id/5564623) If I recall, the comment will be added by the "Automation for Jira" user, but you are also welcome to add a specific string of text to the comment itself to indicate it was added via a transition.

Something like:
> Issue transitioned automatically from In Progress to Resolved.
>
> Comment added by automation.


author: jay
body: Now I added the comment using the REST API only not using the automation. Now you suggest to add the indication string in the comment body right? But other than that is there any solution. Because we need to preserve the exact comment saved by the user. Is there any label or tag to add the string.


author: Robert DaSilva - Adaptavist
body: [@jay](/t5/user/viewprofilepage/user-id/5564623) Unfortunately I do not believe that is possible. If you're using a "Service Account" of sorts, that might work, but the easiest way is appending something to the comment body to indicate it was an automatically created comment.


author: jay
body: Thank you [@Robert DaSilva - Adaptavist](/t5/user/viewprofilepage/user-id/3984541) .


Tags: cloud

jira-cloud

rest-api