Skip to main content
Solved

Discrepancy Between Metric-Aggregates Campaign Data and Get Campaigns Endpoint

  • December 15, 2024
  • 9 replies
  • 51 views

Forum|alt.badge.img+2

I am using the metric-aggregates API with the following request body:

{
    "data": {
        "type": "metric-aggregate",
        "attributes": {
            "measurements": [
                "unique",
                "sum_value",
                "count"
            ],
            "filter": [
                "greater-or-equal(datetime,2024-09-18)",
                "less-than(datetime,2024-10-17)"
            ],
            "by": [
            "$message"
],
            "interval": "month",
            "metric_id": "VDpVWX",
            "page_size": 500
        }
    }
}

In the response, I noticed the following under the dimensions section:

"dimensions": ["RD499B"]

However, when I use the Get Campaigns endpoint:

https://a.klaviyo.com/api/campaigns/?filter=equals(messages.channel,'email')

I am unable to find a campaign with the ID RD499B. While some campaigns are listed in the response, others seem missing.

Additionally, when I modify the metric-aggregates request to include:

"by": ["$message", "Campaign Name"]

I do get the campaign name in the response.

If the Campaign Name is available through the metric-aggregates API, why doesn’t the corresponding campaign ID appear in the Get Campaigns endpoint?

Could you clarify the reason for this discrepancy?

 

Best answer by MANSIR2094

yhh…. you are welcome Ronen Tak,


Since Klaviyo doesn’t label standard campaigns with a specific type, you can try filtering by a naming pattern. If your campaigns have a consistent naming format (e.g., including "Std"), you can filter by Campaign Name using contains($message.name,'Std').

If no pattern exists, you may need to tag standard campaigns (if Klaviyo allows it) or check for unique attributes in the data that set them apart. As a last resort, export the data and manually filter for standard campaigns.

Let me know if you'd like further guidance!

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

9 replies

ArpitBanjara
Principal User I
Forum|alt.badge.img+36
  • Principal User I
  • 371 replies
  • December 16, 2024

Hey ​@ronen tak 

can you confirm that the Campaigns missing from the Get Campaigns endpoint are drafts, archived, or flow emails?


Forum|alt.badge.img+2
  • Author
  • Problem Solver I
  • 15 replies
  • December 16, 2024

Hay ​@ArpitBanjara 

they are not.

 


Forum|alt.badge.img+2
  • Author
  • Problem Solver I
  • 15 replies
  • December 16, 2024

I’ve identified what this is: it’s an event.

When I use the following endpoint:
https://a.klaviyo.com/api/events?fields[event]=event_properties

I can see that it’s related to a campaign.

My question is: if this is categorized as a campaign, why isn’t it accessible through the regular GET campaigns endpoint?


talhahussain
Problem Solver IV
Forum|alt.badge.img+8
  • Problem Solver IV
  • 76 replies
  • December 16, 2024

Answer:

The discrepancy occurs because not all campaigns or messages in the metric-aggregates API are accessible through the GET Campaigns endpoint. This behavior can arise due to:

  1. Different Data Sources:

    • The metric-aggregates API aggregates metrics from all events, including email sends, opens, and clicks, regardless of whether the message originates from a flow, campaign, or other triggers.
    • The GET Campaigns endpoint specifically returns standard campaigns, excluding certain types of messages like flow emails or archived campaigns.
  2. Event-Centric Metrics:

    • When you see a message ID (e.g., RD499B) in the metric-aggregates response, it may represent an event or flow-related message, which does not qualify as a campaign under the GET Campaigns endpoint.
  3. Campaign Name Inclusion:

    • By including "by": ["$message", "Campaign Name"] in the metric-aggregates API, you can fetch the campaign name because the message ID is still linked to historical event data.

Key Takeaway:

The metric-aggregates API provides insights into events (messages) broadly, including campaigns, flows, and other messages, while the GET Campaigns endpoint is limited to standard campaigns. To get a holistic view, consider combining event data with the Campaigns API where applicable.

If further clarification is needed, reviewing the event payload via /api/events can help pinpoint the message source and its relationship to campaigns.


Forum|alt.badge.img+2
  • Author
  • Problem Solver I
  • 15 replies
  • December 17, 2024

@talhahussain 

thank you for your answer 

Do you know if there is an option to filter metric aggregates that only return standard campaigns?


MANSIR2094
Problem Solver IV
Forum|alt.badge.img+13
  • Problem Solver IV
  • 188 replies
  • December 21, 2024

Hello ronen tak,
 

The difference you're experiencing may be due to how Klaviyo associates campaign data across different APIs:

  1. Metric-Aggregates API Context: This API often returns unique internal identifiers, like "RD499B," which may represent specific messages or aggregated data, not directly matching the campaign ID from the Get Campaigns endpoint.

  2. Campaign Name in Metric-Aggregates: When you add "Campaign Name" as an additional grouping, Klaviyo can reference names because it matches data across dimensions, even if the ID is not part of the Get Campaigns list. Campaign IDs in the Get Campaigns endpoint usually reflect active or recent campaigns.

  3. Possible Discrepancy Reasons:

    • Archived or Older Campaigns: Some campaigns might not appear in the current Get Campaigns list if they are archived or no longer active.
    • Partial Data Sync: Ensure your API access keys have the right permissions and that all relevant campaigns are synced.

If this remains complex or you need personalized guidance, feel free to reach out via WhatsApp at [+2349151237531]. I’m happy to assist further!


MANSIR2094
Problem Solver IV
Forum|alt.badge.img+13
  • Problem Solver IV
  • 188 replies
  • December 21, 2024

To filter metric aggregates to return only data for standard campaigns (excluding flows or other non-campaign messages), you can include a filter targeting the message's type or attributes associated with campaigns. Unfortunately, Klaviyo's Metric Aggregates API doesn’t directly allow filtering by “campaign type” at this level, but you can achieve this by:

Adding a Custom Filter

Modify your request body to include a filter for equals($message.type,'campaign'). For example:

 

json

Copy code

{ "data": { "type": "metric-aggregate", "attributes": { "measurements": [ "unique", "sum_value", "count" ], "filter": [ "greater-or-equal(datetime,2024-09-18)", "less-than(datetime,2024-10-17)", "equals($message.type,'campaign')" ], "by": [ "$message", "Campaign Name" ], "interval": "month", "metric_id": "VDpVWX", "page_size": 500 } } }

This should return results filtered to standard campaigns only, assuming Klaviyo categorizes standard campaigns with a specific type like 'campaign'.

If you’re unsure about the exact attribute to filter by, you can:

  1. Check Klaviyo’s API documentation or reach out to their support for clarification.
  2. Use exploratory queries to inspect returned data and identify the correct filter criteria.

Forum|alt.badge.img+2
  • Author
  • Problem Solver I
  • 15 replies
  • December 24, 2024

@MANSIR2094 

Thank you for your help!

I looked into the suggestion regarding the filter, but unfortunately, Klaviyo doesn't categorize standard campaigns under a specific type like 'campaign'.

As a result, I'm still facing the challenge of filtering exclusively for standard campaigns.


MANSIR2094
Problem Solver IV
Forum|alt.badge.img+13
  • Problem Solver IV
  • 188 replies
  • Answer
  • December 24, 2024

yhh…. you are welcome Ronen Tak,


Since Klaviyo doesn’t label standard campaigns with a specific type, you can try filtering by a naming pattern. If your campaigns have a consistent naming format (e.g., including "Std"), you can filter by Campaign Name using contains($message.name,'Std').

If no pattern exists, you may need to tag standard campaigns (if Klaviyo allows it) or check for unique attributes in the data that set them apart. As a last resort, export the data and manually filter for standard campaigns.

Let me know if you'd like further guidance!