Skip to main content
Solved

Is there an API endpoint to fetch campaign stats?


Forum|alt.badge.img+1
  • Contributor I
  • 2 replies

We are sending daily email campaigns to our subscribers. We use Tableau for reporting. I need to fetch campaign performance stats (emails sent, opens count, clicks count, unsubs count, etc.) using the API. 

I see that I can query the API and fetch list of campaigns, etc. but I don’t see an API endpoint to fetch stats. Am I missing something? What the best way to get stats from Klaviyo?

Best answer by David To

Hello@red3i,

Welcome to the Klaviyo Community!

This is something supported under our query metric aggregate endpoint. I would suggest taking a read through our (New) Using the Query Metric Aggregates Endpoint Developer Guide which covers this and offer some example calls. 

For example, to query unique opens for all sent messages you can use:

{  
    "data": {  
         "type": "metric-aggregate",  
         "attributes": {  
              "measurements": [  
                   "unique"  
              ],  
              "filter": [  
                  "greater-or-equal(datetime,2022-01-01)",  
                  "less-than(datetime,2022-12-31)"  
              ],  
              "by": ["$message"],  
              "interval": "month",  
              "timezone": "US/Eastern",  
              "metric_id": "QhyxVR"  
         }  
    }  
}

For unique opens for a specific message, you can use:

{  
    "data": {  
         "type": "metric-aggregate",  
         "attributes": {  
              "measurements": [  
                   "unique"  
              ],  
              "filter": [  
                  "greater-or-equal(datetime,2022-01-01)",  
                  "less-than(datetime,2022-12-31)",  
                  "equals($message,\"01GAQWA31SZKABEZJNXDBGW2F1\")"  
              ],  
              "interval": "month",  
              "timezone": "US/Eastern",  
              "metric_id": "QhyxVR"  
         }  
    }  
}

 I hope this helps!

David

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

2 replies

David To
Klaviyo Employee
Forum|alt.badge.img+60
  • Klaviyo Employee
  • 2456 replies
  • Answer
  • May 10, 2023

Hello@red3i,

Welcome to the Klaviyo Community!

This is something supported under our query metric aggregate endpoint. I would suggest taking a read through our (New) Using the Query Metric Aggregates Endpoint Developer Guide which covers this and offer some example calls. 

For example, to query unique opens for all sent messages you can use:

{  
    "data": {  
         "type": "metric-aggregate",  
         "attributes": {  
              "measurements": [  
                   "unique"  
              ],  
              "filter": [  
                  "greater-or-equal(datetime,2022-01-01)",  
                  "less-than(datetime,2022-12-31)"  
              ],  
              "by": ["$message"],  
              "interval": "month",  
              "timezone": "US/Eastern",  
              "metric_id": "QhyxVR"  
         }  
    }  
}

For unique opens for a specific message, you can use:

{  
    "data": {  
         "type": "metric-aggregate",  
         "attributes": {  
              "measurements": [  
                   "unique"  
              ],  
              "filter": [  
                  "greater-or-equal(datetime,2022-01-01)",  
                  "less-than(datetime,2022-12-31)",  
                  "equals($message,\"01GAQWA31SZKABEZJNXDBGW2F1\")"  
              ],  
              "interval": "month",  
              "timezone": "US/Eastern",  
              "metric_id": "QhyxVR"  
         }  
    }  
}

 I hope this helps!

David


Forum|alt.badge.img+1
  • Author
  • Contributor I
  • 2 replies
  • May 11, 2023

Thank you David. Appreciate your response!