Class: KlaviyoAPI::EventsApi

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_client = ApiClient.default) ⇒ EventsApi

Returns a new instance of EventsApi.



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

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

Instance Attribute Details

#api_client ⇒ Object

Returns the value of attribute api_client.



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

def api_client
  @api_client
end

Instance Method Details

#bulk_create_events(events_bulk_create_job, opts = {}) ⇒ nil Also known as: create_event_bulk_create_job

Bulk Create Events Create a batch of events for one or more profiles. Note that this endpoint allows you to create new profiles or update existing profile properties. At a minimum, profile and metric objects should include at least one profile identifier (e.g., id, email, or phone_number) and the metric name, respectively. Accepts up to 1,000 events per request. The maximum allowed payload size is 5MB. A single string cannot exceed 100KB.

Rate limits:
Burst: 10/s<br>Steady: 150/m Scopes: events:write OpenAPI Spec

Parameters:

  • events_bulk_create_job (EventsBulkCreateJob)
  • opts (Hash) (defaults to: {}) —

    the optional parameters

Returns:

  • (nil)


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

def bulk_create_events(events_bulk_create_job, opts = {})
  bulk_create_events_with_http_info(events_bulk_create_job, opts)
  nil
end

#bulk_create_events_with_http_info(events_bulk_create_job, opts = {}) ⇒ Array<(nil, Integer, Hash)> Also known as: create_event_bulk_create_job_with_http_info

Bulk Create Events Create a batch of events for one or more profiles. Note that this endpoint allows you to create new profiles or update existing profile properties. At a minimum, profile and metric objects should include at least one profile identifier (e.g., `id`, `email`, or `phone_number`) and the metric `name`, respectively. Accepts up to 1,000 events per request. The maximum allowed payload size is 5MB. A single string cannot exceed 100KB.<br><br>Rate limits:<br>Burst: `10/s`<br>Steady: `150/m` Scopes: `events:write` OpenAPI Spec

Parameters:

  • events_bulk_create_job (EventsBulkCreateJob)
  • opts (Hash) (defaults to: {}) —

    the optional parameters

Returns:

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

    nil, 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
# File 'lib/klaviyo-api-sdk/api/events_api.rb', line 39

def bulk_create_events_with_http_info(events_bulk_create_job, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: EventsApi.bulk_create_events ...'
  end
  # verify the required parameter 'events_bulk_create_job' is set
  if @api_client.config.client_side_validation && events_bulk_create_job.nil?
    fail ArgumentError, "Missing the required parameter 'events_bulk_create_job' when calling EventsApi.bulk_create_events"
  end
  # resource path
  local_var_path = '/api/event-bulk-create-jobs'

  # 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'] || "2026-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(events_bulk_create_job)

  # 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 => :"EventsApi.bulk_create_events",
    :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: EventsApi#bulk_create_events\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#create_event(event_create_query_v2, opts = {}) ⇒ nil

Create Event Create a new event to track a profile's activity. Note that this endpoint allows you to create a new profile or update an existing profile's properties. At a minimum, profile and metric objects should include at least one profile identifier (e.g., id, email, or phone_number) and the metric name, respectively. Successful response indicates that the event was validated and submitted for processing, but does not guarantee that processing is complete.

Rate limits:
Burst: 350/s<br>Steady: 3500/m Scopes: events:write OpenAPI Spec

Parameters:

  • event_create_query_v2 (EventCreateQueryV2)
  • opts (Hash) (defaults to: {}) —

    the optional parameters

Returns:

  • (nil)


102
103
104
105
# File 'lib/klaviyo-api-sdk/api/events_api.rb', line 102

def create_event(event_create_query_v2, opts = {})
  create_event_with_http_info(event_create_query_v2, opts)
  nil
end

#create_event_with_http_info(event_create_query_v2, opts = {}) ⇒ Array<(nil, Integer, Hash)>

Create Event Create a new event to track a profile's activity. Note that this endpoint allows you to create a new profile or update an existing profile's properties. At a minimum, profile and metric objects should include at least one profile identifier (e.g., `id`, `email`, or `phone_number`) and the metric `name`, respectively. Successful response indicates that the event was validated and submitted for processing, but does not guarantee that processing is complete.<br><br>Rate limits:<br>Burst: `350/s`<br>Steady: `3500/m` Scopes: `events:write` OpenAPI Spec

Parameters:

  • event_create_query_v2 (EventCreateQueryV2)
  • opts (Hash) (defaults to: {}) —

    the optional parameters

Returns:

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

    nil, response status code and response headers



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
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/klaviyo-api-sdk/api/events_api.rb', line 112

def create_event_with_http_info(event_create_query_v2, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: EventsApi.create_event ...'
  end
  # verify the required parameter 'event_create_query_v2' is set
  if @api_client.config.client_side_validation && event_create_query_v2.nil?
    fail ArgumentError, "Missing the required parameter 'event_create_query_v2' when calling EventsApi.create_event"
  end
  # resource path
  local_var_path = '/api/events'

  # 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'] || "2026-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(event_create_query_v2)

  # 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 => :"EventsApi.create_event",
    :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: EventsApi#create_event\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

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

Get Event Get an event with the given event ID.

Rate limits:
Burst: 10/s<br>Steady: 150/m Scopes: events:read OpenAPI Spec

Parameters:

  • id (String) —

    ID of the event

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

    the optional parameters

Options Hash (opts):

Returns:

  • (Hash<String, Object>)


177
178
179
180
# File 'lib/klaviyo-api-sdk/api/events_api.rb', line 177

def get_event(id, opts = {})
  data, _status_code, _headers = get_event_with_http_info(id, opts)
  data
end

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

Get Event Get an event with the given event ID.<br><br>Rate limits:<br>Burst: `10/s`<br>Steady: `150/m` Scopes: `events:read` OpenAPI Spec

Parameters:

  • id (String) —

    ID of the event

  • 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



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
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
# File 'lib/klaviyo-api-sdk/api/events_api.rb', line 192

def get_event_with_http_info(id, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: EventsApi.get_event ...'
  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 EventsApi.get_event"
  end
  allowable_values = ["id"]
  if @api_client.config.client_side_validation && opts[:'fields_attribution'] && !opts[:'fields_attribution'].all? { |item| allowable_values.include?(item) }
    fail ArgumentError, "invalid value for \"fields_attribution\", must include one of #{allowable_values}"
  end
  allowable_values = ["datetime", "event_properties", "id", "timestamp", "uuid"]
  if @api_client.config.client_side_validation && opts[:'fields_event'] && !opts[:'fields_event'].all? { |item| allowable_values.include?(item) }
    fail ArgumentError, "invalid value for \"fields_event\", must include one of #{allowable_values}"
  end
  allowable_values = ["created", "id", "integration", "name", "updated"]
  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 = ["created", "email", "external_id", "first_name", "id", "image", "last_event_date", "last_name", "locale", "location", "location.address1", "location.address2", "location.city", "location.country", "location.ip", "location.latitude", "location.longitude", "location.region", "location.timezone", "location.zip", "organization", "phone_number", "properties", "title", "updated"]
  if @api_client.config.client_side_validation && opts[:'fields_profile'] && !opts[:'fields_profile'].all? { |item| allowable_values.include?(item) }
    fail ArgumentError, "invalid value for \"fields_profile\", must include one of #{allowable_values}"
  end
  allowable_values = ["attributions", "metric", "profile"]
  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/events/{id}'.sub('{' + 'id' + '}', CGI.escape(id.to_s))

  # query parameters
  query_params = opts[:query_params] || {}
  query_params[:'fields[attribution]'] = @api_client.build_collection_param(opts[:'fields_attribution'], :csv) if !opts[:'fields_attribution'].nil?
  query_params[:'fields[event]'] = @api_client.build_collection_param(opts[:'fields_event'], :csv) if !opts[:'fields_event'].nil?
  query_params[:'fields[metric]'] = @api_client.build_collection_param(opts[:'fields_metric'], :csv) if !opts[:'fields_metric'].nil?
  query_params[:'fields[profile]'] = @api_client.build_collection_param(opts[:'fields_profile'], :csv) if !opts[:'fields_profile'].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'] || "2026-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 => :"EventsApi.get_event",
    :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: EventsApi#get_event\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

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

Get Events Get all events in an account Requests can be sorted by the following fields: datetime, timestamp Custom metrics are not supported in the metric_id filter. Returns a maximum of 200 events per page.

Rate limits:
Burst: 350/s<br>Steady: 3500/m Scopes: events:read OpenAPI Spec

Parameters:

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

    the optional parameters

Options Hash (opts):

Returns:

  • (Hash<String, Object>)


280
281
282
283
# File 'lib/klaviyo-api-sdk/api/events_api.rb', line 280

def get_events(opts = {})
  data, _status_code, _headers = get_events_with_http_info(opts)
  data
end

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

Get Events Get all events in an account Requests can be sorted by the following fields: `datetime`, `timestamp` Custom metrics are not supported in the `metric_id` filter. Returns a maximum of 200 events per page.<br><br>Rate limits:<br>Burst: `350/s`<br>Steady: `3500/m` Scopes: `events:read` OpenAPI Spec

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



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
342
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
# File 'lib/klaviyo-api-sdk/api/events_api.rb', line 298

def get_events_with_http_info(opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: EventsApi.get_events ...'
  end
  allowable_values = ["id"]
  if @api_client.config.client_side_validation && opts[:'fields_attribution'] && !opts[:'fields_attribution'].all? { |item| allowable_values.include?(item) }
    fail ArgumentError, "invalid value for \"fields_attribution\", must include one of #{allowable_values}"
  end
  allowable_values = ["datetime", "event_properties", "id", "timestamp", "uuid"]
  if @api_client.config.client_side_validation && opts[:'fields_event'] && !opts[:'fields_event'].all? { |item| allowable_values.include?(item) }
    fail ArgumentError, "invalid value for \"fields_event\", must include one of #{allowable_values}"
  end
  allowable_values = ["created", "id", "integration", "name", "updated"]
  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 = ["created", "email", "external_id", "first_name", "id", "image", "last_event_date", "last_name", "locale", "location", "location.address1", "location.address2", "location.city", "location.country", "location.ip", "location.latitude", "location.longitude", "location.region", "location.timezone", "location.zip", "organization", "phone_number", "properties", "title", "updated"]
  if @api_client.config.client_side_validation && opts[:'fields_profile'] && !opts[:'fields_profile'].all? { |item| allowable_values.include?(item) }
    fail ArgumentError, "invalid value for \"fields_profile\", must include one of #{allowable_values}"
  end
  allowable_values = ["attributions", "metric", "profile"]
  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
  if @api_client.config.client_side_validation && !opts[:'page_size'].nil? && opts[:'page_size'] > 1000
    fail ArgumentError, 'invalid value for "opts[:"page_size"]" when calling EventsApi.get_events, must be smaller than or equal to 1000.'
  end

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

  allowable_values = ["datetime", "-datetime", "timestamp", "-timestamp"]
  if @api_client.config.client_side_validation && opts[:'sort'] && !allowable_values.include?(opts[:'sort'])
    fail ArgumentError, "invalid value for \"sort\", must be one of #{allowable_values}"
  end
  # resource path
  local_var_path = '/api/events'

  # query parameters
  query_params = opts[:query_params] || {}
  query_params[:'fields[attribution]'] = @api_client.build_collection_param(opts[:'fields_attribution'], :csv) if !opts[:'fields_attribution'].nil?
  query_params[:'fields[event]'] = @api_client.build_collection_param(opts[:'fields_event'], :csv) if !opts[:'fields_event'].nil?
  query_params[:'fields[metric]'] = @api_client.build_collection_param(opts[:'fields_metric'], :csv) if !opts[:'fields_metric'].nil?
  query_params[:'fields[profile]'] = @api_client.build_collection_param(opts[:'fields_profile'], :csv) if !opts[:'fields_profile'].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?
  query_params[:'page[size]'] = opts[:'page_size'] if !opts[:'page_size'].nil?
  query_params[:'sort'] = opts[:'sort'] if !opts[:'sort'].nil?

  # header parameters
  header_params = opts[:header_params] || {}
  # klaviyo api revision
  header_params['revision'] =  ENV['KLAVIYO_API_REVISION'] || ENV['API_REVISION'] || "2026-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 => :"EventsApi.get_events",
    :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: EventsApi#get_events\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

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

Get Metric for Event Get the metric for an event with the given event ID.

Rate limits:
Burst: 350/s<br>Steady: 3500/m Scopes: events:read metrics:read OpenAPI Spec

Parameters:

  • id (String) —

    ID of the event

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

    the optional parameters

Options Hash (opts):

Returns:

  • (Hash<String, Object>)


391
392
393
394
# File 'lib/klaviyo-api-sdk/api/events_api.rb', line 391

def get_metric_for_event(id, opts = {})
  data, _status_code, _headers = get_metric_for_event_with_http_info(id, opts)
  data
end

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

Get Metric for Event Get the metric for an event with the given event ID.<br><br>Rate limits:<br>Burst: `350/s`<br>Steady: `3500/m` Scopes: `events:read` `metrics:read` OpenAPI Spec

Parameters:

  • id (String) —

    ID of the event

  • 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



405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
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
# File 'lib/klaviyo-api-sdk/api/events_api.rb', line 405

def get_metric_for_event_with_http_info(id, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: EventsApi.get_metric_for_event ...'
  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 EventsApi.get_metric_for_event"
  end
  allowable_values = ["created", "id", "integration", "name", "updated"]
  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/events/{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'] || "2026-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 => :"EventsApi.get_metric_for_event",
    :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: EventsApi#get_metric_for_event\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

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

Get Metric ID for Event Get a list of related Metrics for an Event

Rate limits:
Burst: 350/s<br>Steady: 3500/m Scopes: events:read metrics:read OpenAPI Spec

Parameters:

  • id (String) —

    ID of the event

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

    the optional parameters

Returns:

  • (Hash<String, Object>)


468
469
470
471
# File 'lib/klaviyo-api-sdk/api/events_api.rb', line 468

def get_metric_id_for_event(id, opts = {})
  data, _status_code, _headers = get_metric_id_for_event_with_http_info(id, opts)
  data
end

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

Get Metric ID for Event Get a list of related Metrics for an Event<br><br>Rate limits:<br>Burst: `350/s`<br>Steady: `3500/m` Scopes: `events:read` `metrics:read` OpenAPI Spec

Parameters:

  • id (String) —

    ID of the event

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

    the optional parameters

Returns:

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

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



481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
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
# File 'lib/klaviyo-api-sdk/api/events_api.rb', line 481

def get_metric_id_for_event_with_http_info(id, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: EventsApi.get_metric_id_for_event ...'
  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 EventsApi.get_metric_id_for_event"
  end
  # resource path
  local_var_path = '/api/events/{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'] || "2026-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 => :"EventsApi.get_metric_id_for_event",
    :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: EventsApi#get_metric_id_for_event\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

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

Get Profile for Event Get the profile associated with an event with the given event ID.

Rate limits:
Burst: 350/s<br>Steady: 3500/m Scopes: events:read profiles:read OpenAPI Spec

Parameters:

  • id (String) —

    ID of the event

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

    the optional parameters

Options Hash (opts):

Returns:

  • (Hash<String, Object>)


541
542
543
544
# File 'lib/klaviyo-api-sdk/api/events_api.rb', line 541

def get_profile_for_event(id, opts = {})
  data, _status_code, _headers = get_profile_for_event_with_http_info(id, opts)
  data
end

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

Get Profile for Event Get the profile associated with an event with the given event ID.<br><br>Rate limits:<br>Burst: `350/s`<br>Steady: `3500/m` Scopes: `events:read` `profiles:read` OpenAPI Spec

Parameters:

  • id (String) —

    ID of the event

  • 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



556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
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
# File 'lib/klaviyo-api-sdk/api/events_api.rb', line 556

def get_profile_for_event_with_http_info(id, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: EventsApi.get_profile_for_event ...'
  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 EventsApi.get_profile_for_event"
  end
  allowable_values = ["subscriptions", "predictive_analytics"]
  if @api_client.config.client_side_validation && opts[:'additional_fields_profile'] && !opts[:'additional_fields_profile'].all? { |item| allowable_values.include?(item) }
    fail ArgumentError, "invalid value for \"additional_fields_profile\", must include one of #{allowable_values}"
  end
  allowable_values = ["created", "email", "external_id", "first_name", "id", "image", "last_event_date", "last_name", "locale", "location", "location.address1", "location.address2", "location.city", "location.country", "location.ip", "location.latitude", "location.longitude", "location.region", "location.timezone", "location.zip", "organization", "phone_number", "predictive_analytics", "predictive_analytics.average_days_between_orders", "predictive_analytics.average_order_value", "predictive_analytics.churn_probability", "predictive_analytics.expected_date_of_next_order", "predictive_analytics.historic_clv", "predictive_analytics.historic_number_of_orders", "predictive_analytics.predicted_clv", "predictive_analytics.predicted_number_of_orders", "predictive_analytics.ranked_channel_affinity", "predictive_analytics.total_clv", "properties", "subscriptions", "subscriptions.email", "subscriptions.email.marketing", "subscriptions.email.marketing.can_receive_email_marketing", "subscriptions.email.marketing.consent", "subscriptions.email.marketing.consent_timestamp", "subscriptions.email.marketing.custom_method_detail", "subscriptions.email.marketing.double_optin", "subscriptions.email.marketing.last_updated", "subscriptions.email.marketing.list_suppressions", "subscriptions.email.marketing.method", "subscriptions.email.marketing.method_detail", "subscriptions.email.marketing.suppression", "subscriptions.email.open_tracking", "subscriptions.email.open_tracking.can_receive", "subscriptions.email.open_tracking.consent", "subscriptions.email.open_tracking.consent_timestamp", "subscriptions.email.open_tracking.created_timestamp", "subscriptions.email.open_tracking.last_updated", "subscriptions.email.open_tracking.metadata", "subscriptions.email.open_tracking.valid_until", "subscriptions.mobile_push", "subscriptions.mobile_push.marketing", "subscriptions.mobile_push.marketing.can_receive_push_marketing", "subscriptions.mobile_push.marketing.consent", "subscriptions.mobile_push.marketing.consent_timestamp", "subscriptions.sms", "subscriptions.sms.marketing", "subscriptions.sms.marketing.can_receive_sms_marketing", "subscriptions.sms.marketing.consent", "subscriptions.sms.marketing.consent_timestamp", "subscriptions.sms.marketing.last_updated", "subscriptions.sms.marketing.method", "subscriptions.sms.marketing.method_detail", "subscriptions.sms.transactional", "subscriptions.sms.transactional.can_receive_sms_transactional", "subscriptions.sms.transactional.consent", "subscriptions.sms.transactional.consent_timestamp", "subscriptions.sms.transactional.last_updated", "subscriptions.sms.transactional.method", "subscriptions.sms.transactional.method_detail", "subscriptions.whatsapp", "subscriptions.whatsapp.conversational", "subscriptions.whatsapp.conversational.can_receive", "subscriptions.whatsapp.conversational.consent", "subscriptions.whatsapp.conversational.consent_timestamp", "subscriptions.whatsapp.conversational.created_timestamp", "subscriptions.whatsapp.conversational.last_updated", "subscriptions.whatsapp.conversational.metadata", "subscriptions.whatsapp.conversational.phone_number", "subscriptions.whatsapp.conversational.valid_until", "subscriptions.whatsapp.marketing", "subscriptions.whatsapp.marketing.can_receive", "subscriptions.whatsapp.marketing.consent", "subscriptions.whatsapp.marketing.consent_timestamp", "subscriptions.whatsapp.marketing.created_timestamp", "subscriptions.whatsapp.marketing.last_updated", "subscriptions.whatsapp.marketing.metadata", "subscriptions.whatsapp.marketing.phone_number", "subscriptions.whatsapp.marketing.valid_until", "subscriptions.whatsapp.transactional", "subscriptions.whatsapp.transactional.can_receive", "subscriptions.whatsapp.transactional.consent", "subscriptions.whatsapp.transactional.consent_timestamp", "subscriptions.whatsapp.transactional.created_timestamp", "subscriptions.whatsapp.transactional.last_updated", "subscriptions.whatsapp.transactional.metadata", "subscriptions.whatsapp.transactional.phone_number", "subscriptions.whatsapp.transactional.valid_until", "title", "updated"]
  if @api_client.config.client_side_validation && opts[:'fields_profile'] && !opts[:'fields_profile'].all? { |item| allowable_values.include?(item) }
    fail ArgumentError, "invalid value for \"fields_profile\", must include one of #{allowable_values}"
  end
  # resource path
  local_var_path = '/api/events/{id}/profile'.sub('{' + 'id' + '}', CGI.escape(id.to_s))

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

  # header parameters
  header_params = opts[:header_params] || {}
  # klaviyo api revision
  header_params['revision'] =  ENV['KLAVIYO_API_REVISION'] || ENV['API_REVISION'] || "2026-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 => :"EventsApi.get_profile_for_event",
    :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: EventsApi#get_profile_for_event\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

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

Get Profile ID for Event Get profile relationships for an event with the given event ID.

Rate limits:
Burst: 350/s<br>Steady: 3500/m Scopes: events:read profiles:read OpenAPI Spec

Parameters:

  • id (String) —

    ID of the event

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

    the optional parameters

Returns:

  • (Hash<String, Object>)


624
625
626
627
# File 'lib/klaviyo-api-sdk/api/events_api.rb', line 624

def get_profile_id_for_event(id, opts = {})
  data, _status_code, _headers = get_profile_id_for_event_with_http_info(id, opts)
  data
end

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

Get Profile ID for Event Get profile relationships for an event with the given event ID.<br><br>Rate limits:<br>Burst: `350/s`<br>Steady: `3500/m` Scopes: `events:read` `profiles:read` OpenAPI Spec

Parameters:

  • id (String) —

    ID of the event

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

    the optional parameters

Returns:

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

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



637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
# File 'lib/klaviyo-api-sdk/api/events_api.rb', line 637

def get_profile_id_for_event_with_http_info(id, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: EventsApi.get_profile_id_for_event ...'
  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 EventsApi.get_profile_id_for_event"
  end
  # resource path
  local_var_path = '/api/events/{id}/relationships/profile'.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'] || "2026-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 => :"EventsApi.get_profile_id_for_event",
    :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: EventsApi#get_profile_id_for_event\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end