Class: KlaviyoAPI::MetricsApi

Inherits:
Object
  • Object
show all
Defined in:
lib/klaviyo-api-sdk/api/metrics_api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_client = ApiClient.default) ⇒ MetricsApi

Returns a new instance of MetricsApi.



18
19
20
# File 'lib/klaviyo-api-sdk/api/metrics_api.rb', line 18

def initialize(api_client = ApiClient.default)
  @api_client = api_client
end

Instance Attribute Details

#api_clientObject

Returns the value of attribute api_client.



16
17
18
# File 'lib/klaviyo-api-sdk/api/metrics_api.rb', line 16

def api_client
  @api_client
end

Instance Method Details

#create_custom_metric(custom_metric_create_query, opts = {}) ⇒ Hash<String, Object>

Create Custom Metric Create a new custom metric. Custom metric objects must include a ‘name` and `definition`.
*Rate limits*:
Burst: `1/s`
Steady: `15/m`
Daily: `15/d` Scopes: `metrics:write`

Parameters:

  • custom_metric_create_query (CustomMetricCreateQuery)

    Create a custom metric.

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:

  • (Hash<String, Object>)


26
27
28
29
# File 'lib/klaviyo-api-sdk/api/metrics_api.rb', line 26

def create_custom_metric(custom_metric_create_query, opts = {})
  data, _status_code, _headers = create_custom_metric_with_http_info(custom_metric_create_query, opts)
  data
end

#create_custom_metric_with_http_info(custom_metric_create_query, opts = {}) ⇒ Array<(Hash<String, Object>, Integer, Hash)>

Create Custom Metric Create a new custom metric. Custom metric objects must include a &#x60;name&#x60; and &#x60;definition&#x60;.&lt;br&gt;&lt;br&gt;*Rate limits*:&lt;br&gt;Burst: &#x60;1/s&#x60;&lt;br&gt;Steady: &#x60;15/m&#x60;&lt;br&gt;Daily: &#x60;15/d&#x60; Scopes: &#x60;metrics:write&#x60;

Parameters:

  • custom_metric_create_query (CustomMetricCreateQuery)

    Create a custom metric.

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:

  • (Array<(Hash<String, Object>, Integer, Hash)>)

    Hash<String, Object> data, response status code and response headers



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/klaviyo-api-sdk/api/metrics_api.rb', line 36

def create_custom_metric_with_http_info(custom_metric_create_query, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: MetricsApi.create_custom_metric ...'
  end
  # verify the required parameter 'custom_metric_create_query' is set
  if @api_client.config.client_side_validation && custom_metric_create_query.nil?
    fail ArgumentError, "Missing the required parameter 'custom_metric_create_query' when calling MetricsApi.create_custom_metric"
  end
  # resource path
  local_var_path = '/api/custom-metrics'

  # query parameters
  query_params = opts[:query_params] || {}

  # header parameters
  header_params = opts[:header_params] || {}
  # klaviyo api revision
  header_params['revision'] =  ENV['KLAVIYO_API_REVISION'] || ENV['API_REVISION'] || "2025-07-15"
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/vnd.api+json'])
  # HTTP header 'Content-Type'
  content_type = @api_client.select_header_content_type(['application/vnd.api+json'])
  if !content_type.nil?
      header_params['Content-Type'] = content_type
  end

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:debug_body] || @api_client.object_to_http_body(custom_metric_create_query)

  # return_type
  return_type = opts[:debug_return_type] || 'Hash<String, Object>'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['Klaviyo-API-Key', 'OAuth']

  new_options = opts.merge(
    :operation => :"MetricsApi.create_custom_metric",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: MetricsApi#create_custom_metric\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#delete_custom_metric(id, opts = {}) ⇒ nil

Delete Custom Metric Delete a custom metric with the given custom metric ID.
*Rate limits*:
Burst: ‘3/s`
Steady: `60/m` Scopes: `metrics:write`

Parameters:

  • id (String)

    The ID of the custom metric

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:

  • (nil)


96
97
98
99
# File 'lib/klaviyo-api-sdk/api/metrics_api.rb', line 96

def delete_custom_metric(id, opts = {})
  delete_custom_metric_with_http_info(id, opts)
  nil
end

#delete_custom_metric_with_http_info(id, opts = {}) ⇒ Array<(nil, Integer, Hash)>

Delete Custom Metric Delete a custom metric with the given custom metric ID.&lt;br&gt;&lt;br&gt;*Rate limits*:&lt;br&gt;Burst: &#x60;3/s&#x60;&lt;br&gt;Steady: &#x60;60/m&#x60; Scopes: &#x60;metrics:write&#x60;

Parameters:

  • id (String)

    The ID of the custom metric

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:

  • (Array<(nil, Integer, Hash)>)

    nil, response status code and response headers



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/klaviyo-api-sdk/api/metrics_api.rb', line 106

def delete_custom_metric_with_http_info(id, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: MetricsApi.delete_custom_metric ...'
  end
  # verify the required parameter 'id' is set
  if @api_client.config.client_side_validation && id.nil?
    fail ArgumentError, "Missing the required parameter 'id' when calling MetricsApi.delete_custom_metric"
  end
  # resource path
  local_var_path = '/api/custom-metrics/{id}'.sub('{' + 'id' + '}', CGI.escape(id.to_s))

  # query parameters
  query_params = opts[:query_params] || {}

  # header parameters
  header_params = opts[:header_params] || {}
  # klaviyo api revision
  header_params['revision'] =  ENV['KLAVIYO_API_REVISION'] || ENV['API_REVISION'] || "2025-07-15"
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/vnd.api+json'])

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:debug_body]

  # return_type
  return_type = opts[:debug_return_type]

  # auth_names
  auth_names = opts[:debug_auth_names] || ['Klaviyo-API-Key', 'OAuth']

  new_options = opts.merge(
    :operation => :"MetricsApi.delete_custom_metric",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:DELETE, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: MetricsApi#delete_custom_metric\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#get_custom_metric(id, opts = {}) ⇒ Hash<String, Object>

Get Custom Metric Get a custom metric with the given custom metric ID.
*Rate limits*:
Burst: ‘3/s`
Steady: `60/m` Scopes: `metrics:read`

Parameters:

  • id (String)

    The ID of the custom metric

  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

Returns:

  • (Hash<String, Object>)


164
165
166
167
# File 'lib/klaviyo-api-sdk/api/metrics_api.rb', line 164

def get_custom_metric(id, opts = {})
  data, _status_code, _headers = get_custom_metric_with_http_info(id, opts)
  data
end

#get_custom_metric_for_mapped_metric(id, opts = {}) ⇒ Hash<String, Object> Also known as: get_mapped_metric_custom_metric

Get Custom Metric for Mapped Metric Get the custom metric for the given mapped metric ID (if applicable).
*Rate limits*:
Burst: ‘3/s`
Steady: `60/m` Scopes: `metrics:read`

Parameters:

  • id (String)

    The type of mapping.

  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

Returns:

  • (Hash<String, Object>)


248
249
250
251
# File 'lib/klaviyo-api-sdk/api/metrics_api.rb', line 248

def get_custom_metric_for_mapped_metric(id, opts = {})
  data, _status_code, _headers = get_custom_metric_for_mapped_metric_with_http_info(id, opts)
  data
end

#get_custom_metric_for_mapped_metric_with_http_info(id, opts = {}) ⇒ Array<(Hash<String, Object>, Integer, Hash)> Also known as: get_mapped_metric_custom_metric_with_http_info

Get Custom Metric for Mapped Metric Get the custom metric for the given mapped metric ID (if applicable).&lt;br&gt;&lt;br&gt;*Rate limits*:&lt;br&gt;Burst: &#x60;3/s&#x60;&lt;br&gt;Steady: &#x60;60/m&#x60; Scopes: &#x60;metrics:read&#x60;

Parameters:

  • id (String)

    The type of mapping.

  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

Returns:

  • (Array<(Hash<String, Object>, Integer, Hash)>)

    Hash<String, Object> data, response status code and response headers



262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
# File 'lib/klaviyo-api-sdk/api/metrics_api.rb', line 262

def get_custom_metric_for_mapped_metric_with_http_info(id, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: MetricsApi.get_custom_metric_for_mapped_metric ...'
  end
  # verify the required parameter 'id' is set
  if @api_client.config.client_side_validation && id.nil?
    fail ArgumentError, "Missing the required parameter 'id' when calling MetricsApi.get_custom_metric_for_mapped_metric"
  end
  # verify enum value
  allowable_values = ["added_to_cart", "cancelled_sales", "ordered_product", "refunded_sales", "revenue", "started_checkout", "viewed_product"]
  if @api_client.config.client_side_validation && !allowable_values.include?(id)
    fail ArgumentError, "invalid value for \"id\", must be one of #{allowable_values}"
  end
  allowable_values = ["name", "created", "updated", "definition", "definition.aggregation_method", "definition.metric_groups"]
  if @api_client.config.client_side_validation && opts[:'fields_custom_metric'] && !opts[:'fields_custom_metric'].all? { |item| allowable_values.include?(item) }
    fail ArgumentError, "invalid value for \"fields_custom_metric\", must include one of #{allowable_values}"
  end
  # resource path
  local_var_path = '/api/mapped-metrics/{id}/custom-metric'.sub('{' + 'id' + '}', CGI.escape(id.to_s))

  # query parameters
  query_params = opts[:query_params] || {}
  query_params[:'fields[custom-metric]'] = @api_client.build_collection_param(opts[:'fields_custom_metric'], :csv) if !opts[:'fields_custom_metric'].nil?

  # header parameters
  header_params = opts[:header_params] || {}
  # klaviyo api revision
  header_params['revision'] =  ENV['KLAVIYO_API_REVISION'] || ENV['API_REVISION'] || "2025-07-15"
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/vnd.api+json'])

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:debug_body]

  # return_type
  return_type = opts[:debug_return_type] || 'Hash<String, Object>'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['Klaviyo-API-Key', 'OAuth']

  new_options = opts.merge(
    :operation => :"MetricsApi.get_custom_metric_for_mapped_metric",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: MetricsApi#get_custom_metric_for_mapped_metric\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#get_custom_metric_id_for_mapped_metric(id, opts = {}) ⇒ Hash<String, Object> Also known as: get_mapped_metric_relationships_custom_metric

Get Custom Metric ID for Mapped Metric Get the ID of the custom metric for the given mapped metric.
*Rate limits*:
Burst: ‘3/s`
Steady: `60/m` Scopes: `metrics:read`

Parameters:

  • id (String)

    The type of mapping.

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:

  • (Hash<String, Object>)


330
331
332
333
# File 'lib/klaviyo-api-sdk/api/metrics_api.rb', line 330

def get_custom_metric_id_for_mapped_metric(id, opts = {})
  data, _status_code, _headers = get_custom_metric_id_for_mapped_metric_with_http_info(id, opts)
  data
end

#get_custom_metric_id_for_mapped_metric_with_http_info(id, opts = {}) ⇒ Array<(Hash<String, Object>, Integer, Hash)> Also known as: get_mapped_metric_relationships_custom_metric_with_http_info

Get Custom Metric ID for Mapped Metric Get the ID of the custom metric for the given mapped metric.&lt;br&gt;&lt;br&gt;*Rate limits*:&lt;br&gt;Burst: &#x60;3/s&#x60;&lt;br&gt;Steady: &#x60;60/m&#x60; Scopes: &#x60;metrics:read&#x60;

Parameters:

  • id (String)

    The type of mapping.

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:

  • (Array<(Hash<String, Object>, Integer, Hash)>)

    Hash<String, Object> data, response status code and response headers



343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
# File 'lib/klaviyo-api-sdk/api/metrics_api.rb', line 343

def get_custom_metric_id_for_mapped_metric_with_http_info(id, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: MetricsApi.get_custom_metric_id_for_mapped_metric ...'
  end
  # verify the required parameter 'id' is set
  if @api_client.config.client_side_validation && id.nil?
    fail ArgumentError, "Missing the required parameter 'id' when calling MetricsApi.get_custom_metric_id_for_mapped_metric"
  end
  # verify enum value
  allowable_values = ["added_to_cart", "cancelled_sales", "ordered_product", "refunded_sales", "revenue", "started_checkout", "viewed_product"]
  if @api_client.config.client_side_validation && !allowable_values.include?(id)
    fail ArgumentError, "invalid value for \"id\", must be one of #{allowable_values}"
  end
  # resource path
  local_var_path = '/api/mapped-metrics/{id}/relationships/custom-metric'.sub('{' + 'id' + '}', CGI.escape(id.to_s))

  # query parameters
  query_params = opts[:query_params] || {}

  # header parameters
  header_params = opts[:header_params] || {}
  # klaviyo api revision
  header_params['revision'] =  ENV['KLAVIYO_API_REVISION'] || ENV['API_REVISION'] || "2025-07-15"
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/vnd.api+json'])

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:debug_body]

  # return_type
  return_type = opts[:debug_return_type] || 'Hash<String, Object>'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['Klaviyo-API-Key', 'OAuth']

  new_options = opts.merge(
    :operation => :"MetricsApi.get_custom_metric_id_for_mapped_metric",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: MetricsApi#get_custom_metric_id_for_mapped_metric\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#get_custom_metric_with_http_info(id, opts = {}) ⇒ Array<(Hash<String, Object>, Integer, Hash)>

Get Custom Metric Get a custom metric with the given custom metric ID.&lt;br&gt;&lt;br&gt;*Rate limits*:&lt;br&gt;Burst: &#x60;3/s&#x60;&lt;br&gt;Steady: &#x60;60/m&#x60; Scopes: &#x60;metrics:read&#x60;

Parameters:

  • id (String)

    The ID of the custom metric

  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

Returns:

  • (Array<(Hash<String, Object>, Integer, Hash)>)

    Hash<String, Object> data, response status code and response headers



177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# File 'lib/klaviyo-api-sdk/api/metrics_api.rb', line 177

def get_custom_metric_with_http_info(id, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: MetricsApi.get_custom_metric ...'
  end
  # verify the required parameter 'id' is set
  if @api_client.config.client_side_validation && id.nil?
    fail ArgumentError, "Missing the required parameter 'id' when calling MetricsApi.get_custom_metric"
  end
  allowable_values = ["name", "created", "updated", "definition", "definition.aggregation_method", "definition.metric_groups"]
  if @api_client.config.client_side_validation && opts[:'fields_custom_metric'] && !opts[:'fields_custom_metric'].all? { |item| allowable_values.include?(item) }
    fail ArgumentError, "invalid value for \"fields_custom_metric\", must include one of #{allowable_values}"
  end
  allowable_values = ["name", "created", "updated", "integration"]
  if @api_client.config.client_side_validation && opts[:'fields_metric'] && !opts[:'fields_metric'].all? { |item| allowable_values.include?(item) }
    fail ArgumentError, "invalid value for \"fields_metric\", must include one of #{allowable_values}"
  end
  allowable_values = ["metrics"]
  if @api_client.config.client_side_validation && opts[:'include'] && !opts[:'include'].all? { |item| allowable_values.include?(item) }
    fail ArgumentError, "invalid value for \"include\", must include one of #{allowable_values}"
  end
  # resource path
  local_var_path = '/api/custom-metrics/{id}'.sub('{' + 'id' + '}', CGI.escape(id.to_s))

  # query parameters
  query_params = opts[:query_params] || {}
  query_params[:'fields[custom-metric]'] = @api_client.build_collection_param(opts[:'fields_custom_metric'], :csv) if !opts[:'fields_custom_metric'].nil?
  query_params[:'fields[metric]'] = @api_client.build_collection_param(opts[:'fields_metric'], :csv) if !opts[:'fields_metric'].nil?
  query_params[:'include'] = @api_client.build_collection_param(opts[:'include'], :csv) if !opts[:'include'].nil?

  # header parameters
  header_params = opts[:header_params] || {}
  # klaviyo api revision
  header_params['revision'] =  ENV['KLAVIYO_API_REVISION'] || ENV['API_REVISION'] || "2025-07-15"
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/vnd.api+json'])

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:debug_body]

  # return_type
  return_type = opts[:debug_return_type] || 'Hash<String, Object>'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['Klaviyo-API-Key', 'OAuth']

  new_options = opts.merge(
    :operation => :"MetricsApi.get_custom_metric",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: MetricsApi#get_custom_metric\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#get_custom_metrics(opts = {}) ⇒ Hash<String, Object>

Get Custom Metrics Get all custom metrics in an account.
*Rate limits*:
Burst: ‘3/s`
Steady: `60/m` Scopes: `metrics:read`

Parameters:

  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

Returns:

  • (Hash<String, Object>)


408
409
410
411
# File 'lib/klaviyo-api-sdk/api/metrics_api.rb', line 408

def get_custom_metrics(opts = {})
  data, _status_code, _headers = get_custom_metrics_with_http_info(opts)
  data
end

#get_custom_metrics_with_http_info(opts = {}) ⇒ Array<(Hash<String, Object>, Integer, Hash)>

Get Custom Metrics Get all custom metrics in an account.&lt;br&gt;&lt;br&gt;*Rate limits*:&lt;br&gt;Burst: &#x60;3/s&#x60;&lt;br&gt;Steady: &#x60;60/m&#x60; Scopes: &#x60;metrics:read&#x60;

Parameters:

  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

Returns:

  • (Array<(Hash<String, Object>, Integer, Hash)>)

    Hash<String, Object> data, response status code and response headers



420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
# File 'lib/klaviyo-api-sdk/api/metrics_api.rb', line 420

def get_custom_metrics_with_http_info(opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: MetricsApi.get_custom_metrics ...'
  end
  allowable_values = ["name", "created", "updated", "definition", "definition.aggregation_method", "definition.metric_groups"]
  if @api_client.config.client_side_validation && opts[:'fields_custom_metric'] && !opts[:'fields_custom_metric'].all? { |item| allowable_values.include?(item) }
    fail ArgumentError, "invalid value for \"fields_custom_metric\", must include one of #{allowable_values}"
  end
  allowable_values = ["name", "created", "updated", "integration"]
  if @api_client.config.client_side_validation && opts[:'fields_metric'] && !opts[:'fields_metric'].all? { |item| allowable_values.include?(item) }
    fail ArgumentError, "invalid value for \"fields_metric\", must include one of #{allowable_values}"
  end
  allowable_values = ["metrics"]
  if @api_client.config.client_side_validation && opts[:'include'] && !opts[:'include'].all? { |item| allowable_values.include?(item) }
    fail ArgumentError, "invalid value for \"include\", must include one of #{allowable_values}"
  end
  # resource path
  local_var_path = '/api/custom-metrics'

  # query parameters
  query_params = opts[:query_params] || {}
  query_params[:'fields[custom-metric]'] = @api_client.build_collection_param(opts[:'fields_custom_metric'], :csv) if !opts[:'fields_custom_metric'].nil?
  query_params[:'fields[metric]'] = @api_client.build_collection_param(opts[:'fields_metric'], :csv) if !opts[:'fields_metric'].nil?
  query_params[:'include'] = @api_client.build_collection_param(opts[:'include'], :csv) if !opts[:'include'].nil?

  # header parameters
  header_params = opts[:header_params] || {}
  # klaviyo api revision
  header_params['revision'] =  ENV['KLAVIYO_API_REVISION'] || ENV['API_REVISION'] || "2025-07-15"
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/vnd.api+json'])

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:debug_body]

  # return_type
  return_type = opts[:debug_return_type] || 'Hash<String, Object>'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['Klaviyo-API-Key', 'OAuth']

  new_options = opts.merge(
    :operation => :"MetricsApi.get_custom_metrics",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: MetricsApi#get_custom_metrics\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#get_flows_triggered_by_metric(id, opts = {}) ⇒ Hash<String, Object> Also known as: get_flow_triggers_for_metric, get_metric_flow_triggers

Get Flows Triggered by Metric Get all flows where the given metric is being used as the trigger.
*Rate limits*:
Burst: ‘10/s`
Steady: `150/m` Scopes: `flows:read` `metrics:read`

Parameters:

  • id (String)
  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

Returns:

  • (Hash<String, Object>)


487
488
489
490
# File 'lib/klaviyo-api-sdk/api/metrics_api.rb', line 487

def get_flows_triggered_by_metric(id, opts = {})
  data, _status_code, _headers = get_flows_triggered_by_metric_with_http_info(id, opts)
  data
end

#get_flows_triggered_by_metric_with_http_info(id, opts = {}) ⇒ Array<(Hash<String, Object>, Integer, Hash)> Also known as: get_flow_triggers_for_metric_with_http_info, get_metric_flow_triggers_with_http_info

Get Flows Triggered by Metric Get all flows where the given metric is being used as the trigger.&lt;br&gt;&lt;br&gt;*Rate limits*:&lt;br&gt;Burst: &#x60;10/s&#x60;&lt;br&gt;Steady: &#x60;150/m&#x60; Scopes: &#x60;flows:read&#x60; &#x60;metrics:read&#x60;

Parameters:

  • id (String)
  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

Returns:

  • (Array<(Hash<String, Object>, Integer, Hash)>)

    Hash<String, Object> data, response status code and response headers



504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
# File 'lib/klaviyo-api-sdk/api/metrics_api.rb', line 504

def get_flows_triggered_by_metric_with_http_info(id, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: MetricsApi.get_flows_triggered_by_metric ...'
  end
  # verify the required parameter 'id' is set
  if @api_client.config.client_side_validation && id.nil?
    fail ArgumentError, "Missing the required parameter 'id' when calling MetricsApi.get_flows_triggered_by_metric"
  end
  allowable_values = ["name", "status", "archived", "created", "updated", "trigger_type"]
  if @api_client.config.client_side_validation && opts[:'fields_flow'] && !opts[:'fields_flow'].all? { |item| allowable_values.include?(item) }
    fail ArgumentError, "invalid value for \"fields_flow\", must include one of #{allowable_values}"
  end
  # resource path
  local_var_path = '/api/metrics/{id}/flow-triggers'.sub('{' + 'id' + '}', CGI.escape(id.to_s))

  # query parameters
  query_params = opts[:query_params] || {}
  query_params[:'fields[flow]'] = @api_client.build_collection_param(opts[:'fields_flow'], :csv) if !opts[:'fields_flow'].nil?

  # header parameters
  header_params = opts[:header_params] || {}
  # klaviyo api revision
  header_params['revision'] =  ENV['KLAVIYO_API_REVISION'] || ENV['API_REVISION'] || "2025-07-15"
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/vnd.api+json'])

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:debug_body]

  # return_type
  return_type = opts[:debug_return_type] || 'Hash<String, Object>'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['Klaviyo-API-Key', 'OAuth']

  new_options = opts.merge(
    :operation => :"MetricsApi.get_flows_triggered_by_metric",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: MetricsApi#get_flows_triggered_by_metric\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#get_ids_for_flows_triggered_by_metric(id, opts = {}) ⇒ Hash<String, Object> Also known as: get_flow_trigger_ids_for_metric, get_metric_relationships_flow_triggers

Get IDs for Flows Triggered by Metric Get the IDs of all flows where the given metric is being used as the trigger.
*Rate limits*:
Burst: ‘10/s`
Steady: `150/m` Scopes: `flows:read` `metrics:read`

Parameters:

  • id (String)
  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:

  • (Hash<String, Object>)


570
571
572
573
# File 'lib/klaviyo-api-sdk/api/metrics_api.rb', line 570

def get_ids_for_flows_triggered_by_metric(id, opts = {})
  data, _status_code, _headers = get_ids_for_flows_triggered_by_metric_with_http_info(id, opts)
  data
end

#get_ids_for_flows_triggered_by_metric_with_http_info(id, opts = {}) ⇒ Array<(Hash<String, Object>, Integer, Hash)> Also known as: get_flow_trigger_ids_for_metric_with_http_info, get_metric_relationships_flow_triggers_with_http_info

Get IDs for Flows Triggered by Metric Get the IDs of all flows where the given metric is being used as the trigger.&lt;br&gt;&lt;br&gt;*Rate limits*:&lt;br&gt;Burst: &#x60;10/s&#x60;&lt;br&gt;Steady: &#x60;150/m&#x60; Scopes: &#x60;flows:read&#x60; &#x60;metrics:read&#x60;

Parameters:

  • id (String)
  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:

  • (Array<(Hash<String, Object>, Integer, Hash)>)

    Hash<String, Object> data, response status code and response headers



586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
# File 'lib/klaviyo-api-sdk/api/metrics_api.rb', line 586

def get_ids_for_flows_triggered_by_metric_with_http_info(id, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: MetricsApi.get_ids_for_flows_triggered_by_metric ...'
  end
  # verify the required parameter 'id' is set
  if @api_client.config.client_side_validation && id.nil?
    fail ArgumentError, "Missing the required parameter 'id' when calling MetricsApi.get_ids_for_flows_triggered_by_metric"
  end
  # resource path
  local_var_path = '/api/metrics/{id}/relationships/flow-triggers'.sub('{' + 'id' + '}', CGI.escape(id.to_s))

  # query parameters
  query_params = opts[:query_params] || {}

  # header parameters
  header_params = opts[:header_params] || {}
  # klaviyo api revision
  header_params['revision'] =  ENV['KLAVIYO_API_REVISION'] || ENV['API_REVISION'] || "2025-07-15"
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/vnd.api+json'])

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:debug_body]

  # return_type
  return_type = opts[:debug_return_type] || 'Hash<String, Object>'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['Klaviyo-API-Key', 'OAuth']

  new_options = opts.merge(
    :operation => :"MetricsApi.get_ids_for_flows_triggered_by_metric",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: MetricsApi#get_ids_for_flows_triggered_by_metric\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#get_mapped_metric(id, opts = {}) ⇒ Hash<String, Object>

Get Mapped Metric Get the mapped metric with the given ID.
*Rate limits*:
Burst: ‘3/s`
Steady: `60/m` Scopes: `metrics:read`

Parameters:

  • id (String)

    The type of mapping.

  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

Returns:

  • (Hash<String, Object>)


651
652
653
654
# File 'lib/klaviyo-api-sdk/api/metrics_api.rb', line 651

def get_mapped_metric(id, opts = {})
  data, _status_code, _headers = get_mapped_metric_with_http_info(id, opts)
  data
end

#get_mapped_metric_with_http_info(id, opts = {}) ⇒ Array<(Hash<String, Object>, Integer, Hash)>

Get Mapped Metric Get the mapped metric with the given ID.&lt;br&gt;&lt;br&gt;*Rate limits*:&lt;br&gt;Burst: &#x60;3/s&#x60;&lt;br&gt;Steady: &#x60;60/m&#x60; Scopes: &#x60;metrics:read&#x60;

Parameters:

  • id (String)

    The type of mapping.

  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

Returns:

  • (Array<(Hash<String, Object>, Integer, Hash)>)

    Hash<String, Object> data, response status code and response headers



665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
# File 'lib/klaviyo-api-sdk/api/metrics_api.rb', line 665

def get_mapped_metric_with_http_info(id, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: MetricsApi.get_mapped_metric ...'
  end
  # verify the required parameter 'id' is set
  if @api_client.config.client_side_validation && id.nil?
    fail ArgumentError, "Missing the required parameter 'id' when calling MetricsApi.get_mapped_metric"
  end
  # verify enum value
  allowable_values = ["added_to_cart", "cancelled_sales", "ordered_product", "refunded_sales", "revenue", "started_checkout", "viewed_product"]
  if @api_client.config.client_side_validation && !allowable_values.include?(id)
    fail ArgumentError, "invalid value for \"id\", must be one of #{allowable_values}"
  end
  allowable_values = ["name", "created", "updated", "definition", "definition.aggregation_method", "definition.metric_groups"]
  if @api_client.config.client_side_validation && opts[:'fields_custom_metric'] && !opts[:'fields_custom_metric'].all? { |item| allowable_values.include?(item) }
    fail ArgumentError, "invalid value for \"fields_custom_metric\", must include one of #{allowable_values}"
  end
  allowable_values = ["updated"]
  if @api_client.config.client_side_validation && opts[:'fields_mapped_metric'] && !opts[:'fields_mapped_metric'].all? { |item| allowable_values.include?(item) }
    fail ArgumentError, "invalid value for \"fields_mapped_metric\", must include one of #{allowable_values}"
  end
  allowable_values = ["name", "created", "updated", "integration"]
  if @api_client.config.client_side_validation && opts[:'fields_metric'] && !opts[:'fields_metric'].all? { |item| allowable_values.include?(item) }
    fail ArgumentError, "invalid value for \"fields_metric\", must include one of #{allowable_values}"
  end
  allowable_values = ["custom-metric", "metric"]
  if @api_client.config.client_side_validation && opts[:'include'] && !opts[:'include'].all? { |item| allowable_values.include?(item) }
    fail ArgumentError, "invalid value for \"include\", must include one of #{allowable_values}"
  end
  # resource path
  local_var_path = '/api/mapped-metrics/{id}'.sub('{' + 'id' + '}', CGI.escape(id.to_s))

  # query parameters
  query_params = opts[:query_params] || {}
  query_params[:'fields[custom-metric]'] = @api_client.build_collection_param(opts[:'fields_custom_metric'], :csv) if !opts[:'fields_custom_metric'].nil?
  query_params[:'fields[mapped-metric]'] = @api_client.build_collection_param(opts[:'fields_mapped_metric'], :csv) if !opts[:'fields_mapped_metric'].nil?
  query_params[:'fields[metric]'] = @api_client.build_collection_param(opts[:'fields_metric'], :csv) if !opts[:'fields_metric'].nil?
  query_params[:'include'] = @api_client.build_collection_param(opts[:'include'], :csv) if !opts[:'include'].nil?

  # header parameters
  header_params = opts[:header_params] || {}
  # klaviyo api revision
  header_params['revision'] =  ENV['KLAVIYO_API_REVISION'] || ENV['API_REVISION'] || "2025-07-15"
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/vnd.api+json'])

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:debug_body]

  # return_type
  return_type = opts[:debug_return_type] || 'Hash<String, Object>'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['Klaviyo-API-Key', 'OAuth']

  new_options = opts.merge(
    :operation => :"MetricsApi.get_mapped_metric",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: MetricsApi#get_mapped_metric\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#get_mapped_metrics(opts = {}) ⇒ Hash<String, Object>

Get Mapped Metrics Get all mapped metrics in an account.
*Rate limits*:
Burst: ‘3/s`
Steady: `60/m` Scopes: `metrics:read`

Parameters:

  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

Returns:

  • (Hash<String, Object>)


748
749
750
751
# File 'lib/klaviyo-api-sdk/api/metrics_api.rb', line 748

def get_mapped_metrics(opts = {})
  data, _status_code, _headers = get_mapped_metrics_with_http_info(opts)
  data
end

#get_mapped_metrics_with_http_info(opts = {}) ⇒ Array<(Hash<String, Object>, Integer, Hash)>

Get Mapped Metrics Get all mapped metrics in an account.&lt;br&gt;&lt;br&gt;*Rate limits*:&lt;br&gt;Burst: &#x60;3/s&#x60;&lt;br&gt;Steady: &#x60;60/m&#x60; Scopes: &#x60;metrics:read&#x60;

Parameters:

  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

Returns:

  • (Array<(Hash<String, Object>, Integer, Hash)>)

    Hash<String, Object> data, response status code and response headers



761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
# File 'lib/klaviyo-api-sdk/api/metrics_api.rb', line 761

def get_mapped_metrics_with_http_info(opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: MetricsApi.get_mapped_metrics ...'
  end
  allowable_values = ["name", "created", "updated", "definition", "definition.aggregation_method", "definition.metric_groups"]
  if @api_client.config.client_side_validation && opts[:'fields_custom_metric'] && !opts[:'fields_custom_metric'].all? { |item| allowable_values.include?(item) }
    fail ArgumentError, "invalid value for \"fields_custom_metric\", must include one of #{allowable_values}"
  end
  allowable_values = ["updated"]
  if @api_client.config.client_side_validation && opts[:'fields_mapped_metric'] && !opts[:'fields_mapped_metric'].all? { |item| allowable_values.include?(item) }
    fail ArgumentError, "invalid value for \"fields_mapped_metric\", must include one of #{allowable_values}"
  end
  allowable_values = ["name", "created", "updated", "integration"]
  if @api_client.config.client_side_validation && opts[:'fields_metric'] && !opts[:'fields_metric'].all? { |item| allowable_values.include?(item) }
    fail ArgumentError, "invalid value for \"fields_metric\", must include one of #{allowable_values}"
  end
  allowable_values = ["custom-metric", "metric"]
  if @api_client.config.client_side_validation && opts[:'include'] && !opts[:'include'].all? { |item| allowable_values.include?(item) }
    fail ArgumentError, "invalid value for \"include\", must include one of #{allowable_values}"
  end
  # resource path
  local_var_path = '/api/mapped-metrics'

  # query parameters
  query_params = opts[:query_params] || {}
  query_params[:'fields[custom-metric]'] = @api_client.build_collection_param(opts[:'fields_custom_metric'], :csv) if !opts[:'fields_custom_metric'].nil?
  query_params[:'fields[mapped-metric]'] = @api_client.build_collection_param(opts[:'fields_mapped_metric'], :csv) if !opts[:'fields_mapped_metric'].nil?
  query_params[:'fields[metric]'] = @api_client.build_collection_param(opts[:'fields_metric'], :csv) if !opts[:'fields_metric'].nil?
  query_params[:'include'] = @api_client.build_collection_param(opts[:'include'], :csv) if !opts[:'include'].nil?

  # header parameters
  header_params = opts[:header_params] || {}
  # klaviyo api revision
  header_params['revision'] =  ENV['KLAVIYO_API_REVISION'] || ENV['API_REVISION'] || "2025-07-15"
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/vnd.api+json'])

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:debug_body]

  # return_type
  return_type = opts[:debug_return_type] || 'Hash<String, Object>'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['Klaviyo-API-Key', 'OAuth']

  new_options = opts.merge(
    :operation => :"MetricsApi.get_mapped_metrics",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: MetricsApi#get_mapped_metrics\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#get_metric(id, opts = {}) ⇒ Hash<String, Object>

Get Metric Get a metric with the given metric ID.
*Rate limits*:
Burst: ‘10/s`
Steady: `150/m` Scopes: `metrics:read`

Parameters:

  • id (String)

    Metric ID

  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

Returns:

  • (Hash<String, Object>)


835
836
837
838
# File 'lib/klaviyo-api-sdk/api/metrics_api.rb', line 835

def get_metric(id, opts = {})
  data, _status_code, _headers = get_metric_with_http_info(id, opts)
  data
end

#get_metric_for_mapped_metric(id, opts = {}) ⇒ Hash<String, Object> Also known as: get_mapped_metric_metric

Get Metric for Mapped Metric Get the metric for the given mapped metric ID (if applicable).
*Rate limits*:
Burst: ‘3/s`
Steady: `60/m` Scopes: `metrics:read`

Parameters:

  • id (String)

    The type of mapping.

  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

Returns:

  • (Hash<String, Object>)


919
920
921
922
# File 'lib/klaviyo-api-sdk/api/metrics_api.rb', line 919

def get_metric_for_mapped_metric(id, opts = {})
  data, _status_code, _headers = get_metric_for_mapped_metric_with_http_info(id, opts)
  data
end

#get_metric_for_mapped_metric_with_http_info(id, opts = {}) ⇒ Array<(Hash<String, Object>, Integer, Hash)> Also known as: get_mapped_metric_metric_with_http_info

Get Metric for Mapped Metric Get the metric for the given mapped metric ID (if applicable).&lt;br&gt;&lt;br&gt;*Rate limits*:&lt;br&gt;Burst: &#x60;3/s&#x60;&lt;br&gt;Steady: &#x60;60/m&#x60; Scopes: &#x60;metrics:read&#x60;

Parameters:

  • id (String)

    The type of mapping.

  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

Returns:

  • (Array<(Hash<String, Object>, Integer, Hash)>)

    Hash<String, Object> data, response status code and response headers



933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
# File 'lib/klaviyo-api-sdk/api/metrics_api.rb', line 933

def get_metric_for_mapped_metric_with_http_info(id, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: MetricsApi.get_metric_for_mapped_metric ...'
  end
  # verify the required parameter 'id' is set
  if @api_client.config.client_side_validation && id.nil?
    fail ArgumentError, "Missing the required parameter 'id' when calling MetricsApi.get_metric_for_mapped_metric"
  end
  # verify enum value
  allowable_values = ["added_to_cart", "cancelled_sales", "ordered_product", "refunded_sales", "revenue", "started_checkout", "viewed_product"]
  if @api_client.config.client_side_validation && !allowable_values.include?(id)
    fail ArgumentError, "invalid value for \"id\", must be one of #{allowable_values}"
  end
  allowable_values = ["name", "created", "updated", "integration"]
  if @api_client.config.client_side_validation && opts[:'fields_metric'] && !opts[:'fields_metric'].all? { |item| allowable_values.include?(item) }
    fail ArgumentError, "invalid value for \"fields_metric\", must include one of #{allowable_values}"
  end
  # resource path
  local_var_path = '/api/mapped-metrics/{id}/metric'.sub('{' + 'id' + '}', CGI.escape(id.to_s))

  # query parameters
  query_params = opts[:query_params] || {}
  query_params[:'fields[metric]'] = @api_client.build_collection_param(opts[:'fields_metric'], :csv) if !opts[:'fields_metric'].nil?

  # header parameters
  header_params = opts[:header_params] || {}
  # klaviyo api revision
  header_params['revision'] =  ENV['KLAVIYO_API_REVISION'] || ENV['API_REVISION'] || "2025-07-15"
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/vnd.api+json'])

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:debug_body]

  # return_type
  return_type = opts[:debug_return_type] || 'Hash<String, Object>'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['Klaviyo-API-Key', 'OAuth']

  new_options = opts.merge(
    :operation => :"MetricsApi.get_metric_for_mapped_metric",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: MetricsApi#get_metric_for_mapped_metric\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#get_metric_for_metric_property(id, opts = {}) ⇒ Hash<String, Object> Also known as: get_metric_property_metric

Get Metric for Metric Property Get the metric for the given metric property ID.
*Rate limits*:
Burst: ‘1/s`
Steady: `15/m` Scopes: `metrics:read`

Parameters:

  • id (String)

    The ID of the metric property

  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

Returns:

  • (Hash<String, Object>)


1002
1003
1004
1005
# File 'lib/klaviyo-api-sdk/api/metrics_api.rb', line 1002

def get_metric_for_metric_property(id, opts = {})
  data, _status_code, _headers = get_metric_for_metric_property_with_http_info(id, opts)
  data
end

#get_metric_for_metric_property_with_http_info(id, opts = {}) ⇒ Array<(Hash<String, Object>, Integer, Hash)> Also known as: get_metric_property_metric_with_http_info

Get Metric for Metric Property Get the metric for the given metric property ID.&lt;br&gt;&lt;br&gt;*Rate limits*:&lt;br&gt;Burst: &#x60;1/s&#x60;&lt;br&gt;Steady: &#x60;15/m&#x60; Scopes: &#x60;metrics:read&#x60;

Parameters:

  • id (String)

    The ID of the metric property

  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

Returns:

  • (Array<(Hash<String, Object>, Integer, Hash)>)

    Hash<String, Object> data, response status code and response headers



1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
# File 'lib/klaviyo-api-sdk/api/metrics_api.rb', line 1016

def get_metric_for_metric_property_with_http_info(id, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: MetricsApi.get_metric_for_metric_property ...'
  end
  # verify the required parameter 'id' is set
  if @api_client.config.client_side_validation && id.nil?
    fail ArgumentError, "Missing the required parameter 'id' when calling MetricsApi.get_metric_for_metric_property"
  end
  allowable_values = ["name", "created", "updated", "integration"]
  if @api_client.config.client_side_validation && opts[:'fields_metric'] && !opts[:'fields_metric'].all? { |item| allowable_values.include?(item) }
    fail ArgumentError, "invalid value for \"fields_metric\", must include one of #{allowable_values}"
  end
  # resource path
  local_var_path = '/api/metric-properties/{id}/metric'.sub('{' + 'id' + '}', CGI.escape(id.to_s))

  # query parameters
  query_params = opts[:query_params] || {}
  query_params[:'fields[metric]'] = @api_client.build_collection_param(opts[:'fields_metric'], :csv) if !opts[:'fields_metric'].nil?

  # header parameters
  header_params = opts[:header_params] || {}
  # klaviyo api revision
  header_params['revision'] =  ENV['KLAVIYO_API_REVISION'] || ENV['API_REVISION'] || "2025-07-15"
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/vnd.api+json'])

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:debug_body]

  # return_type
  return_type = opts[:debug_return_type] || 'Hash<String, Object>'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['Klaviyo-API-Key', 'OAuth']

  new_options = opts.merge(
    :operation => :"MetricsApi.get_metric_for_metric_property",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: MetricsApi#get_metric_for_metric_property\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#get_metric_id_for_mapped_metric(id, opts = {}) ⇒ Hash<String, Object> Also known as: get_mapped_metric_relationships_metric

Get Metric ID for Mapped Metric Get the ID of the metric for the given mapped metric.
*Rate limits*:
Burst: ‘3/s`
Steady: `60/m` Scopes: `metrics:read`

Parameters:

  • id (String)

    The type of mapping.

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:

  • (Hash<String, Object>)


1079
1080
1081
1082
# File 'lib/klaviyo-api-sdk/api/metrics_api.rb', line 1079

def get_metric_id_for_mapped_metric(id, opts = {})
  data, _status_code, _headers = get_metric_id_for_mapped_metric_with_http_info(id, opts)
  data
end

#get_metric_id_for_mapped_metric_with_http_info(id, opts = {}) ⇒ Array<(Hash<String, Object>, Integer, Hash)> Also known as: get_mapped_metric_relationships_metric_with_http_info

Get Metric ID for Mapped Metric Get the ID of the metric for the given mapped metric.&lt;br&gt;&lt;br&gt;*Rate limits*:&lt;br&gt;Burst: &#x60;3/s&#x60;&lt;br&gt;Steady: &#x60;60/m&#x60; Scopes: &#x60;metrics:read&#x60;

Parameters:

  • id (String)

    The type of mapping.

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:

  • (Array<(Hash<String, Object>, Integer, Hash)>)

    Hash<String, Object> data, response status code and response headers



1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
# File 'lib/klaviyo-api-sdk/api/metrics_api.rb', line 1092

def get_metric_id_for_mapped_metric_with_http_info(id, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: MetricsApi.get_metric_id_for_mapped_metric ...'
  end
  # verify the required parameter 'id' is set
  if @api_client.config.client_side_validation && id.nil?
    fail ArgumentError, "Missing the required parameter 'id' when calling MetricsApi.get_metric_id_for_mapped_metric"
  end
  # verify enum value
  allowable_values = ["added_to_cart", "cancelled_sales", "ordered_product", "refunded_sales", "revenue", "started_checkout", "viewed_product"]
  if @api_client.config.client_side_validation && !allowable_values.include?(id)
    fail ArgumentError, "invalid value for \"id\", must be one of #{allowable_values}"
  end
  # resource path
  local_var_path = '/api/mapped-metrics/{id}/relationships/metric'.sub('{' + 'id' + '}', CGI.escape(id.to_s))

  # query parameters
  query_params = opts[:query_params] || {}

  # header parameters
  header_params = opts[:header_params] || {}
  # klaviyo api revision
  header_params['revision'] =  ENV['KLAVIYO_API_REVISION'] || ENV['API_REVISION'] || "2025-07-15"
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/vnd.api+json'])

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:debug_body]

  # return_type
  return_type = opts[:debug_return_type] || 'Hash<String, Object>'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['Klaviyo-API-Key', 'OAuth']

  new_options = opts.merge(
    :operation => :"MetricsApi.get_metric_id_for_mapped_metric",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: MetricsApi#get_metric_id_for_mapped_metric\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#get_metric_id_for_metric_property(id, opts = {}) ⇒ Hash<String, Object> Also known as: get_metric_property_relationships_metric

Get Metric ID for Metric Property Get the ID of the metric for the given metric property.
*Rate limits*:
Burst: ‘1/s`
Steady: `15/m` Scopes: `metrics:read`

Parameters:

  • id (String)

    The ID of the metric property

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:

  • (Hash<String, Object>)


1155
1156
1157
1158
# File 'lib/klaviyo-api-sdk/api/metrics_api.rb', line 1155

def get_metric_id_for_metric_property(id, opts = {})
  data, _status_code, _headers = get_metric_id_for_metric_property_with_http_info(id, opts)
  data
end

#get_metric_id_for_metric_property_with_http_info(id, opts = {}) ⇒ Array<(Hash<String, Object>, Integer, Hash)> Also known as: get_metric_property_relationships_metric_with_http_info

Get Metric ID for Metric Property Get the ID of the metric for the given metric property.&lt;br&gt;&lt;br&gt;*Rate limits*:&lt;br&gt;Burst: &#x60;1/s&#x60;&lt;br&gt;Steady: &#x60;15/m&#x60; Scopes: &#x60;metrics:read&#x60;

Parameters:

  • id (String)

    The ID of the metric property

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:

  • (Array<(Hash<String, Object>, Integer, Hash)>)

    Hash<String, Object> data, response status code and response headers



1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
# File 'lib/klaviyo-api-sdk/api/metrics_api.rb', line 1168

def get_metric_id_for_metric_property_with_http_info(id, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: MetricsApi.get_metric_id_for_metric_property ...'
  end
  # verify the required parameter 'id' is set
  if @api_client.config.client_side_validation && id.nil?
    fail ArgumentError, "Missing the required parameter 'id' when calling MetricsApi.get_metric_id_for_metric_property"
  end
  # resource path
  local_var_path = '/api/metric-properties/{id}/relationships/metric'.sub('{' + 'id' + '}', CGI.escape(id.to_s))

  # query parameters
  query_params = opts[:query_params] || {}

  # header parameters
  header_params = opts[:header_params] || {}
  # klaviyo api revision
  header_params['revision'] =  ENV['KLAVIYO_API_REVISION'] || ENV['API_REVISION'] || "2025-07-15"
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/vnd.api+json'])

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:debug_body]

  # return_type
  return_type = opts[:debug_return_type] || 'Hash<String, Object>'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['Klaviyo-API-Key', 'OAuth']

  new_options = opts.merge(
    :operation => :"MetricsApi.get_metric_id_for_metric_property",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: MetricsApi#get_metric_id_for_metric_property\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#get_metric_ids_for_custom_metric(id, opts = {}) ⇒ Hash<String, Object> Also known as: get_custom_metric_relationships_metrics

Get Metric IDs for Custom Metric Get all metrics for the given custom metric ID.
*Rate limits*:
Burst: ‘3/s`
Steady: `60/m` Scopes: `metrics:read`

Parameters:

  • id (String)

    The ID of the custom metric

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:

  • (Hash<String, Object>)


1226
1227
1228
1229
# File 'lib/klaviyo-api-sdk/api/metrics_api.rb', line 1226

def get_metric_ids_for_custom_metric(id, opts = {})
  data, _status_code, _headers = get_metric_ids_for_custom_metric_with_http_info(id, opts)
  data
end

#get_metric_ids_for_custom_metric_with_http_info(id, opts = {}) ⇒ Array<(Hash<String, Object>, Integer, Hash)> Also known as: get_custom_metric_relationships_metrics_with_http_info

Get Metric IDs for Custom Metric Get all metrics for the given custom metric ID.&lt;br&gt;&lt;br&gt;*Rate limits*:&lt;br&gt;Burst: &#x60;3/s&#x60;&lt;br&gt;Steady: &#x60;60/m&#x60; Scopes: &#x60;metrics:read&#x60;

Parameters:

  • id (String)

    The ID of the custom metric

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:

  • (Array<(Hash<String, Object>, Integer, Hash)>)

    Hash<String, Object> data, response status code and response headers



1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
# File 'lib/klaviyo-api-sdk/api/metrics_api.rb', line 1239

def get_metric_ids_for_custom_metric_with_http_info(id, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: MetricsApi.get_metric_ids_for_custom_metric ...'
  end
  # verify the required parameter 'id' is set
  if @api_client.config.client_side_validation && id.nil?
    fail ArgumentError, "Missing the required parameter 'id' when calling MetricsApi.get_metric_ids_for_custom_metric"
  end
  # resource path
  local_var_path = '/api/custom-metrics/{id}/relationships/metrics'.sub('{' + 'id' + '}', CGI.escape(id.to_s))

  # query parameters
  query_params = opts[:query_params] || {}

  # header parameters
  header_params = opts[:header_params] || {}
  # klaviyo api revision
  header_params['revision'] =  ENV['KLAVIYO_API_REVISION'] || ENV['API_REVISION'] || "2025-07-15"
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/vnd.api+json'])

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:debug_body]

  # return_type
  return_type = opts[:debug_return_type] || 'Hash<String, Object>'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['Klaviyo-API-Key', 'OAuth']

  new_options = opts.merge(
    :operation => :"MetricsApi.get_metric_ids_for_custom_metric",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: MetricsApi#get_metric_ids_for_custom_metric\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#get_metric_property(id, opts = {}) ⇒ Hash<String, Object>

Get Metric Property Get a metric property with the given metric property ID.
*Rate limits*:
Burst: ‘1/s`
Steady: `15/m` Scopes: `metrics:read`

Parameters:

  • id (String)

    The ID of the metric property

  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

Returns:

  • (Hash<String, Object>)


1301
1302
1303
1304
# File 'lib/klaviyo-api-sdk/api/metrics_api.rb', line 1301

def get_metric_property(id, opts = {})
  data, _status_code, _headers = get_metric_property_with_http_info(id, opts)
  data
end

#get_metric_property_with_http_info(id, opts = {}) ⇒ Array<(Hash<String, Object>, Integer, Hash)>

Get Metric Property Get a metric property with the given metric property ID.&lt;br&gt;&lt;br&gt;*Rate limits*:&lt;br&gt;Burst: &#x60;1/s&#x60;&lt;br&gt;Steady: &#x60;15/m&#x60; Scopes: &#x60;metrics:read&#x60;

Parameters:

  • id (String)

    The ID of the metric property

  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

Returns:

  • (Array<(Hash<String, Object>, Integer, Hash)>)

    Hash<String, Object> data, response status code and response headers



1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
# File 'lib/klaviyo-api-sdk/api/metrics_api.rb', line 1315

def get_metric_property_with_http_info(id, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: MetricsApi.get_metric_property ...'
  end
  # verify the required parameter 'id' is set
  if @api_client.config.client_side_validation && id.nil?
    fail ArgumentError, "Missing the required parameter 'id' when calling MetricsApi.get_metric_property"
  end
  allowable_values = ["sample_values"]
  if @api_client.config.client_side_validation && opts[:'additional_fields_metric_property'] && !opts[:'additional_fields_metric_property'].all? { |item| allowable_values.include?(item) }
    fail ArgumentError, "invalid value for \"additional_fields_metric_property\", must include one of #{allowable_values}"
  end
  allowable_values = ["label", "property", "inferred_type", "sample_values"]
  if @api_client.config.client_side_validation && opts[:'fields_metric_property'] && !opts[:'fields_metric_property'].all? { |item| allowable_values.include?(item) }
    fail ArgumentError, "invalid value for \"fields_metric_property\", must include one of #{allowable_values}"
  end
  allowable_values = ["name", "created", "updated", "integration"]
  if @api_client.config.client_side_validation && opts[:'fields_metric'] && !opts[:'fields_metric'].all? { |item| allowable_values.include?(item) }
    fail ArgumentError, "invalid value for \"fields_metric\", must include one of #{allowable_values}"
  end
  allowable_values = ["metric"]
  if @api_client.config.client_side_validation && opts[:'include'] && !opts[:'include'].all? { |item| allowable_values.include?(item) }
    fail ArgumentError, "invalid value for \"include\", must include one of #{allowable_values}"
  end
  # resource path
  local_var_path = '/api/metric-properties/{id}'.sub('{' + 'id' + '}', CGI.escape(id.to_s))

  # query parameters
  query_params = opts[:query_params] || {}
  query_params[:'additional-fields[metric-property]'] = @api_client.build_collection_param(opts[:'additional_fields_metric_property'], :csv) if !opts[:'additional_fields_metric_property'].nil?
  query_params[:'fields[metric-property]'] = @api_client.build_collection_param(opts[:'fields_metric_property'], :csv) if !opts[:'fields_metric_property'].nil?
  query_params[:'fields[metric]'] = @api_client.build_collection_param(opts[:'fields_metric'], :csv) if !opts[:'fields_metric'].nil?
  query_params[:'include'] = @api_client.build_collection_param(opts[:'include'], :csv) if !opts[:'include'].nil?

  # header parameters
  header_params = opts[:header_params] || {}
  # klaviyo api revision
  header_params['revision'] =  ENV['KLAVIYO_API_REVISION'] || ENV['API_REVISION'] || "2025-07-15"
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/vnd.api+json'])

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:debug_body]

  # return_type
  return_type = opts[:debug_return_type] || 'Hash<String, Object>'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['Klaviyo-API-Key', 'OAuth']

  new_options = opts.merge(
    :operation => :"MetricsApi.get_metric_property",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: MetricsApi#get_metric_property\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#get_metric_with_http_info(id, opts = {}) ⇒ Array<(Hash<String, Object>, Integer, Hash)>

Get Metric Get a metric with the given metric ID.&lt;br&gt;&lt;br&gt;*Rate limits*:&lt;br&gt;Burst: &#x60;10/s&#x60;&lt;br&gt;Steady: &#x60;150/m&#x60; Scopes: &#x60;metrics:read&#x60;

Parameters:

  • id (String)

    Metric ID

  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

Returns:

  • (Array<(Hash<String, Object>, Integer, Hash)>)

    Hash<String, Object> data, response status code and response headers



848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
# File 'lib/klaviyo-api-sdk/api/metrics_api.rb', line 848

def get_metric_with_http_info(id, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: MetricsApi.get_metric ...'
  end
  # verify the required parameter 'id' is set
  if @api_client.config.client_side_validation && id.nil?
    fail ArgumentError, "Missing the required parameter 'id' when calling MetricsApi.get_metric"
  end
  allowable_values = ["name", "status", "archived", "created", "updated", "trigger_type"]
  if @api_client.config.client_side_validation && opts[:'fields_flow'] && !opts[:'fields_flow'].all? { |item| allowable_values.include?(item) }
    fail ArgumentError, "invalid value for \"fields_flow\", must include one of #{allowable_values}"
  end
  allowable_values = ["name", "created", "updated", "integration"]
  if @api_client.config.client_side_validation && opts[:'fields_metric'] && !opts[:'fields_metric'].all? { |item| allowable_values.include?(item) }
    fail ArgumentError, "invalid value for \"fields_metric\", must include one of #{allowable_values}"
  end
  allowable_values = ["flow-triggers"]
  if @api_client.config.client_side_validation && opts[:'include'] && !opts[:'include'].all? { |item| allowable_values.include?(item) }
    fail ArgumentError, "invalid value for \"include\", must include one of #{allowable_values}"
  end
  # resource path
  local_var_path = '/api/metrics/{id}'.sub('{' + 'id' + '}', CGI.escape(id.to_s))

  # query parameters
  query_params = opts[:query_params] || {}
  query_params[:'fields[flow]'] = @api_client.build_collection_param(opts[:'fields_flow'], :csv) if !opts[:'fields_flow'].nil?
  query_params[:'fields[metric]'] = @api_client.build_collection_param(opts[:'fields_metric'], :csv) if !opts[:'fields_metric'].nil?
  query_params[:'include'] = @api_client.build_collection_param(opts[:'include'], :csv) if !opts[:'include'].nil?

  # header parameters
  header_params = opts[:header_params] || {}
  # klaviyo api revision
  header_params['revision'] =  ENV['KLAVIYO_API_REVISION'] || ENV['API_REVISION'] || "2025-07-15"
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/vnd.api+json'])

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:debug_body]

  # return_type
  return_type = opts[:debug_return_type] || 'Hash<String, Object>'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['Klaviyo-API-Key', 'OAuth']

  new_options = opts.merge(
    :operation => :"MetricsApi.get_metric",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: MetricsApi#get_metric\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#get_metrics(opts = {}) ⇒ Hash<String, Object>

Get Metrics Get all metrics in an account. Requests can be filtered by the following fields: integration ‘name`, integration `category` Returns a maximum of 200 results per page.
*Rate limits*:
Burst: `10/s`
Steady: `150/m` Scopes: `metrics:read`

Parameters:

  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

Returns:

  • (Hash<String, Object>)


1394
1395
1396
1397
# File 'lib/klaviyo-api-sdk/api/metrics_api.rb', line 1394

def get_metrics(opts = {})
  data, _status_code, _headers = get_metrics_with_http_info(opts)
  data
end

#get_metrics_for_custom_metric(id, opts = {}) ⇒ Hash<String, Object> Also known as: get_custom_metric_metrics

Get Metrics for Custom Metric Get all metrics for the given custom metric ID.
*Rate limits*:
Burst: ‘3/s`
Steady: `60/m` Scopes: `metrics:read`

Parameters:

  • id (String)

    The ID of the custom metric

  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

Returns:

  • (Hash<String, Object>)


1477
1478
1479
1480
# File 'lib/klaviyo-api-sdk/api/metrics_api.rb', line 1477

def get_metrics_for_custom_metric(id, opts = {})
  data, _status_code, _headers = get_metrics_for_custom_metric_with_http_info(id, opts)
  data
end

#get_metrics_for_custom_metric_with_http_info(id, opts = {}) ⇒ Array<(Hash<String, Object>, Integer, Hash)> Also known as: get_custom_metric_metrics_with_http_info

Get Metrics for Custom Metric Get all metrics for the given custom metric ID.&lt;br&gt;&lt;br&gt;*Rate limits*:&lt;br&gt;Burst: &#x60;3/s&#x60;&lt;br&gt;Steady: &#x60;60/m&#x60; Scopes: &#x60;metrics:read&#x60;

Parameters:

  • id (String)

    The ID of the custom metric

  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

Returns:

  • (Array<(Hash<String, Object>, Integer, Hash)>)

    Hash<String, Object> data, response status code and response headers



1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
# File 'lib/klaviyo-api-sdk/api/metrics_api.rb', line 1491

def get_metrics_for_custom_metric_with_http_info(id, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: MetricsApi.get_metrics_for_custom_metric ...'
  end
  # verify the required parameter 'id' is set
  if @api_client.config.client_side_validation && id.nil?
    fail ArgumentError, "Missing the required parameter 'id' when calling MetricsApi.get_metrics_for_custom_metric"
  end
  allowable_values = ["name", "created", "updated", "integration"]
  if @api_client.config.client_side_validation && opts[:'fields_metric'] && !opts[:'fields_metric'].all? { |item| allowable_values.include?(item) }
    fail ArgumentError, "invalid value for \"fields_metric\", must include one of #{allowable_values}"
  end
  # resource path
  local_var_path = '/api/custom-metrics/{id}/metrics'.sub('{' + 'id' + '}', CGI.escape(id.to_s))

  # query parameters
  query_params = opts[:query_params] || {}
  query_params[:'fields[metric]'] = @api_client.build_collection_param(opts[:'fields_metric'], :csv) if !opts[:'fields_metric'].nil?

  # header parameters
  header_params = opts[:header_params] || {}
  # klaviyo api revision
  header_params['revision'] =  ENV['KLAVIYO_API_REVISION'] || ENV['API_REVISION'] || "2025-07-15"
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/vnd.api+json'])

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:debug_body]

  # return_type
  return_type = opts[:debug_return_type] || 'Hash<String, Object>'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['Klaviyo-API-Key', 'OAuth']

  new_options = opts.merge(
    :operation => :"MetricsApi.get_metrics_for_custom_metric",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: MetricsApi#get_metrics_for_custom_metric\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#get_metrics_with_http_info(opts = {}) ⇒ Array<(Hash<String, Object>, Integer, Hash)>

Get Metrics Get all metrics in an account. Requests can be filtered by the following fields: integration &#x60;name&#x60;, integration &#x60;category&#x60; Returns a maximum of 200 results per page.&lt;br&gt;&lt;br&gt;*Rate limits*:&lt;br&gt;Burst: &#x60;10/s&#x60;&lt;br&gt;Steady: &#x60;150/m&#x60; Scopes: &#x60;metrics:read&#x60;

Parameters:

  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

Returns:

  • (Array<(Hash<String, Object>, Integer, Hash)>)

    Hash<String, Object> data, response status code and response headers



1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
# File 'lib/klaviyo-api-sdk/api/metrics_api.rb', line 1408

def get_metrics_with_http_info(opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: MetricsApi.get_metrics ...'
  end
  allowable_values = ["name", "status", "archived", "created", "updated", "trigger_type"]
  if @api_client.config.client_side_validation && opts[:'fields_flow'] && !opts[:'fields_flow'].all? { |item| allowable_values.include?(item) }
    fail ArgumentError, "invalid value for \"fields_flow\", must include one of #{allowable_values}"
  end
  allowable_values = ["name", "created", "updated", "integration"]
  if @api_client.config.client_side_validation && opts[:'fields_metric'] && !opts[:'fields_metric'].all? { |item| allowable_values.include?(item) }
    fail ArgumentError, "invalid value for \"fields_metric\", must include one of #{allowable_values}"
  end
  allowable_values = ["flow-triggers"]
  if @api_client.config.client_side_validation && opts[:'include'] && !opts[:'include'].all? { |item| allowable_values.include?(item) }
    fail ArgumentError, "invalid value for \"include\", must include one of #{allowable_values}"
  end
  # resource path
  local_var_path = '/api/metrics'

  # query parameters
  query_params = opts[:query_params] || {}
  query_params[:'fields[flow]'] = @api_client.build_collection_param(opts[:'fields_flow'], :csv) if !opts[:'fields_flow'].nil?
  query_params[:'fields[metric]'] = @api_client.build_collection_param(opts[:'fields_metric'], :csv) if !opts[:'fields_metric'].nil?
  query_params[:'filter'] = opts[:'filter'] if !opts[:'filter'].nil?
  query_params[:'include'] = @api_client.build_collection_param(opts[:'include'], :csv) if !opts[:'include'].nil?
  query_params[:'page[cursor]'] = opts[:'page_cursor'] if !opts[:'page_cursor'].nil?

  # header parameters
  header_params = opts[:header_params] || {}
  # klaviyo api revision
  header_params['revision'] =  ENV['KLAVIYO_API_REVISION'] || ENV['API_REVISION'] || "2025-07-15"
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/vnd.api+json'])

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:debug_body]

  # return_type
  return_type = opts[:debug_return_type] || 'Hash<String, Object>'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['Klaviyo-API-Key', 'OAuth']

  new_options = opts.merge(
    :operation => :"MetricsApi.get_metrics",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: MetricsApi#get_metrics\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#get_properties_for_metric(id, opts = {}) ⇒ Hash<String, Object> Also known as: get_metric_metric_properties, get_metric_properties

Get Properties for Metric Get the metric properties for the given metric ID.
*Rate limits*:
Burst: ‘1/s`
Steady: `15/m` Scopes: `metrics:read`

Parameters:

  • id (String)

    The ID of the metric

  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

Returns:

  • (Hash<String, Object>)


1556
1557
1558
1559
# File 'lib/klaviyo-api-sdk/api/metrics_api.rb', line 1556

def get_properties_for_metric(id, opts = {})
  data, _status_code, _headers = get_properties_for_metric_with_http_info(id, opts)
  data
end

#get_properties_for_metric_with_http_info(id, opts = {}) ⇒ Array<(Hash<String, Object>, Integer, Hash)> Also known as: get_metric_metric_properties_with_http_info, get_metric_properties_with_http_info

Get Properties for Metric Get the metric properties for the given metric ID.&lt;br&gt;&lt;br&gt;*Rate limits*:&lt;br&gt;Burst: &#x60;1/s&#x60;&lt;br&gt;Steady: &#x60;15/m&#x60; Scopes: &#x60;metrics:read&#x60;

Parameters:

  • id (String)

    The ID of the metric

  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

Returns:

  • (Array<(Hash<String, Object>, Integer, Hash)>)

    Hash<String, Object> data, response status code and response headers



1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
# File 'lib/klaviyo-api-sdk/api/metrics_api.rb', line 1574

def get_properties_for_metric_with_http_info(id, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: MetricsApi.get_properties_for_metric ...'
  end
  # verify the required parameter 'id' is set
  if @api_client.config.client_side_validation && id.nil?
    fail ArgumentError, "Missing the required parameter 'id' when calling MetricsApi.get_properties_for_metric"
  end
  allowable_values = ["sample_values"]
  if @api_client.config.client_side_validation && opts[:'additional_fields_metric_property'] && !opts[:'additional_fields_metric_property'].all? { |item| allowable_values.include?(item) }
    fail ArgumentError, "invalid value for \"additional_fields_metric_property\", must include one of #{allowable_values}"
  end
  allowable_values = ["label", "property", "inferred_type", "sample_values"]
  if @api_client.config.client_side_validation && opts[:'fields_metric_property'] && !opts[:'fields_metric_property'].all? { |item| allowable_values.include?(item) }
    fail ArgumentError, "invalid value for \"fields_metric_property\", must include one of #{allowable_values}"
  end
  # resource path
  local_var_path = '/api/metrics/{id}/metric-properties'.sub('{' + 'id' + '}', CGI.escape(id.to_s))

  # query parameters
  query_params = opts[:query_params] || {}
  query_params[:'additional-fields[metric-property]'] = @api_client.build_collection_param(opts[:'additional_fields_metric_property'], :csv) if !opts[:'additional_fields_metric_property'].nil?
  query_params[:'fields[metric-property]'] = @api_client.build_collection_param(opts[:'fields_metric_property'], :csv) if !opts[:'fields_metric_property'].nil?

  # header parameters
  header_params = opts[:header_params] || {}
  # klaviyo api revision
  header_params['revision'] =  ENV['KLAVIYO_API_REVISION'] || ENV['API_REVISION'] || "2025-07-15"
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/vnd.api+json'])

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:debug_body]

  # return_type
  return_type = opts[:debug_return_type] || 'Hash<String, Object>'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['Klaviyo-API-Key', 'OAuth']

  new_options = opts.merge(
    :operation => :"MetricsApi.get_properties_for_metric",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: MetricsApi#get_properties_for_metric\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#get_property_ids_for_metric(id, opts = {}) ⇒ Hash<String, Object> Also known as: get_metric_relationships_metric_properties, get_metric_relationships_properties

Get Property IDs for Metric Get the IDs of metric properties for the given metric.
*Rate limits*:
Burst: ‘1/s`
Steady: `15/m` Scopes: `metrics:read`

Parameters:

  • id (String)

    The ID of the metric

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:

  • (Hash<String, Object>)


1645
1646
1647
1648
# File 'lib/klaviyo-api-sdk/api/metrics_api.rb', line 1645

def get_property_ids_for_metric(id, opts = {})
  data, _status_code, _headers = get_property_ids_for_metric_with_http_info(id, opts)
  data
end

#get_property_ids_for_metric_with_http_info(id, opts = {}) ⇒ Array<(Hash<String, Object>, Integer, Hash)> Also known as: get_metric_relationships_metric_properties_with_http_info, get_metric_relationships_properties_with_http_info

Get Property IDs for Metric Get the IDs of metric properties for the given metric.&lt;br&gt;&lt;br&gt;*Rate limits*:&lt;br&gt;Burst: &#x60;1/s&#x60;&lt;br&gt;Steady: &#x60;15/m&#x60; Scopes: &#x60;metrics:read&#x60;

Parameters:

  • id (String)

    The ID of the metric

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:

  • (Array<(Hash<String, Object>, Integer, Hash)>)

    Hash<String, Object> data, response status code and response headers



1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
# File 'lib/klaviyo-api-sdk/api/metrics_api.rb', line 1661

def get_property_ids_for_metric_with_http_info(id, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: MetricsApi.get_property_ids_for_metric ...'
  end
  # verify the required parameter 'id' is set
  if @api_client.config.client_side_validation && id.nil?
    fail ArgumentError, "Missing the required parameter 'id' when calling MetricsApi.get_property_ids_for_metric"
  end
  # resource path
  local_var_path = '/api/metrics/{id}/relationships/metric-properties'.sub('{' + 'id' + '}', CGI.escape(id.to_s))

  # query parameters
  query_params = opts[:query_params] || {}

  # header parameters
  header_params = opts[:header_params] || {}
  # klaviyo api revision
  header_params['revision'] =  ENV['KLAVIYO_API_REVISION'] || ENV['API_REVISION'] || "2025-07-15"
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/vnd.api+json'])

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:debug_body]

  # return_type
  return_type = opts[:debug_return_type] || 'Hash<String, Object>'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['Klaviyo-API-Key', 'OAuth']

  new_options = opts.merge(
    :operation => :"MetricsApi.get_property_ids_for_metric",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: MetricsApi#get_property_ids_for_metric\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#query_metric_aggregates(metric_aggregate_query, opts = {}) ⇒ Hash<String, Object> Also known as: create_metric_aggregate

Query Metric Aggregates Query and aggregate event data associated with a metric, including native Klaviyo metrics, integration-specific metrics, and custom events (not to be confused with [custom metrics](developers.klaviyo.com/en/reference/custom_metrics_api_overview), which are not supported at this time). Queries must be passed in the JSON body of your ‘POST` request. To request campaign and flow performance data that matches the data shown in Klaviyo’s UI, we recommend the [Reporting API](developers.klaviyo.com/en/reference/reporting_api_overview). Results can be filtered and grouped by time, event, or profile dimensions. To learn more about how to use this endpoint, check out our new [Using the Query Metric Aggregates Endpoint guide](developers.klaviyo.com/en/docs/using-the-query-metric-aggregates-endpoint). For a comprehensive list of request body parameters, native Klaviyo metrics, and their associated attributes for grouping and filtering, please refer to the [metrics attributes guide](developers.klaviyo.com/en/docs/supported_metrics_and_attributes).
*Rate limits*:
Burst: ‘3/s`
Steady: `60/m` Scopes: `metrics:read`

Parameters:

  • metric_aggregate_query (MetricAggregateQuery)

    Retrieve Metric Aggregations

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:

  • (Hash<String, Object>)


1722
1723
1724
1725
# File 'lib/klaviyo-api-sdk/api/metrics_api.rb', line 1722

def query_metric_aggregates(metric_aggregate_query, opts = {})
  data, _status_code, _headers = query_metric_aggregates_with_http_info(metric_aggregate_query, opts)
  data
end

#query_metric_aggregates_with_http_info(metric_aggregate_query, opts = {}) ⇒ Array<(Hash<String, Object>, Integer, Hash)> Also known as: create_metric_aggregate_with_http_info

Query Metric Aggregates Query and aggregate event data associated with a metric, including native Klaviyo metrics, integration-specific metrics, and custom events (not to be confused with [custom metrics](developers.klaviyo.com/en/reference/custom_metrics_api_overview), which are not supported at this time). Queries must be passed in the JSON body of your &#x60;POST&#x60; request. To request campaign and flow performance data that matches the data shown in Klaviyo&#39;s UI, we recommend the [Reporting API](developers.klaviyo.com/en/reference/reporting_api_overview). Results can be filtered and grouped by time, event, or profile dimensions. To learn more about how to use this endpoint, check out our new [Using the Query Metric Aggregates Endpoint guide](developers.klaviyo.com/en/docs/using-the-query-metric-aggregates-endpoint). For a comprehensive list of request body parameters, native Klaviyo metrics, and their associated attributes for grouping and filtering, please refer to the [metrics attributes guide](developers.klaviyo.com/en/docs/supported_metrics_and_attributes).&lt;br&gt;&lt;br&gt;*Rate limits*:&lt;br&gt;Burst: &#x60;3/s&#x60;&lt;br&gt;Steady: &#x60;60/m&#x60; Scopes: &#x60;metrics:read&#x60;

Parameters:

  • metric_aggregate_query (MetricAggregateQuery)

    Retrieve Metric Aggregations

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:

  • (Array<(Hash<String, Object>, Integer, Hash)>)

    Hash<String, Object> data, response status code and response headers



1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
# File 'lib/klaviyo-api-sdk/api/metrics_api.rb', line 1735

def query_metric_aggregates_with_http_info(metric_aggregate_query, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: MetricsApi.query_metric_aggregates ...'
  end
  # verify the required parameter 'metric_aggregate_query' is set
  if @api_client.config.client_side_validation && metric_aggregate_query.nil?
    fail ArgumentError, "Missing the required parameter 'metric_aggregate_query' when calling MetricsApi.query_metric_aggregates"
  end
  # resource path
  local_var_path = '/api/metric-aggregates'

  # query parameters
  query_params = opts[:query_params] || {}

  # header parameters
  header_params = opts[:header_params] || {}
  # klaviyo api revision
  header_params['revision'] =  ENV['KLAVIYO_API_REVISION'] || ENV['API_REVISION'] || "2025-07-15"
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/vnd.api+json'])
  # HTTP header 'Content-Type'
  content_type = @api_client.select_header_content_type(['application/vnd.api+json'])
  if !content_type.nil?
      header_params['Content-Type'] = content_type
  end

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:debug_body] || @api_client.object_to_http_body(metric_aggregate_query)

  # return_type
  return_type = opts[:debug_return_type] || 'Hash<String, Object>'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['Klaviyo-API-Key', 'OAuth']

  new_options = opts.merge(
    :operation => :"MetricsApi.query_metric_aggregates",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: MetricsApi#query_metric_aggregates\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#update_custom_metric(id, custom_metric_partial_update_query, opts = {}) ⇒ Hash<String, Object>

Update Custom Metric Update a custom metric with the given custom metric ID.
*Rate limits*:
Burst: ‘1/s`
Steady: `15/m`
Daily: `15/d` Scopes: `metrics:write`

Parameters:

  • id (String)

    The ID of the custom metric

  • custom_metric_partial_update_query (CustomMetricPartialUpdateQuery)

    Update a custom metric by ID.

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:

  • (Hash<String, Object>)


1799
1800
1801
1802
# File 'lib/klaviyo-api-sdk/api/metrics_api.rb', line 1799

def update_custom_metric(id, custom_metric_partial_update_query, opts = {})
  data, _status_code, _headers = update_custom_metric_with_http_info(id, custom_metric_partial_update_query, opts)
  data
end

#update_custom_metric_with_http_info(id, custom_metric_partial_update_query, opts = {}) ⇒ Array<(Hash<String, Object>, Integer, Hash)>

Update Custom Metric Update a custom metric with the given custom metric ID.&lt;br&gt;&lt;br&gt;*Rate limits*:&lt;br&gt;Burst: &#x60;1/s&#x60;&lt;br&gt;Steady: &#x60;15/m&#x60;&lt;br&gt;Daily: &#x60;15/d&#x60; Scopes: &#x60;metrics:write&#x60;

Parameters:

  • id (String)

    The ID of the custom metric

  • custom_metric_partial_update_query (CustomMetricPartialUpdateQuery)

    Update a custom metric by ID.

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:

  • (Array<(Hash<String, Object>, Integer, Hash)>)

    Hash<String, Object> data, response status code and response headers



1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
# File 'lib/klaviyo-api-sdk/api/metrics_api.rb', line 1810

def update_custom_metric_with_http_info(id, custom_metric_partial_update_query, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: MetricsApi.update_custom_metric ...'
  end
  # verify the required parameter 'id' is set
  if @api_client.config.client_side_validation && id.nil?
    fail ArgumentError, "Missing the required parameter 'id' when calling MetricsApi.update_custom_metric"
  end
  # verify the required parameter 'custom_metric_partial_update_query' is set
  if @api_client.config.client_side_validation && custom_metric_partial_update_query.nil?
    fail ArgumentError, "Missing the required parameter 'custom_metric_partial_update_query' when calling MetricsApi.update_custom_metric"
  end
  # resource path
  local_var_path = '/api/custom-metrics/{id}'.sub('{' + 'id' + '}', CGI.escape(id.to_s))

  # query parameters
  query_params = opts[:query_params] || {}

  # header parameters
  header_params = opts[:header_params] || {}
  # klaviyo api revision
  header_params['revision'] =  ENV['KLAVIYO_API_REVISION'] || ENV['API_REVISION'] || "2025-07-15"
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/vnd.api+json'])
  # HTTP header 'Content-Type'
  content_type = @api_client.select_header_content_type(['application/vnd.api+json'])
  if !content_type.nil?
      header_params['Content-Type'] = content_type
  end

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:debug_body] || @api_client.object_to_http_body(custom_metric_partial_update_query)

  # return_type
  return_type = opts[:debug_return_type] || 'Hash<String, Object>'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['Klaviyo-API-Key', 'OAuth']

  new_options = opts.merge(
    :operation => :"MetricsApi.update_custom_metric",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:PATCH, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: MetricsApi#update_custom_metric\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#update_mapped_metric(id, mapped_metric_partial_update_query, opts = {}) ⇒ Hash<String, Object>

Update Mapped Metric Update the mapped metric with the given ID.
*Rate limits*:
Burst: ‘1/s`
Steady: `15/m`
Daily: `30/d` Scopes: `metrics:write`

Parameters:

  • id (String)

    The type of mapping.

  • mapped_metric_partial_update_query (MappedMetricPartialUpdateQuery)

    Update a mapped metric by ID

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:

  • (Hash<String, Object>)


1875
1876
1877
1878
# File 'lib/klaviyo-api-sdk/api/metrics_api.rb', line 1875

def update_mapped_metric(id, mapped_metric_partial_update_query, opts = {})
  data, _status_code, _headers = update_mapped_metric_with_http_info(id, mapped_metric_partial_update_query, opts)
  data
end

#update_mapped_metric_with_http_info(id, mapped_metric_partial_update_query, opts = {}) ⇒ Array<(Hash<String, Object>, Integer, Hash)>

Update Mapped Metric Update the mapped metric with the given ID.&lt;br&gt;&lt;br&gt;*Rate limits*:&lt;br&gt;Burst: &#x60;1/s&#x60;&lt;br&gt;Steady: &#x60;15/m&#x60;&lt;br&gt;Daily: &#x60;30/d&#x60; Scopes: &#x60;metrics:write&#x60;

Parameters:

  • id (String)

    The type of mapping.

  • mapped_metric_partial_update_query (MappedMetricPartialUpdateQuery)

    Update a mapped metric by ID

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:

  • (Array<(Hash<String, Object>, Integer, Hash)>)

    Hash<String, Object> data, response status code and response headers



1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
# File 'lib/klaviyo-api-sdk/api/metrics_api.rb', line 1886

def update_mapped_metric_with_http_info(id, mapped_metric_partial_update_query, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: MetricsApi.update_mapped_metric ...'
  end
  # verify the required parameter 'id' is set
  if @api_client.config.client_side_validation && id.nil?
    fail ArgumentError, "Missing the required parameter 'id' when calling MetricsApi.update_mapped_metric"
  end
  # verify enum value
  allowable_values = ["added_to_cart", "cancelled_sales", "ordered_product", "refunded_sales", "revenue", "started_checkout", "viewed_product"]
  if @api_client.config.client_side_validation && !allowable_values.include?(id)
    fail ArgumentError, "invalid value for \"id\", must be one of #{allowable_values}"
  end
  # verify the required parameter 'mapped_metric_partial_update_query' is set
  if @api_client.config.client_side_validation && mapped_metric_partial_update_query.nil?
    fail ArgumentError, "Missing the required parameter 'mapped_metric_partial_update_query' when calling MetricsApi.update_mapped_metric"
  end
  # resource path
  local_var_path = '/api/mapped-metrics/{id}'.sub('{' + 'id' + '}', CGI.escape(id.to_s))

  # query parameters
  query_params = opts[:query_params] || {}

  # header parameters
  header_params = opts[:header_params] || {}
  # klaviyo api revision
  header_params['revision'] =  ENV['KLAVIYO_API_REVISION'] || ENV['API_REVISION'] || "2025-07-15"
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/vnd.api+json'])
  # HTTP header 'Content-Type'
  content_type = @api_client.select_header_content_type(['application/vnd.api+json'])
  if !content_type.nil?
      header_params['Content-Type'] = content_type
  end

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:debug_body] || @api_client.object_to_http_body(mapped_metric_partial_update_query)

  # return_type
  return_type = opts[:debug_return_type] || 'Hash<String, Object>'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['Klaviyo-API-Key', 'OAuth']

  new_options = opts.merge(
    :operation => :"MetricsApi.update_mapped_metric",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:PATCH, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: MetricsApi#update_mapped_metric\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end