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.
/rest/api/2/issue/{issueIdOrKey}/transitions
@jay, 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.
Great option if comment details need to be provided as part of the REST request.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks @Pears Whims 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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey @jay
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Pears Whims 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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @jay ,
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
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:
Let me please know if you find this helpful.
Cheers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Pears Whims 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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @jay ,
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[]
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"
}
]
}
How does this work for Your case?
Pears.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Pears Whims 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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@jay,
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:
Let me please know if that answers.
Pears.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Pears Whims 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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am happy to help 🤜🤛.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Pears Whims 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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Pears Whims 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
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey @jay ,
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
References
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank You jay!
Great it did help!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @jay , 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
Action: Comment on Issue
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
thank you @Robert DaSilva
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@jay 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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@jay 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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.