Skip to main content
Solved

"metric_id" for Klaviyo API not documented / no values are valid


Forum|alt.badge.img+4

Hi, 

Running into an issue that I cannot seem to find any documentation on, so any help would be very welcome! 

I’m trying to use the Klaviyo Metrics API (documented here). I’m able to successfully execute some queries in my terminal, and I’m ultimately pulling this information into google sheets to run various client reports for their Klaviyo data. Ultimately, I want to pull aggregate metrics by date such as “Active on Site”, “Bounced Email”, “Clicked Email”, “Marked Email as Spam”, etc. The more granular the data, the better, but we’ll see what kind of limits I run into with Google Sheets. 

The problem

While I can successfully execute general queries for all metrics (from this page on their documentation for instance), I cannot execute ANY queries where “metric_id” is a required value. Furthermore, there doesn’t appear to be any documentation on metric_id, or what values are actually valid. 

Example

This page hints that i can pull events for a specific metric. The first field they ask for is “metric_id” for which their “example value” and their “default value” returns an error for. this value is simply METRIC_ID, which I wouldn’t expect to return anything helpful. 

My two part question

Am I on the right track? Will querying their api for events from a specific metric get me what I want here? If so, is there a resource that explains how I can get metric_id’s for various metrics on my Klaviyo accounts? If not, which API should I be digging into to get these types of metrics surfaced?

Any help would be amazing. Thank you!

 

Taylor

Best answer by David To

Hello@ctTaylor,

Welcome to the Klaviyo Community!

As mentioned in our Analytics Glossary Help Center article:

Metric ID: the six-digit ID associated with a given metric. To find the metric ID, navigate to Analytics > Metrics and click into a metric. The metric ID will display within the URL of that page.

As an example, in my screenshot below the Metric_ID for my Checkout Started event would be A1b2C3. This ID can then used as part of my query parameters when making specific calls to the desired metric endpoints.

Additionally, instead of having to reference each metric’s ID individually within your Klaviyo account, making a request to the https://a.klaviyo.com/api/v1/metrics endpoint as mentioned in the Get Metrics Info Developer’s documentation would return a list of all the metrics in your account. This is helpful as it would also return each metric’s specific ID in its response. As detailed in that same documentation, an example response from that call: 

Depending on what it is you were trying to accomplish, it may also be helpful to look at our Export Data from Klaviyo and Klaviyo's Data Model documents on how to export data from Klaviyo. Though, from the sounds of it, leveraging the https://a.klaviyo.com/api/v1/metric/{metric_id}/timeline endpoint should allow you to achieve your goal of querying for a specific metric. 

I hope this helps!

David

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

3 replies

David To
Klaviyo Employee
Forum|alt.badge.img+60
  • Klaviyo Employee
  • 2456 replies
  • Answer
  • March 31, 2022

Hello@ctTaylor,

Welcome to the Klaviyo Community!

As mentioned in our Analytics Glossary Help Center article:

Metric ID: the six-digit ID associated with a given metric. To find the metric ID, navigate to Analytics > Metrics and click into a metric. The metric ID will display within the URL of that page.

As an example, in my screenshot below the Metric_ID for my Checkout Started event would be A1b2C3. This ID can then used as part of my query parameters when making specific calls to the desired metric endpoints.

Additionally, instead of having to reference each metric’s ID individually within your Klaviyo account, making a request to the https://a.klaviyo.com/api/v1/metrics endpoint as mentioned in the Get Metrics Info Developer’s documentation would return a list of all the metrics in your account. This is helpful as it would also return each metric’s specific ID in its response. As detailed in that same documentation, an example response from that call: 

Depending on what it is you were trying to accomplish, it may also be helpful to look at our Export Data from Klaviyo and Klaviyo's Data Model documents on how to export data from Klaviyo. Though, from the sounds of it, leveraging the https://a.klaviyo.com/api/v1/metric/{metric_id}/timeline endpoint should allow you to achieve your goal of querying for a specific metric. 

I hope this helps!

David


Forum|alt.badge.img+4
  • Author
  • Contributor I
  • 1 reply
  • March 31, 2022

Ah, amazing. Perfect. Thanks David. 

A note for whomever is managing both the Glossary you referenced and the api help page, this needs to be better documented. 

The API Page should link directly to that section of the glossary, and the glossary itself should have at least one mention of “metric_id” rather than “Metric ID” since google doesn’t know to index it. Was searching for hours for this.

 

Thanks David!
Taylor


David To
Klaviyo Employee
Forum|alt.badge.img+60
  • Klaviyo Employee
  • 2456 replies
  • March 31, 2022

Hey @ctTaylor,

Thanks for those suggestions! I’ll share your feedback with our documentation!

David