Skip to content

Instantly share code, notes, and snippets.

@strangeman
Created August 17, 2019 00:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save strangeman/cdca57bed7da41a820b6922379279279 to your computer and use it in GitHub Desktop.
Save strangeman/cdca57bed7da41a820b6922379279279 to your computer and use it in GitHub Desktop.
Remove all issues from Sentry project (need Python 3.7+)
import json
import requests
API_KEY="longrandomstring" # Sentry API key with event:admin scope
ORG_SLUG = "organization" # organization slug
PROJECT_SLUG = "nice-project" # project slug
SENTRY_ROOT = "https://sentry.example.com/" # root Sentry URL
BATCH_SIZE = 20 # how many issues deletes by one request (from 1 to 100)
headers = {'Authorization': f'Bearer {API_KEY}'}
def batch(iterable, n=1):
l = len(iterable)
for ndx in range(0, l, n):
yield iterable[ndx:min(ndx + n, l)]
count = 0
while True:
response = requests.get(
f'{SENTRY_ROOT}/api/0/projects/{ORG_SLUG}/{PROJECT_SLUG}/issues/?query=&statsPeriod=', headers=headers)
issues = response.json()
count += len(issues)
if count % 1000 == 0:
print(f'{count} issues was deleted')
if len(issues) > 0:
for x in batch(issues, BATCH_SIZE):
id_query = ''
for idx, item in enumerate(x):
if idx == 0:
id_query += f'?id={item["id"]}'
else:
id_query += f'&id={item["id"]}'
delreq = requests.delete(
f'{SENTRY_ROOT}/api/0/projects/{ORG_SLUG}/{PROJECT_SLUG}/issues/{id_query}', headers=headers)
if (delreq.status_code != 204):
print(f'Some issues are not deleted with status code {delreq.status_code}')
else:
print('All done! {count} issues was deleted')
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment