I’ve been using the python sdk to query metrics and it was working well up to last month.
This week I have been receiving ‘None” responses. I think tried querying using the requests module as the examples shown in the docs, that returns a “Bad Request for url: https://a.klaviyo.com/api/metric-aggregates/”.
Between last month and this month, the only thing that changed in my query are the date filters.
What could be the cause of this?
import requests
from klaviyo_api import KlaviyoAPI
import connections.keys.klaviyo_keys as klaviyo_keys
payload = { "data": {
"type": "metric-aggregate",
"attributes": {
"metric_id": "HKCzM3",
"measurements": ["count", "sum_value", "unique"],
"interval": "day",
"by": ["$message"],
"filter": ["greater-or-equal(datetime,2023-09-01)",
"less-than(datetime,2023-10-01)"],
"timezone": "America/New_York"
}
}
}
klaviyo = KlaviyoAPI(klaviyo_keys.api_key)
metrics = klaviyo.Metrics.query_metric_aggregates(payload)
print(metrics)
# RETURNS NONE
# ----------------------------------------------------------------
# --------------------------------------------------------------
input()
url = "https://a.klaviyo.com/api/metric-aggregates/"
headers = {
'revision': '2023-10-15',
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': f'Klaviyo-API-Key {klaviyo_keys.api_key}'
}
response = requests.post(url, headers=headers, data=payload)
response.raise_for_status()
print(response.text)
# RETURNS 400 Client Error: Bad Request for url