How to update comments restriction in Jira through the REST API

Still need help?

The Atlassian Community is here for you.

Ask the community

Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.

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


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-829 - Getting 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-7119 - Getting 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.


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 collecting this information.

      Expand to see the SQL query...
      select jiraaction.issueid as ISSUE_ID,
      from jiraaction 
      inner join entity_property on 
      inner join jiraissue on
      inner join project on
      where jiraaction.actiontype = 'comment'
      and entity_property.json_value='{"internal":true}'
      and entity_property.entity_name=''
      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.

    2. 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)
    3. 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
    4. 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

Last modified on Mar 15, 2021

Was this helpful?

Provide feedback about this article
Powered by Confluence and Scroll Viewport.