Matthew Blau
05/11/2021, 6:19 PMKevin Kho
Kevin Kho
import requests
import json
query1 = """query {
flow_run (where: {state: {_eq: "Scheduled"}}){
id
state
}
}
"""
def cancel_mutation(flow_run_id):
query2 = """
mutation {
cancel_flow_run(input: {
flow_run_id: \"""" + str(flow_run_id) + """\",
}) {
state
}
}
"""
return query2
url = '<https://api.prefect.io>'
r = <http://requests.post|requests.post>(url, json={'query': query1}, headers={"authorization": "Bearer API_TOKEN"})
print(r.status_code)
data = r.json()['data']
for flow in data['flow_run']:
flow_id = flow['id']
_r = <http://requests.post|requests.post>(url, json={'query': cancel_mutation(flow_id)}, headers={"authorization": "Bearer API_TOKEN"})
Kevin Kho
Kevin Kho
import prefect
client = prefect.Client()
client.graphql(query)
and this will authenticate.