How to update comments restriction in Jira through the REST API
Platform notice: Server and Data Center only. This article only applies to Atlassian products on the server and data center platforms.
Summary
On Jira Service Management (JSM), comments on issues are either internal or shared with customer.
See Editing and collaborating on issues for more information on how comments relate to JSM issues.
As with other Jira project types, there's no option for JSM projects to use roles to restrict comments in an issue.
This is reported as a feature in
-
JSDSERVER-829Getting issue details...
STATUS
.
Moving issues from JSM to other projects' types (Business or Software) turns all comments into public (no restrictions) by default and there's no option in the move issue wizard to assign internal comments to a specific role in the target project.
There's a feature request about it in
-
JSDSERVER-7119Getting issue details...
STATUS
.
Sometimes there may be a requirement to move all (or a set of) issues from a JSM project to another from a different type and internal comments should be restricted to a specific project role.
Changing the comments' restrictions from the UI for each comment and issue might be an obstacle.
This document describes the steps needed to modify comments' restrictions through the Jira REST API.
Solution
The following procedure is based on comments executed in the Linux Shell.
You may adapt it to run on your preferred coding language.
- Determine the combination of Issue ID and Comment ID for all target internal comments that should be restricted to a specific project role.
If moving all issues in a specific project, the following query helps collecting this information.
- Move the target issues to the new project.
- While the next steps aren't executed, the comments will be public to the new project.
- For each comment (combination of Issue ID and Comment ID), run the following commands to change the comment's restriction.
Define values for some environment variables.
JIRA_ADMIN_USERNAME=admin JIRA_ADMIN_PASSWORD=admin JIRA_BASE_URL=https://mycompany.com/jira ROLE_NAME=Administrators ISSUE_ID=10142 COMMENT_ID=10106
Get current comment data and metadata.
REST_CONTENT_FULL_OUTPUT=$(curl -u ${JIRA_ADMIN_USERNAME}:${JIRA_ADMIN_PASSWORD} -X GET -H "Accept: application/json" ${JIRA_BASE_URL}'/rest/api/2/issue/'${ISSUE_ID}'/comment/'${COMMENT_ID} 2>/dev/null)
Modify comment's visibility and temporarily save it in a file.
echo -E ${REST_CONTENT_FULL_OUTPUT} | \ jq '{body: .body, visibility: { type: ("role"), value: ("'${ROLE_NAME}'")}}' \ > modified-comment-data.json
Update the comment with the new restriction to a project role.
curl -u ${JIRA_ADMIN_USERNAME}:${JIRA_ADMIN_PASSWORD} -X PUT -H "Content-Type: application/json" ${JIRA_BASE_URL}'/rest/api/2/issue/'${ISSUE_ID}'/comment/'${COMMENT_ID} --data @modified-comment-data.json
See Also
Restricted comments disappear after moving an issue to a new project
How to Retrieve Internal or External Comment in Jira Service Management