Exporting Event Data for a Specific Time Range

  • 16 October 2020
  • 1 reply

Userlevel 2
Badge +5

Klaviyo's Metrics endpoint does not provide a method by which you can easily fetch events (metrics) within a specified date range. The metrics/{metric_id}/timeline endpoint takes a ‘since’ and a sort parameter. What is not well documented is that the sort parameter manipulates the returned data in two ways as it defines the direction and also the side of the ‘since’ parameter for which data is returned.

The best way to illustrate this is a request without a ‘since’ parameter (defaults to now) and toggling the sort parameter (defaults to desc). The default request without either param specified returns all events (paginated) before the ‘since parameter’ (now, the time of the request). A request with only the sort parameter set to "asc" will return an empty array because there are no events that can be returned after the ‘since’ parameter (these events are in the future and haven't been recorded yet).


Alternatively, you can export aggregated event data by using the metrics/{metric_id}/timeline endpoint for specific time ranges. 

For the api endpoint reference, please see here: https://www.klaviyo.com/docs/api/metrics#metric-timeline

1 reply

Badge +2

I am also in favor of the above suggestion.
I need to pull back lots of event data and using the current functionality of “since” only provides the ability to look at one side or another of a date.

Few suggestions: 

1, the name of this parameter “since” is misleading compared to its function.  

2, Instead of “since” and “sort”, perhaps two optional date parameters (from and to) would be better, where “from” defaults to 0 (unixtime) and “to” defaults to now. A third sort option would be ideal, but I would sacrifice that for the from/to.

3, While the above are much higher priority, being able to then further filter this request by event properties would be super great.