Skip to main content
Solved

Request by Campaign Name also shows Flows

  • December 14, 2022
  • 6 replies
  • 244 views

Forum|alt.badge.img+3
  • Active Contributor I
  • 14 replies

Hi!

I realized that for some of my clients, when I use the segment “Campaign Name”, some of their Flows also show up in the API response. For example, the request I use is: 

https://a.klaviyo.com/api/v1/metric/api_key/export?start_date=2022-11-01&end_date=2022-11-30&count=1000&measurements=count&api_key=PrivateKey=Campaign Name&unit=day

And while the API response contains valid campaigns for my client (such as “Email #1”), it also contains what my client says is a Flow and not a Campaign (such as, for example, “New Customer Thank You: Email #1” or “Browse Abandonment: Email #1”). When I use the segment “$flow” in the request, this flow doesn’t show up in the API response.

I also tried it in the new stable API, using this request (thinking it might be because I still use the legacy API):

{
  "data": {
    "type": "metric-aggregate",
    "attributes": {
      "metric_id": "_____",
      "measurements": [
        "count"
      ],
      "interval": "day",
      "filter": [
        "greater-or-equal(datetime,2022-11-01T00:00:00)",
        "less-than(datetime,2022-11-30T00:00:00)"
      ],
      "page_size": 1000,
      "by": [
         "Campaign Name"
      ]
    }
  }
}

But I get the same API response.

 

Do you know what could be the problem? Is there a way I could ask my client for a screenshot of their Klaviyo platform to help differentiate Campaigns and Flows?

 

Thank you!

Best answer by Brian Turcotte

Hi@Nymesia!

 

Sorry for the delay here - after speaking with Engineering further, it appears that if you use the V3 version of this API, you should be able to apply a filter that essentially says "Where $flow is not set". This would be accomplished by adding a filter not(equals($flow,\"\")):

 

curl --location --request POST 'https://a.klaviyo.com/api/metric-aggregates/' \
--header 'Authorization: Klaviyo-API-Key insert-api-key' \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--header 'revision: 2022-10-17' \
--data-raw '
{
     "data": {
          "type": "metric-aggregate",
          "attributes": {
               "measurements": [
                    "count"
               ],
               "by": [
                    "Campaign Name"
               ],
               "filter": [
                    "greater-or-equal(datetime,2022-12-01T00:00:00)",
                    "less-than(datetime,2023-01-01T00:00:00)",
                    "not(equals($flow,\"\"))"
               ],
               "metric_id": "insert-metric-id",
               "interval": "month",
               "timezone": "UTC"
          }
     }
}
'

 

The current behavior of this API is that you can evaluate whether $flow is equal to an empty string "" , but in the future, we expect to allow for use of null in this case.

 

I hope this helps!

- Brian

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

6 replies

Brian Turcotte
Forum|alt.badge.img+37

Hi @Nymesia and welcome back to the Community!

 

This is a great question! Are you looking for metric data from all Campaigns, or one specific Campaign? This would affect how you would want to filter. If you are only looking for a specific campaign, you might be better off using the general metric API. Knowing more specifics about your end goal will help myself and other Community members to get some more perspective on the issue.

 

I will definitely check with engineering to determine the best way to accomplish your use case, and I’ll update the thread ASAP.

 

Thanks for using the Community!

 

- Brian


Brian Turcotte
Forum|alt.badge.img+37

Hi @Nymesia!

 

I just checked with engineering, and it turns out that there’s actually no way to filter out the flow-attributed results from this query. I completely understand why the "by": [ "Campaign Name" ] filter sounds appropriate in this instance, and it’s actually due to some overlapping naming conventions. In the context of metric-filtering, "Campaign Name" actually refers to the name associated with every individual message regardless of type (it exists in order to isolate messages from their flow). In other words, both flows and campaigns contain the “Campaign Name” attribute. 

 

However, you can isolate the flow messages from the campaigns, by using the following filter:

"by": ["$flow"]

 

Only flows have this unique ID attribute, but unfortunately for this use case, campaigns do not have a parallel $campaign attribute - so using this filter should only yield aggregates from flows. I have raised a product request internally to address this in addition to the potentially-misleading naming convention of the “Campaign Name” attribute.

 

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

- Brian


Forum|alt.badge.img+3
  • Author
  • Active Contributor I
  • 14 replies
  • December 19, 2022

Hey @Brian Turcotte !

 

Thanks for the response! I was actually just looking for a way to separate the Campaigns and Flows from each other, because my clients want an overview of their Campaigns only, and found it weird that the segment “Campaign Name” would also display “flows”. But you response confirms this behaviour.

Do you have a workaround to get the Campaigns only? At the moment, I’m just thinking about querying the API for $flow and “Campaign Name”, and then removing the flows from the “Campaign Name” response to satisfy my clients.

 

Thank you!

 

-Marie


Forum|alt.badge.img+3
  • Author
  • Active Contributor I
  • 14 replies
  • January 16, 2023

Hey @Brian Turcotte!

Just making a quick follow up on that issue: do you have a workaround to get the Campaigns only?

 

Thanks a bunch!

 

-Marie


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

Hi@Nymesia!

 

Sorry for the delay here - after speaking with Engineering further, it appears that if you use the V3 version of this API, you should be able to apply a filter that essentially says "Where $flow is not set". This would be accomplished by adding a filter not(equals($flow,\"\")):

 

curl --location --request POST 'https://a.klaviyo.com/api/metric-aggregates/' \
--header 'Authorization: Klaviyo-API-Key insert-api-key' \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--header 'revision: 2022-10-17' \
--data-raw '
{
     "data": {
          "type": "metric-aggregate",
          "attributes": {
               "measurements": [
                    "count"
               ],
               "by": [
                    "Campaign Name"
               ],
               "filter": [
                    "greater-or-equal(datetime,2022-12-01T00:00:00)",
                    "less-than(datetime,2023-01-01T00:00:00)",
                    "not(equals($flow,\"\"))"
               ],
               "metric_id": "insert-metric-id",
               "interval": "month",
               "timezone": "UTC"
          }
     }
}
'

 

The current behavior of this API is that you can evaluate whether $flow is equal to an empty string "" , but in the future, we expect to allow for use of null in this case.

 

I hope this helps!

- Brian


Forum|alt.badge.img+3
  • Author
  • Active Contributor I
  • 14 replies
  • February 7, 2023

Hey @Brian Turcotte,

 

Thanks for the info! We plan on migrating soon to the new API, so I’m glad I will be able to fix this issue with the new version.

 

Cheers,

Marie