Skip to content

Instantly share code, notes, and snippets.

@mattatsnyk
Created January 22, 2024 20:22
Show Gist options
  • Save mattatsnyk/59ab4c699f78b0be99cf2b474e569aac to your computer and use it in GitHub Desktop.
Save mattatsnyk/59ab4c699f78b0be99cf2b474e569aac to your computer and use it in GitHub Desktop.
A simple script to pull down snyk ignores for an organization
#!/opt/homebrew/bin/python3
import requests
# Replace with the relevant snyk api token and org ID
api_token = ""
org_id = ""
issuesPerPage = 100
api_version = "2024-01-04"
data = []
size = 100
uri = f"https://api.snyk.io/rest/orgs/{org_id}/audit_logs/search?version={api_version}&size={size}"
ignore_events = ["org.project.ignore.create", "org.project.ignore.delete", "org.project.ignore.edit"]
# GET all the ignore events
response = requests.get(url=uri,
headers={"Authorization": f"token {api_token}",
"Accept": "application/vnd.api+json"})
for event in response.json()["data"]["items"]:
if event["event"] in ignore_events:
data.append(event)
# Handle Paginated Responses
while "links" in response and response["data"]:
uri = "https://api.snyk.io" + response["links"]["next"]
response = requests.get(url=uri,
headers={"Authorization": f"token {api_token}",
"Accept": "application/vnd.api+json"}).json()
for event in response["data"]["items"]:
if event["event"] in ignore_events:
data.append(event)
# GET the usernames and set into the ignore dict (note: this is a beta API)
for ignore in data:
userID = ignore["content"]["ignoredBy"]["id"]
uri = f"https://api.snyk.io/rest/orgs/{org_id}/users/{userID}?version=2024-01-04%7Ebeta"
response = requests.get(url=uri,
headers={"Authorization": f"token {api_token}",
"Accept": "application/vnd.api+json"}).json()
ignore["username"] = response["data"]["attributes"]["name"]
ignore["email"] = response["data"]["attributes"]["email"]
print(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment