I’m trying to grab a minutes worth of usage a couple of times an hour to keep tabs on our site and not been having much luck understanding how to write the query to do this. I have a query, but currently it keeps returning the same information for the same time peroid?
Python code that I am trying to tweak
-----start
import requests
import datetime
import json
myheaders = {
‘Authorization’: ‘Bearer #TOKEN#’,
‘Content-Type’: ‘application/json’
}
x = datetime.datetime.now()
#date_after=“"”+x.strftime(“%Y-%m-%dT%H:%M:00Z”)+“"”
date_now=“"”+x.strftime(“%Y-%m-%dT%H:%M:00Z”)+“"”
x = datetime.datetime.now() - datetime.timedelta(hours = 1)
date_before=" "“+x.strftime(”%Y-%m-%dT%H:%M:00Z")+"" "
#print ( date_before )
data = “”"
{
viewer {
zones(filter: {zoneTag: “#ZoneTag#” }) {
httpRequests1mGroups( limit: 1, filter:{datetime_geq: “”“+date_now+”“”}) {
sum {
bytes
cachedBytes
cachedRequests
encryptedBytes
encryptedRequests
pageViews
requests
responseStatusMap {
requests
edgeResponseStatus
}
threats
}
dimensions {
datetimeMinute
}
}
}
}
}
“”"
#print ( data )
response = requests.post(
‘https://api.cloudflare.com/client/v4/graphql’,
json={ ‘query’ : data},
headers=myheaders
)
#print ( response.text )
json_data = json.loads( response.text )
print ( json.dumps( json_data, indent=2) )
-----end
Thanks,
Matt