Skip to main content

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?

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

klaviyo.Events.get_events(
    fields_event=e'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'
)

 


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?


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 fieldseevent] it’s t'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")&fieldsmprofile]=email&include=profile


Reply