Redmine API delete query

Juni 30, 2021

If Redmine starts to become slow, this may be due to too many tickets and especially subordinate tickets. The only thing that helps here is to delete redundant, expired or finished tickets. To do this, you usually create a filter, select all tickets and then remove them with one click. However, it happens that the performance of the system has become so bad that the process stops after a certain time. For this purpose, here is a small script that can delete tickets through the API slowly, but safely and cleanly: 

Required is the package: python-redmine

pip install python-redmine

Code:

from redminelib import Redmine
from getpass import getpass
import time

input_login_username= input("Username:")
input_login_password = getpass()

redmine = Redmine('##Redmine URL##', username=input_login_username, password=input_login_password)
input_query_id=input("ID Query:")
issues = redmine.issue.filter(query_id=input_query_id)

print("Please wait....")
print("===============Checking================")
print("First Issue: " , issues[0].id)
laenge_issues= len(issues)
print("Last Issue: " , issues[laenge_issues-1].id)
print("Number of issues to be deleted: ", laenge_issues)
print("===========================================================")
input_confimation = input("Do you really want to delete the selected area? (y/n)")

if(input_confimation.lower()=="y"): index=0 for issue in issues: issue.delete() print ("Issue: ", index, " von ", laenge_issues, end="\r") index = index+1 print("Deletion executed") else: print("Aborted!") time.sleep(3)