Skip to main content
Solved

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

  • November 16, 2023
  • 3 replies
  • 122 views

Forum|alt.badge.img+1

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?

Best answer by saulblum

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

View original
Did this topic or the replies in the thread help you find an answer to your question?

3 replies

Forum|alt.badge.img+7
  • Klaviyo Employee
  • 169 replies
  • November 16, 2023

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'
)

 


Forum|alt.badge.img+1
  • Author
  • Contributor II
  • 3 replies
  • November 16, 2023

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?


Forum|alt.badge.img+7
  • Klaviyo Employee
  • 169 replies
  • Answer
  • November 16, 2023

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