Solved

Query Metric Aggregates - Can't group by multiple fields

  • 25 October 2022
  • 5 replies
  • 144 views

Userlevel 1
Badge

I would like to be able to group by multiple fields in my query.

In my query I set "by": ["Campaign Name", "Subject", "Bounce Type"], 

However, whenever I do so I get the below error:

Length of ‘by’ must be <= 1

 

Based on the docs it appears that grouping by multiple fields is possible - if not can this be made available? It would prove extremely useful 

icon

Best answer by ben.liang 31 October 2022, 16:51

View original

5 replies

Userlevel 5
Badge +27

Hello @rpaul12 and welcome back to the Community!

 

May I ask you to provide the documentation you are referring to so that I can get a better perspective on the issue?

 

With some more context, I can figure out whether or not the documentation needs to be updated and/or a product request made to our Product Team.

 

Thanks for being a Community Member!

 

-Brian

Userlevel 1
Badge

Sure so looking at: https://developers.klaviyo.com/en/reference/query_metric_aggregates

If I expand the body params tab I see the following:

It seems to indicate that multiple fields can be added to the “by” array, but when I try this on my machine, I get the above error.

 

 

Badge

@Brian Turcotte @ben.liang thoughts? we’re blocked on using the new API for this

Badge

Hey @rpaul12 and @daniellanger ! We can probably add additional grouping fields to this endpoint, we wanted to start off small though in order to avoid extremely complex queries that may bog down our backend. Out of curiosity, how many additional groups would satisfy your respective use cases? @rpaul12 would you be able to make do with 2 group-by’s, or is your posted list of three a firm requirement for this to be useful for you?

Badge

@ben.liang For our use case, we’d need to be able to breakdown the data by a flexible number. Right now, we are grabbing many properties from metrics from the v1/timeline endpoint and applying them as tags. These properties vary by metric, and grow based on customer requests. Therefore, having a hard limit is tough from an adoption POV. Maybe there is some “data response limit” where we maybe couldn’t request a full YEAR of data broken down by 5+ tags, but rather only a day at a time. Otherwise, we’ll have to continue using the timeline endpoint so we get full access to metadata. Does this make sense?

Reply