Skip to main content
Problem Solver I
October 25, 2022
Solved

Query Metric Aggregates - Can't group by multiple fields

  • October 25, 2022
  • 5 replies
  • 331 views

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 

    This topic has been closed for replies.
    Best answer by ben.liang

    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?

    5 replies

    Brian Turcotte
    Klaviyo Alum
    October 26, 2022

    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

    rpaul12Author
    Problem Solver I
    October 27, 2022

    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.

     

     

    Contributor II
    October 31, 2022

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

    ben.liangAnswer
    Klaviyo Employee
    October 31, 2022

    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?

    Contributor II
    October 31, 2022

    @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?