Skip to main content
Solved

Issue Filtering "metric-aggregates"


Forum|alt.badge.img+2

Hello, I am trying to filter metric-aggregates endpoint to fetch metrics per campaign using the “Campaign Name” filter, but when tried the `Invalid filter supplied` error pops up. This seems to happen with all filters with a space between multiple words. Here is the request:

{   
    "data":
        {
            "type" : "metric-aggregate",
            "attributes" : 
                { "interval" : "month",
                  "metric_id" : "TGxjH2",
                  "measurements" : ["count"],
                  "filter": [ "greater-or-equal(datetime,2022-01-01T11:00:00Z)", 
                            "less-than(datetime,2023-01-01T11:00:00Z)", 
                            "equals(Campaign Name,'test')"]
                }
        }
}

 

Best answer by Brian Turcotte

Hi @aleksa.gavrilovic!

 

Sorry for the delay in getting back, it seems that someone accidentally marked a Best Answer prematurely!

 

I think I see what’s going on here - the Campaign Name parameter is actually not a filter, but rather a dimension to be used under the “by” attribute. Per our documentation on this endpoint, the filter header can only apply to date-related fields:

  • filter: list of filters for specific fields, must include time range using ISO 8601 format ("YYYY-MM-DDTHH:MM:SS.mmmmmm")
    • The time range can be filtered by providing a greater-or-equal filter on the datetime field, such as "greater-or-equal(datetime,2021-07-01T00:00:00)" and a less-than filter on the same datetime field, such as "less-than(datetime,2022-07-01T00:00:00)"
    • The time range may span a maximum of one year. Time range dates may be set to a maximum of 5 years prior to the current date
    • Filter the list of supported aggregate dimensions using the common filter syntax, such as "equals(URL,\"https://www.klaviyo.com/\")"

 

The “Campaign Name” parameter is only for use under the “by” attribute, which groups the response by aggregated function:

  • by: optional attributes used to group by the aggregation function
    • When using by attributes, an empty dimensions response is expected when the counts for the events do not have the associated dimension requested by the set by attribute. For example, a query including "by": ["$flow"] will return an empty dimensions response for counts of metrics not associated with a $flow

 

 

I hope this helps to clarify, and thanks for using the Community!

- Brian

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

3 replies

Brian Turcotte
Forum|alt.badge.img+37

Hi @aleksa.gavrilovic and welcome to the Community!

 

Would you be willing to provide a screenshot of the actual error message so that myself and other Community members can gather some more context (with sensitive information redacted)?

 

Also, does the error still occur if you use the “contains” operation instead of equals?

"filter": ["equals(Campaign Name,'test')"]

 

I’ll look into this further and get back to the thread ASAP, but this information will be helpful to investigate.

 

Thanks for using the Community!

- Brian


Forum|alt.badge.img+2

​Hi, @Brian Turcotte thanks for the fast reply!


I’ve tried all of the available string functions but still get the same error. As I said this happens with all filters that have multiple words separated by a space (e.g. Client Type, Message Name etc.), but works fine with URL e.g. Could it be that I’m using the system incorrectly?

Here is the error that I’m getting in all of the cases I stated above:



Brian Turcotte
Forum|alt.badge.img+37
  • Klaviyo Alum
  • 1393 replies
  • Answer
  • February 21, 2023

Hi @aleksa.gavrilovic!

 

Sorry for the delay in getting back, it seems that someone accidentally marked a Best Answer prematurely!

 

I think I see what’s going on here - the Campaign Name parameter is actually not a filter, but rather a dimension to be used under the “by” attribute. Per our documentation on this endpoint, the filter header can only apply to date-related fields:

  • filter: list of filters for specific fields, must include time range using ISO 8601 format ("YYYY-MM-DDTHH:MM:SS.mmmmmm")
    • The time range can be filtered by providing a greater-or-equal filter on the datetime field, such as "greater-or-equal(datetime,2021-07-01T00:00:00)" and a less-than filter on the same datetime field, such as "less-than(datetime,2022-07-01T00:00:00)"
    • The time range may span a maximum of one year. Time range dates may be set to a maximum of 5 years prior to the current date
    • Filter the list of supported aggregate dimensions using the common filter syntax, such as "equals(URL,\"https://www.klaviyo.com/\")"

 

The “Campaign Name” parameter is only for use under the “by” attribute, which groups the response by aggregated function:

  • by: optional attributes used to group by the aggregation function
    • When using by attributes, an empty dimensions response is expected when the counts for the events do not have the associated dimension requested by the set by attribute. For example, a query including "by": ["$flow"] will return an empty dimensions response for counts of metrics not associated with a $flow

 

 

I hope this helps to clarify, and thanks for using the Community!

- Brian