# pip install gql aiohttp
from gql import gql, Client
from gql.transport.aiohttp import AIOHTTPTransport
transport = AIOHTTPTransport(
url="YOUR_PANTHER_API_URL",
headers={"X-API-Key": "YOUR_API_KEY"}
client = Client(transport=transport, fetch_schema_from_transport=True)
# `FindAlerts` is a nickname for the query. You can fully omit it.
query FindAlerts($input: AlertsInput!) {
# `UpdateAlerts` is a nickname for the query. You can fully omit it.
mutation UpdateAlerts($input: UpdateAlertStatusByIdInput!) {
updateAlertStatusById(input: $input) {
# an accumulator that holds all alerts that we fetch all pages
# a helper to know when to exit the loop
# Keep fetching pages until there are no more left
query_data = client.execute(
"createdAtBefore": "2022-03-01T00:00:00.000Z",
"createdAtAfter": "2022-02-01T00:00:00.000Z",
all_alerts.extend([edge["node"] for edge in query_data["alerts"]["edges"]])
has_more = query_data["alerts"]["pageInfo"]["hasNextPage"]
cursor = query_data["alerts"]["pageInfo"]["endCursor"]
mutation_data = client.execute(
"ids": [alert["id"] for alert in all_alerts],
print(f'Resolved {len(mutation_data["updateAlertStatusById"]["alerts"])} alert(s)!')