Update comments restriction in Jira Service Management via REST API

Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.

Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

Summary

On Jira Service Management (JSM), comments on issues are either internal or shared with customer.

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-829 Adding Comments - more comment visiblity options instead of just being restricted to 2 options.

Moving an issue 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-7119 As a user I want to be able to restrict internal comments to a Project role when moving an issue from a Jira Service Management Project to a different Software or Business Project.

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.

  1. 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 collect this information.

      1 2 3 4 5 6 7 8 9 10 11 select jiraaction.issueid as ISSUE_ID, jiraaction.id as COMMENT_ID from jiraaction inner join entity_property on jiraaction.id=entity_property.entity_id inner join jiraissue on jiraaction.issueid=jiraissue.id inner join project on project.id=jiraissue.project where jiraaction.actiontype = 'comment' and entity_property.json_value='{"internal":true}' and entity_property.entity_name='sd.comment.property' and project.pkey = '<PROJECT_KEY>' ;
  2. Move the target issues to the new project.

    • While the next steps aren't executed, the comments will be public to the new project.

  3. For each comment (combination of Issue ID and Comment ID), run the following commands to change the comment's restriction.

    1. Define values for some environment variables.

      1 2 3 4 5 6 JIRA_ADMIN_USERNAME=admin JIRA_ADMIN_PASSWORD=admin JIRA_BASE_URL=https://mycompany.com/jira ROLE_NAME=Administrators ISSUE_ID=10142 COMMENT_ID=10106
    2. Get current comment data and metadata.

      1 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)
    3. Modify comment's visibility and temporarily save it in a file.

      1 2 3 echo -E ${REST_CONTENT_FULL_OUTPUT} | \ jq '{body: .body, visibility: { type: ("role"), value: ("'${ROLE_NAME}'")}}' \ > modified-comment-data.json
    4. Update the comment with the new restriction to a project role.

      1 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

Updated on March 3, 2025

Still need help?

The Atlassian Community is here for you.