Hi,
We have been struggling to get the appropriate data using the new version of the API. The reason for this is because the results from the dashboard do not match the ones from the API. So, the question is how to create an exact match of the Campagin Performance Report using the API service? We believe that if we are able to figure this out, we should be able to replicate the other reports too. Firstly, let’s assume we want this report:
![](https://uploads-us-west-2.insided.com/klaviyo-en/attachment/6b34c395-3612-4226-9894-d4bcb80f92e5.png)
Which in return gives us (not all data is shown for simplicity):
![](https://uploads-us-west-2.insided.com/klaviyo-en/attachment/b36e568a-98eb-440d-97ba-769b14adf682.png)
Our implementation, step by step:
- We are using the python sdk (API returns similar results too) https://github.com/klaviyo/klaviyo-api-python
- We get the metric id by running: client.Metrics.get_metrics() (In this case, open emails id is LwHApy and Placed Order one is VKACVC)
- Then we call the campaign api to get the campaign info.
client.Campaigns.get_campaigns( filter=( f"greater-or-equal(created_at,{date_from})," f"less-or-equal(created_at,{date_to})," "equals(messages.channel,'email')" ), include=["campaign-messages"], )
- Next, we call the metric-aggregates endpoint two times to get the open emails metric and total placed orders
body = { "data": { "type": "metric-aggregate", "attributes": { "metric_id": metric.get("id"), "interval": "day", "page_size": 500, # "page_cursor": "", "timezone": "UTC", "measurements": ["count", "sum_value", "unique"], "filter": [ f"greater-or-equal(datetime,{date_from})", f"less-than(datetime,{date_to})", ], # "return_fields": [metric.get("id")], "by": ["$attributed_message"], }, } } metric_aggregates = client.Metrics.query_metric_aggregates_with_http_info(body)
- Issues after running metric-aggregates:
- Placed Order: Result does not match with the one from the dashboard for the same campaign id.
- Open emails: Returns no dimension data, only results. So, how to know which data belongs to what campaign id.
Although the API works, the data returned is not the same with the one we get from the dashboard. The question here is: What are the necessary steps to reach to the same result as in the dashboard?
We are happy that the new API is much more powerful than the older version, but it is somewhat unclear what should be the combination of fields such that the data returned matches the dashboard.