Skip to main content
Solved

Retrieving Campaign IDs from Aggregation API Responses in SMS Campaigns

  • September 15, 2024
  • 1 reply
  • 34 views

Forum|alt.badge.img+2

I am working with SMS campaigns and using the aggregation API with the following filter:

"by": ["$message"]

In the API response, I received a dimension ID, which I initially assumed to be the campaign ID.

{
                    "dimensions": [
                        "RK77F6"
                    ],
                    "measurements": {
                        "unique": [
                            1.0
                        ],
                        "sum_value": [
                            0.0
                        ],
                        "count": [
                            1.0
                        ]
                    }
                }

However, when I retrieve all my campaigns from the endpoint:

https://a.klaviyo.com/api/campaigns/

I noticed that the ID I received from the aggregation API is not the actual campaign ID(“01HTF4Q020NERWDJ0V0J39MQ35”) it campaign's relationship data.

  {
            "type": "campaign",
            "id": "01HTF4Q020NERWDJ0V0J39MQ35",
            "attributes": {
                "name": "20240403 human >> sms20240402-dead-humir-interest-prom",
                "status": "Sent",
                "audiences": {
                    "included": [
                        "Tt28es",
                        "UFuWZy",

                    ],
                    "excluded": [
                        "12345",
                        "23456"

                    ]
                },
                "updated_at": "2024-04-02T18:59:49.085525+00:00",
                "created_at": "2024-04-02T10:12:11.968942+00:00",
                "send_time": "2024-04-02T09:00:00+00:00",
                "send_strategy": {
                    "method": "static",
                    "options_static": {
                        "datetime": "2024-04-02T09:00:00+00:00",
                        "is_local": true,
                        "send_past_recipients_immediately": true
                    },
                    "options_throttled": null,
                    "options_sto": null
                },
                "send_options": {
                    "use_smart_sending": false
                }
            },
            "relationships": {
                "campaign-messages": {
                    "data": [
                        {
                            "type": "campaign-message",
                            "id": "RK77F6"
                        }
                    ],
                    "links": {
                        "self": "https://a.klaviyo.com/api/campaigns/01HTF4Q020NERWDJ0V0J39MQ35/relationships/campaign-messages/",
                        "related": "https://a.klaviyo.com/api/campaigns/01HTF4Q020NERWDJ0V0J39MQ35/campaign-messages/"
                    }
                },
                "tags": {
                    "links": {
                        "self": "https://a.klaviyo.com/api/campaigns/01HTF4Q020NERWDJ0V0J39MQ35/relationships/tags/",
                        "related": "https://a.klaviyo.com/api/campaigns/01HTF4Q020NERWDJ0V0J39MQ35/tags/"
                    }
                }
            },
            "links": {
                "self": "https://a.klaviyo.com/api/campaigns/01HTF4Q020NERWDJ0V0J39MQ35/"
            }
        }

Based on my understanding, when I request the aggregation API with BY "$message", it should return the campaign ID. However, it seems to return a relationship to the campaign ID.

How can I retrieve the actual campaign ID from the results I get in the aggregation API?

Best answer by chloe.strange

Hi @ronen tak

When adding grouping ”by”: [“$message”], you are requesting that the metrics are grouped by $message. That is the reason you are seeing the results for each given campaign-message type. 

Detailed documentation on the by field of the query metrics API can be found here: https://developers.klaviyo.com/en/docs/supported_metrics_and_attributes#request-body-parameters-nested-under-attributes

Please also see this general documentation on using the query metric aggregate endpoint: https://developers.klaviyo.com/en/docs/using_the_query_metric_aggregates_endpoint

Please try re-submitting your request but instead of grouping by $message please try this group by, ”by”: [“Campaign Name”].

~Chloe

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

1 reply

chloe.strange
Community Manager
Forum|alt.badge.img+41
  • Community Manager
  • 426 replies
  • Answer
  • September 23, 2024

Hi @ronen tak

When adding grouping ”by”: [“$message”], you are requesting that the metrics are grouped by $message. That is the reason you are seeing the results for each given campaign-message type. 

Detailed documentation on the by field of the query metrics API can be found here: https://developers.klaviyo.com/en/docs/supported_metrics_and_attributes#request-body-parameters-nested-under-attributes

Please also see this general documentation on using the query metric aggregate endpoint: https://developers.klaviyo.com/en/docs/using_the_query_metric_aggregates_endpoint

Please try re-submitting your request but instead of grouping by $message please try this group by, ”by”: [“Campaign Name”].

~Chloe