Time range can't be wider than 259200s, but it's 2592000s"

Could you pls help me? I need upgrade my account for premium? What plan I need?
1 Reply
[NODERS] Aleksandr
[NODERS] AleksandrOP8mo ago
import requests
from datetime import datetime, timedelta

headers = {
'Authorization': 'Bearer my_api_key',
'Content-Type': 'application/json'
}

# Определение временного интервала за последние 24 часа
end_time = datetime.utcnow()
start_time = end_time - timedelta(days=1)

# Преобразование временных меток в строковый формат для использования в запросе GraphQL
end_time_str = end_time.strftime('%Y-%m-%dT%H:%M:%SZ')
start_time_str = start_time.strftime('%Y-%m-%dT%H:%M:%SZ')

data = """
{
viewer {
zones(filter: {zoneTag: "my_zone_id"}) {
httpRequests1hGroups(limit: 100, filter: {datetime_geq: "%s", datetime_lt: "%s"}) {
uniq {
uniques
}
sum {
requests
}
}
}
}
}
""" % (start_time_str, end_time_str)

response = requests.post(
'https://api.cloudflare.com/client/v4/graphql',
headers=headers,
json={'query': data}
)

if response.status_code == 200:
data = response.json()
total_requests = data['data']['viewer']['zones'][0]['httpRequests1hGroups'][0]['sum']['requests']
unique_visitors = data['data']['viewer']['zones'][0]['httpRequests1hGroups'][0]['uniq']['uniques']

print("Total Requests:", total_requests)
print("Unique Visitors:", unique_visitors)
else:
print("Error:", response.status_code)
import requests
from datetime import datetime, timedelta

headers = {
'Authorization': 'Bearer my_api_key',
'Content-Type': 'application/json'
}

# Определение временного интервала за последние 24 часа
end_time = datetime.utcnow()
start_time = end_time - timedelta(days=1)

# Преобразование временных меток в строковый формат для использования в запросе GraphQL
end_time_str = end_time.strftime('%Y-%m-%dT%H:%M:%SZ')
start_time_str = start_time.strftime('%Y-%m-%dT%H:%M:%SZ')

data = """
{
viewer {
zones(filter: {zoneTag: "my_zone_id"}) {
httpRequests1hGroups(limit: 100, filter: {datetime_geq: "%s", datetime_lt: "%s"}) {
uniq {
uniques
}
sum {
requests
}
}
}
}
}
""" % (start_time_str, end_time_str)

response = requests.post(
'https://api.cloudflare.com/client/v4/graphql',
headers=headers,
json={'query': data}
)

if response.status_code == 200:
data = response.json()
total_requests = data['data']['viewer']['zones'][0]['httpRequests1hGroups'][0]['sum']['requests']
unique_visitors = data['data']['viewer']['zones'][0]['httpRequests1hGroups'][0]['uniq']['uniques']

print("Total Requests:", total_requests)
print("Unique Visitors:", unique_visitors)
else:
print("Error:", response.status_code)
for last 24h its works good, but when I request for time more then 3d I get error I can't receive in the last 30 days? this is great, I just need the number of requests in the last 30 days and the number of unique visitors, for this I need to upgrade to pro too? I tried changing it, but I don't get a response with request 1d, is it really supported? @Leo sorry for ping, could you help me?
Want results from more Discord servers?
Add your server