How to delete comments from issues

Platform Notice: Cloud - This article applies to Atlassian products on the cloud platform.

Summary

Adding unlimited comments to issues often resulted in unusual load times, which in some cases caused reliability and performance problems.

With many comments across different issues and a lack of good ways to delete them in bulk ( JRACLOUD-91983 - Getting issue details... STATUS ), we don’t expect you to jump into your issues and remove the comments one by one.

Solution

Jira doesn’t have an easy way to delete comments in bulk. Below are some options:

Option 1: Delete all comments with Jira Automation

You can use Jira Cloud’s automation to delete comments in bulk.

To create a rule that deletes all comments (the comments can't be restored):

  1. Go to the Automation Rules page.

  2. Select Create automation.

  3. Specify rule details as follows:

    1. Trigger: Manual trigger
    2. Advanced branching:
      1. Smart value: {{issue.comments.id}}
      2. Variable name: commentId
    3. Action: Delete comment
      1. comment id: {{commentId}}

Option 2: Delete comments older than a specific date with API

The following pages link to APIs used to delete issue comments.

  1. Get a list of comment IDs under an issue: GET comments

  2. Delete a comment based on its ID: DELETE comment

Below is an example of a Python script that can be used to delete comments:

  • Remember to install python3 first and then jira and requests libraries before running it.
  • The advantage of using the API is that you can define a cutoff date and only delete comments older than the cutoff date.

Please be aware that the usage of the below script is not supported.

Python Script:
Delete Comments
from jira import JIRA
from datetime import datetime
import requests
from requests.auth import HTTPBasicAuth

def delete_old_comments(email, token, domain, issue_key, date_str):
    # Connect to Jira
    options = {'server': f'https://{domain}.atlassian.net'}
    jira = JIRA(options, basic_auth=(email, token))

    try:
        # Parse the input date
        cutoff_date = datetime.strptime(date_str, '%Y-%m-%d')

        # Get the issue
        issue = jira.issue(issue_key)
        
        # Retrieve all comments
        comments = jira.comments(issue)

        # Iterate over comments and delete those older than the cutoff date
        for comment in comments:
            comment_created = datetime.strptime(comment.created.split('T')[0], '%Y-%m-%d')
            if comment_created < cutoff_date:
                # Delete the comment using REST API
                comment_url = f"https://{domain}.atlassian.net/rest/api/3/issue/{issue_key}/comment/{comment.id}"
                response = requests.delete(
                    comment_url,
                    auth=HTTPBasicAuth(email, token)
                )
                
                if response.status_code == 204:
                    print(f"Deleted comment {comment.id} created on {comment.created}: {comment.body[:50]}...")
                else:
                    print(f"Failed to delete comment {comment.id}. Status code: {response.status_code}")

    except Exception as e:
        print(f"An error occurred: {e}")

if __name__ == '__main__':
    #Define your inputs here
    email = '' #your email
    api_token = '' #your token
    domain = '' #your Jira domain, only the one before %.atlassian.net
    issue_key = 'KEY-1234' #the issue key
    date_str = '2025-01-01' #Format: YYYY-MM-DD

    # Call the function with the specified inputs
    delete_old_comments(email, api_token, domain, issue_key, date_str)


Last modified on Jan 17, 2025

Was this helpful?

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