Solved

Get All Events In Account for Specific Date Range and Specific Metric_ID(s)

  • 16 November 2023
  • 3 replies
  • 52 views

Badge

This was possible using the old version of the Python SDK however it does not appear to be possible here (or I”m missing).  I’d like to grab all events in my account but only those that pertain to a certain set of metric_ids and for a specific time range.   The problem with just grabbing all events is that on certain days, I’m grabbing 1million+ events which I don’t need.  I’m hoping if I can narrow my query to a certain metric Id my query would take a lot less time.

 

Is this possible with the new version of the API?

icon

Best answer by saulblum 16 November 2023, 18:30

View original

3 replies

Userlevel 4
Badge +7

You’d want to set a time range in the filter param, e.g.

klaviyo.Events.get_events(
    fields_event=['event_properties'], 
    filter="equals(metric_id,\"aBc123\"),greater-than(datetime,2023-01-01T00:00:00Z),less-than(datetime,2023-01-02T00:00:00Z)", 
    sort='-datetime'
)

 

Badge

Thank you! One more question, would limiting the set of fields I want, possibly make the API calls faster or does that not have anything to do with the number of requests I can make?

For example, if I only cared about:
id, 
event_properties.$message,
event_properties.$event_id,
relationships.profiles.data.id

How could I modify the API call and would this even help?

Userlevel 4
Badge +7

You mean with sparse fieldsets? https://developers.klaviyo.com/en/reference/api_overview#sparse-fieldsets

It won’t change the Get Events rate limit but will shrink the response size, so any code calling the API might process faster with a smaller response to parse.

As for properties you can fetch, for fields[event] it’s ['datetime', 'event_properties', 'id', 'timestamp', 'uuid'].

The ID of the event’s profile will already be returned, but you can fetch additional properties like first_name and email without having to make a separate API call to get the profile, e.g.

https://a.klaviyo.com/api/events/?filter=equals(metric_id,"ABC123")&fields[profile]=email&include=profile

Reply