Class: Klaviyo::MetricsApi

Inherits:
Object
  • Object
show all
Defined in:
lib/klaviyo_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.



19
20
21
# File 'lib/klaviyo_sdk/api/metrics_api.rb', line 19

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

Instance Attribute Details

#api_clientObject

Returns the value of attribute api_client.



17
18
19
# File 'lib/klaviyo_sdk/api/metrics_api.rb', line 17

def api_client
  @api_client
end

Instance Method Details

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

Get Metrics Info Returns a list of all the metrics in your account.

Parameters:

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

    the optional parameters

Options Hash (opts):

  • :page (Integer)

    For pagination, which page of results to return. Default &#x3D; 0 (default to 0)

  • :count (Integer)

    For pagination, the number of results to return. Default &#x3D; 50 ; Max &#x3D; 100 (default to 50)

Returns:

  • (Hash<String, Object>)


28
29
30
31
# File 'lib/klaviyo_sdk/api/metrics_api.rb', line 28

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

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

Get Metrics Info Returns a list of all the metrics in your account.

Parameters:

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

    the optional parameters

Options Hash (opts):

  • :page (Integer)

    For pagination, which page of results to return. Default &#x3D; 0

  • :count (Integer)

    For pagination, the number of results to return. Default &#x3D; 50 ; Max &#x3D; 100

Returns:

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

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



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
90
91
92
93
94
95
# File 'lib/klaviyo_sdk/api/metrics_api.rb', line 39

def get_metrics_with_http_info(opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: MetricsApi.get_metrics ...'
  end
  if @api_client.config.client_side_validation && !opts[:'page'].nil? && opts[:'page'] < 0
    fail ArgumentError, 'invalid value for "opts[:"page"]" when calling MetricsApi.get_metrics, must be greater than or equal to 0.'
  end

  if @api_client.config.client_side_validation && !opts[:'count'].nil? && opts[:'count'] > 100
    fail ArgumentError, 'invalid value for "opts[:"count"]" when calling MetricsApi.get_metrics, must be smaller than or equal to 100.'
  end

  if @api_client.config.client_side_validation && !opts[:'count'].nil? && opts[:'count'] < 1
    fail ArgumentError, 'invalid value for "opts[:"count"]" when calling MetricsApi.get_metrics, must be greater than or equal to 1.'
  end

  # resource path
  local_var_path = '/v1/metrics'

  # query parameters
  query_params = opts[:query_params] || {}
  query_params[:'page'] = opts[:'page'] if !opts[:'page'].nil?
  query_params[:'count'] = opts[:'count'] if !opts[:'count'].nil?

  # header parameters
  header_params = opts[:header_params] || {}
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/json'])

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

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

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

  # auth_names
  auth_names = opts[:debug_auth_names] || ['ApiKeyAuth']

  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

#metric_export(metric_id, opts = {}) ⇒ MetricExport

Query Event Data Exports event data from Klaviyo, optionally filtering and segmenting on available event properties. Note that the only comparison operator currently supported is ‘=`. To ensure a correct response, enter parameters in the curl request as they are ordered below:

Parameters:

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

    the optional parameters

Options Hash (opts):

  • :start_date (String)

    Beginning of timeframe to pull event data for. The default value is 1 month ago. Can also accept a 10-digit UNIX timestamp. When sending a &#x60;start_date&#x60;, you must also send an &#x60;end_date&#x60; Ex: &#x60;1610524800&#x60; OR &#x60;2021-01-13&#x60;

  • :end_date (String)

    End of timeframe to pull event data for. The default is the current day, or 1 month from start_date, whichever is sooner. Can also accept a 10-digit UNIX timestamp. When sending an &#x60;end_date&#x60;, you must also send a &#x60;start_date&#x60;. Must be *at most* 31 days after &#x60;start_date&#x60; Ex: &#x60;1612080000&#x60; OR &#x60;2021-01-31&#x60;

  • :unit (String)

    Granularity to bucket data points into - one of &#x60;day&#x60;, &#x60;week&#x60;, or &#x60;month&#x60;. Defaults to &#x60;day&#x60;. (default to ‘day’)

  • :measurement (String)

    Type of metric to fetch - one of &#x60;unique&#x60;, &#x60;count&#x60;, &#x60;value&#x60;, or &#x60;sum&#x60;. Defaults to &#x60;count&#x60;. For &#x60;sum&#x60; a property name to operate on must be supplied as a JSON-encoded list like &#x60;&#x60; (default to ‘count’)

  • :where (String)

    Optional, JSON-encoded list. Conditions to use to filter the set of events. A max of 1 condition can be given. &#x60;where&#x60; and &#x60;by&#x60; parameters cannot be specified at the same time. ex: &#x60;[]&#x60;

  • :by (String)

    The name of a property to segment the event data on. &#x60;where&#x60; and &#x60;by&#x60; parameters cannot be specified at the same time. Cannot be used alongside &#x60;where&#x60; parameter.

  • :count (Integer)

    Maximum number of segments to return. Default &#x3D; 25, **MAX &#x3D; 1000** (default to 25)

Returns:



109
110
111
112
# File 'lib/klaviyo_sdk/api/metrics_api.rb', line 109

def metric_export(metric_id, opts = {})
  data, _status_code, _headers = metric_export_with_http_info(metric_id, opts)
  data
end

#metric_export_with_http_info(metric_id, opts = {}) ⇒ Array<(MetricExport, Integer, Hash)>

Query Event Data Exports event data from Klaviyo, optionally filtering and segmenting on available event properties. Note that the only comparison operator currently supported is &#x60;&#x3D;&#x60;. To ensure a correct response, enter parameters in the curl request as they are ordered below:

Parameters:

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

    the optional parameters

Options Hash (opts):

  • :start_date (String)

    Beginning of timeframe to pull event data for. The default value is 1 month ago. Can also accept a 10-digit UNIX timestamp. When sending a &#x60;start_date&#x60;, you must also send an &#x60;end_date&#x60; Ex: &#x60;1610524800&#x60; OR &#x60;2021-01-13&#x60;

  • :end_date (String)

    End of timeframe to pull event data for. The default is the current day, or 1 month from start_date, whichever is sooner. Can also accept a 10-digit UNIX timestamp. When sending an &#x60;end_date&#x60;, you must also send a &#x60;start_date&#x60;. Must be *at most* 31 days after &#x60;start_date&#x60; Ex: &#x60;1612080000&#x60; OR &#x60;2021-01-31&#x60;

  • :unit (String)

    Granularity to bucket data points into - one of &#x60;day&#x60;, &#x60;week&#x60;, or &#x60;month&#x60;. Defaults to &#x60;day&#x60;.

  • :measurement (String)

    Type of metric to fetch - one of &#x60;unique&#x60;, &#x60;count&#x60;, &#x60;value&#x60;, or &#x60;sum&#x60;. Defaults to &#x60;count&#x60;. For &#x60;sum&#x60; a property name to operate on must be supplied as a JSON-encoded list like &#x60;&#x60;

  • :where (String)

    Optional, JSON-encoded list. Conditions to use to filter the set of events. A max of 1 condition can be given. &#x60;where&#x60; and &#x60;by&#x60; parameters cannot be specified at the same time. ex: &#x60;[]&#x60;

  • :by (String)

    The name of a property to segment the event data on. &#x60;where&#x60; and &#x60;by&#x60; parameters cannot be specified at the same time. Cannot be used alongside &#x60;where&#x60; parameter.

  • :count (Integer)

    Maximum number of segments to return. Default &#x3D; 25, **MAX &#x3D; 1000**

Returns:

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

    MetricExport data, response status code and response headers



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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/klaviyo_sdk/api/metrics_api.rb', line 126

def metric_export_with_http_info(metric_id, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: MetricsApi.metric_export ...'
  end
  # verify the required parameter 'metric_id' is set
  if @api_client.config.client_side_validation && metric_id.nil?
    fail ArgumentError, "Missing the required parameter 'metric_id' when calling MetricsApi.metric_export"
  end
  if @api_client.config.client_side_validation && !opts[:'count'].nil? && opts[:'count'] > 1000
    fail ArgumentError, 'invalid value for "opts[:"count"]" when calling MetricsApi.metric_export, must be smaller than or equal to 1000.'
  end

  if @api_client.config.client_side_validation && !opts[:'count'].nil? && opts[:'count'] < 1
    fail ArgumentError, 'invalid value for "opts[:"count"]" when calling MetricsApi.metric_export, must be greater than or equal to 1.'
  end

  # resource path
  local_var_path = '/v1/metric/{metric_id}/export'.sub('{' + 'metric_id' + '}', CGI.escape(metric_id.to_s))

  # query parameters
  query_params = opts[:query_params] || {}
  query_params[:'start_date'] = opts[:'start_date'] if !opts[:'start_date'].nil?
  query_params[:'end_date'] = opts[:'end_date'] if !opts[:'end_date'].nil?
  query_params[:'unit'] = opts[:'unit'] if !opts[:'unit'].nil?
  query_params[:'measurement'] = opts[:'measurement'] if !opts[:'measurement'].nil?
  query_params[:'where'] = opts[:'where'] if !opts[:'where'].nil?
  query_params[:'by'] = opts[:'by'] if !opts[:'by'].nil?
  query_params[:'count'] = opts[:'count'] if !opts[:'count'].nil?

  # header parameters
  header_params = opts[:header_params] || {}
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/json'])

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

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

  # return_type
  return_type = opts[:debug_return_type] || 'MetricExport'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['ApiKeyAuth']

  new_options = opts.merge(
    :operation => :"MetricsApi.metric_export",
    :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#metric_export\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#metric_timeline(metric_id, opts = {}) ⇒ MetricTimeline

Get Events for a Specific Metric Returns a batched timeline for one specific metric.

Parameters:

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

    the optional parameters

Options Hash (opts):

  • :since (String)

    Either a 10-digit Unix timestamp (UTC) to use as starting datetime, OR a pagination token obtained from the &#x60;next&#x60; attribute of a prior API call. For backwards compatibility, UUIDs will continue to be supported for a limited time. Defaults to current time.

  • :count (Integer)

    Number of events to return in a batch. Max &#x3D; 100 (default to 50)

  • :sort (String)

    Sort order to apply to timeline, either descending or ascending. Valid values are &#x60;desc&#x60; or &#x60;asc&#x60;. Defaults to &#x60;desc&#x60;. Always descending when &#x60;since&#x60; is not sent, as &#x60;since&#x60; defaults to current time. (default to ‘desc’)

Returns:



197
198
199
200
# File 'lib/klaviyo_sdk/api/metrics_api.rb', line 197

def metric_timeline(metric_id, opts = {})
  data, _status_code, _headers = metric_timeline_with_http_info(metric_id, opts)
  data
end

#metric_timeline_with_http_info(metric_id, opts = {}) ⇒ Array<(MetricTimeline, Integer, Hash)>

Get Events for a Specific Metric Returns a batched timeline for one specific metric.

Parameters:

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

    the optional parameters

Options Hash (opts):

  • :since (String)

    Either a 10-digit Unix timestamp (UTC) to use as starting datetime, OR a pagination token obtained from the &#x60;next&#x60; attribute of a prior API call. For backwards compatibility, UUIDs will continue to be supported for a limited time. Defaults to current time.

  • :count (Integer)

    Number of events to return in a batch. Max &#x3D; 100

  • :sort (String)

    Sort order to apply to timeline, either descending or ascending. Valid values are &#x60;desc&#x60; or &#x60;asc&#x60;. Defaults to &#x60;desc&#x60;. Always descending when &#x60;since&#x60; is not sent, as &#x60;since&#x60; defaults to current time.

Returns:

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

    MetricTimeline data, response status code and response headers



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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
# File 'lib/klaviyo_sdk/api/metrics_api.rb', line 210

def metric_timeline_with_http_info(metric_id, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: MetricsApi.metric_timeline ...'
  end
  # verify the required parameter 'metric_id' is set
  if @api_client.config.client_side_validation && metric_id.nil?
    fail ArgumentError, "Missing the required parameter 'metric_id' when calling MetricsApi.metric_timeline"
  end
  if @api_client.config.client_side_validation && !opts[:'count'].nil? && opts[:'count'] > 100
    fail ArgumentError, 'invalid value for "opts[:"count"]" when calling MetricsApi.metric_timeline, must be smaller than or equal to 100.'
  end

  if @api_client.config.client_side_validation && !opts[:'count'].nil? && opts[:'count'] < 1
    fail ArgumentError, 'invalid value for "opts[:"count"]" when calling MetricsApi.metric_timeline, must be greater than or equal to 1.'
  end

  # resource path
  local_var_path = '/v1/metric/{metric_id}/timeline'.sub('{' + 'metric_id' + '}', CGI.escape(metric_id.to_s))

  # query parameters
  query_params = opts[:query_params] || {}
  query_params[:'since'] = opts[:'since'] if !opts[:'since'].nil?
  query_params[:'count'] = opts[:'count'] if !opts[:'count'].nil?
  query_params[:'sort'] = opts[:'sort'] if !opts[:'sort'].nil?

  # header parameters
  header_params = opts[:header_params] || {}
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/json'])

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

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

  # return_type
  return_type = opts[:debug_return_type] || 'MetricTimeline'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['ApiKeyAuth']

  new_options = opts.merge(
    :operation => :"MetricsApi.metric_timeline",
    :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#metric_timeline\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#metrics_timeline(opts = {}) ⇒ MetricTimeline

Get Events for All Metrics Returns a batched timeline of all events in your account.

Parameters:

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

    the optional parameters

Options Hash (opts):

  • :since (String)

    Either a 10-digit Unix timestamp (UTC) to use as starting datetime, OR a pagination token obtained from the next attribute of a prior API call. For backwards compatibility, UUIDs will continue to be supported for a limited time. Defaults to current time.

  • :count (Integer)

    Number of events to return in a batch. Default &#x3D; 50, Max &#x3D; 100 (default to 50)

  • :sort (String)

    Sort order to apply to timeline, either descending or ascending. Valid values are &#x60;desc&#x60; or &#x60;asc&#x60;. Defaults to &#x60;desc&#x60;. Always descending when &#x60;since&#x60; is not sent, as &#x60;since&#x60; defaults to current time. (default to ‘desc’)

Returns:



276
277
278
279
# File 'lib/klaviyo_sdk/api/metrics_api.rb', line 276

def metrics_timeline(opts = {})
  data, _status_code, _headers = metrics_timeline_with_http_info(opts)
  data
end

#metrics_timeline_with_http_info(opts = {}) ⇒ Array<(MetricTimeline, Integer, Hash)>

Get Events for All Metrics Returns a batched timeline of all events in your account.

Parameters:

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

    the optional parameters

Options Hash (opts):

  • :since (String)

    Either a 10-digit Unix timestamp (UTC) to use as starting datetime, OR a pagination token obtained from the next attribute of a prior API call. For backwards compatibility, UUIDs will continue to be supported for a limited time. Defaults to current time.

  • :count (Integer)

    Number of events to return in a batch. Default &#x3D; 50, Max &#x3D; 100

  • :sort (String)

    Sort order to apply to timeline, either descending or ascending. Valid values are &#x60;desc&#x60; or &#x60;asc&#x60;. Defaults to &#x60;desc&#x60;. Always descending when &#x60;since&#x60; is not sent, as &#x60;since&#x60; defaults to current time.

Returns:

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

    MetricTimeline data, response status code and response headers



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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
# File 'lib/klaviyo_sdk/api/metrics_api.rb', line 288

def metrics_timeline_with_http_info(opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: MetricsApi.metrics_timeline ...'
  end
  if @api_client.config.client_side_validation && !opts[:'count'].nil? && opts[:'count'] > 100
    fail ArgumentError, 'invalid value for "opts[:"count"]" when calling MetricsApi.metrics_timeline, must be smaller than or equal to 100.'
  end

  if @api_client.config.client_side_validation && !opts[:'count'].nil? && opts[:'count'] < 1
    fail ArgumentError, 'invalid value for "opts[:"count"]" when calling MetricsApi.metrics_timeline, must be greater than or equal to 1.'
  end

  # resource path
  local_var_path = '/v1/metrics/timeline'

  # query parameters
  query_params = opts[:query_params] || {}
  query_params[:'since'] = opts[:'since'] if !opts[:'since'].nil?
  query_params[:'count'] = opts[:'count'] if !opts[:'count'].nil?
  query_params[:'sort'] = opts[:'sort'] if !opts[:'sort'].nil?

  # header parameters
  header_params = opts[:header_params] || {}
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/json'])

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

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

  # return_type
  return_type = opts[:debug_return_type] || 'MetricTimeline'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['ApiKeyAuth']

  new_options = opts.merge(
    :operation => :"MetricsApi.metrics_timeline",
    :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#metrics_timeline\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end