Class: KlaviyoAPI::SegmentsApi

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_client = ApiClient.default) ⇒ SegmentsApi

Returns a new instance of SegmentsApi.



18
19
20
# File 'lib/klaviyo-api-sdk/api/segments_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/segments_api.rb', line 16

def api_client
  @api_client
end

Instance Method Details

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

Create Segment Create a segment.
*Rate limits*:
Burst: ‘1/s`
Steady: `15/m`
Daily: `100/d` Scopes: `segments:write`

Parameters:

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

    the optional parameters

Returns:

  • (Hash<String, Object>)


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

def create_segment(segment_create_query, opts = {})
  data, _status_code, _headers = create_segment_with_http_info(segment_create_query, opts)
  data
end

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

Create Segment Create a segment.&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;100/d&#x60; Scopes: &#x60;segments:write&#x60;

Parameters:

  • segment_create_query (SegmentCreateQuery)
  • 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/segments_api.rb', line 36

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

  # 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-04-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(segment_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 => :"SegmentsApi.create_segment",
    :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: SegmentsApi#create_segment\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

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

Delete Segment Delete a segment with the given segment ID.
*Rate limits*:
Burst: ‘3/s`
Steady: `60/m` Scopes: `segments:write`

Parameters:

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

    the optional parameters

Returns:

  • (nil)


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

def delete_segment(id, opts = {})
  delete_segment_with_http_info(id, opts)
  nil
end

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

Delete Segment Delete a segment with the given segment 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;segments:write&#x60;

Parameters:

  • id (String)
  • 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/segments_api.rb', line 106

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

#get_flows_triggered_by_segment(id, opts = {}) ⇒ Hash<String, Object> Also known as: get_flow_triggers_for_segment, get_segment_flow_triggers

Get Flows Triggered by Segment Get all flows where the given segment ID is being used as the trigger.
*Rate limits*:
Burst: ‘3/s`
Steady: `60/m` Scopes: `flows:read` `segments:read`

Parameters:

  • id (String)

    Primary key that uniquely identifies this segment. Generated by Klaviyo.

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

    the optional parameters

Options Hash (opts):

Returns:

  • (Hash<String, Object>)


162
163
164
165
# File 'lib/klaviyo-api-sdk/api/segments_api.rb', line 162

def get_flows_triggered_by_segment(id, opts = {})
  data, _status_code, _headers = get_flows_triggered_by_segment_with_http_info(id, opts)
  data
end

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

Get Flows Triggered by Segment Get all flows where the given segment ID is being used as the trigger.&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;flows:read&#x60; &#x60;segments:read&#x60;

Parameters:

  • id (String)

    Primary key that uniquely identifies this segment. Generated by Klaviyo.

  • 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



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

def get_flows_triggered_by_segment_with_http_info(id, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: SegmentsApi.get_flows_triggered_by_segment ...'
  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 SegmentsApi.get_flows_triggered_by_segment"
  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/segments/{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-04-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 => :"SegmentsApi.get_flows_triggered_by_segment",
    :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: SegmentsApi#get_flows_triggered_by_segment\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#get_ids_for_flows_triggered_by_segment(id, opts = {}) ⇒ Hash<String, Object> Also known as: get_flow_trigger_ids_for_segment, get_segment_relationships_flow_triggers

Get IDs for Flows Triggered by Segment Get the IDs of all flows where the given segment is being used as the trigger.
*Rate limits*:
Burst: ‘3/s`
Steady: `60/m` Scopes: `flows:read` `segments:read`

Parameters:

  • id (String)

    Primary key that uniquely identifies this segment. Generated by Klaviyo.

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

    the optional parameters

Returns:

  • (Hash<String, Object>)


245
246
247
248
# File 'lib/klaviyo-api-sdk/api/segments_api.rb', line 245

def get_ids_for_flows_triggered_by_segment(id, opts = {})
  data, _status_code, _headers = get_ids_for_flows_triggered_by_segment_with_http_info(id, opts)
  data
end

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

Get IDs for Flows Triggered by Segment Get the IDs of all flows where the given segment is being used as the trigger.&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;flows:read&#x60; &#x60;segments:read&#x60;

Parameters:

  • id (String)

    Primary key that uniquely identifies this segment. Generated by Klaviyo.

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

    the optional parameters

Returns:

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

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



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

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

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

Get Profile IDs for Segment Get all profile membership [relationships](developers.klaviyo.com/en/reference/api_overview#relationships) for the given segment ID.
*Rate limits*:
Burst: ‘75/s`
Steady: `700/m` Scopes: `profiles:read` `segments:read`

Parameters:

  • id (String)

    Primary key that uniquely identifies this segment. Generated by Klaviyo.

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

    the optional parameters

Options Hash (opts):

Returns:

  • (Hash<String, Object>)


326
327
328
329
# File 'lib/klaviyo-api-sdk/api/segments_api.rb', line 326

def get_profile_ids_for_segment(id, opts = {})
  data, _status_code, _headers = get_profile_ids_for_segment_with_http_info(id, opts)
  data
end

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

Get Profile IDs for Segment Get all profile membership [relationships](developers.klaviyo.com/en/reference/api_overview#relationships) for the given segment ID.&lt;br&gt;&lt;br&gt;*Rate limits*:&lt;br&gt;Burst: &#x60;75/s&#x60;&lt;br&gt;Steady: &#x60;700/m&#x60; Scopes: &#x60;profiles:read&#x60; &#x60;segments:read&#x60;

Parameters:

  • id (String)

    Primary key that uniquely identifies this segment. Generated by Klaviyo.

  • 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



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
397
398
399
400
401
402
403
404
405
406
407
# File 'lib/klaviyo-api-sdk/api/segments_api.rb', line 343

def get_profile_ids_for_segment_with_http_info(id, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: SegmentsApi.get_profile_ids_for_segment ...'
  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 SegmentsApi.get_profile_ids_for_segment"
  end
  if @api_client.config.client_side_validation && !opts[:'page_size'].nil? && opts[:'page_size'] > 100
    fail ArgumentError, 'invalid value for "opts[:"page_size"]" when calling SegmentsApi.get_profile_ids_for_segment, must be smaller than or equal to 100.'
  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 SegmentsApi.get_profile_ids_for_segment, must be greater than or equal to 1.'
  end

  allowable_values = ["joined_group_at", "-joined_group_at"]
  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/segments/{id}/relationships/profiles'.sub('{' + 'id' + '}', CGI.escape(id.to_s))

  # query parameters
  query_params = opts[:query_params] || {}
  query_params[:'filter'] = opts[:'filter'] if !opts[:'filter'].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'] || "2025-04-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 => :"SegmentsApi.get_profile_ids_for_segment",
    :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: SegmentsApi#get_profile_ids_for_segment\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

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

Get Profiles for Segment Get all profiles within a segment with the given segment ID. Filter to request a subset of all profiles. Profiles can be filtered by ‘email`, `phone_number`, `push_token`, and `joined_group_at` fields. Profiles can be sorted by the following fields, in ascending and descending order: `joined_group_at`
*Rate limits*:
Burst: `75/s`
Steady: `700/m` Scopes: `profiles:read` `segments:read`

Parameters:

  • id (String)

    Primary key that uniquely identifies this segment. Generated by Klaviyo.

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

    the optional parameters

Options Hash (opts):

Returns:

  • (Hash<String, Object>)


423
424
425
426
# File 'lib/klaviyo-api-sdk/api/segments_api.rb', line 423

def get_profiles_for_segment(id, opts = {})
  data, _status_code, _headers = get_profiles_for_segment_with_http_info(id, opts)
  data
end

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

Get Profiles for Segment Get all profiles within a segment with the given segment ID. Filter to request a subset of all profiles. Profiles can be filtered by &#x60;email&#x60;, &#x60;phone_number&#x60;, &#x60;push_token&#x60;, and &#x60;joined_group_at&#x60; fields. Profiles can be sorted by the following fields, in ascending and descending order: &#x60;joined_group_at&#x60;&lt;br&gt;&lt;br&gt;*Rate limits*:&lt;br&gt;Burst: &#x60;75/s&#x60;&lt;br&gt;Steady: &#x60;700/m&#x60; Scopes: &#x60;profiles:read&#x60; &#x60;segments:read&#x60;

Parameters:

  • id (String)

    Primary key that uniquely identifies this segment. Generated by Klaviyo.

  • 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



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

def get_profiles_for_segment_with_http_info(id, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: SegmentsApi.get_profiles_for_segment ...'
  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 SegmentsApi.get_profiles_for_segment"
  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 = ["email", "phone_number", "external_id", "first_name", "last_name", "organization", "locale", "title", "image", "created", "updated", "last_event_date", "location", "location.address1", "location.address2", "location.city", "location.country", "location.latitude", "location.longitude", "location.region", "location.zip", "location.timezone", "location.ip", "properties", "joined_group_at", "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.last_updated", "subscriptions.email.marketing.method", "subscriptions.email.marketing.method_detail", "subscriptions.email.marketing.custom_method_detail", "subscriptions.email.marketing.double_optin", "subscriptions.email.marketing.suppression", "subscriptions.email.marketing.list_suppressions", "subscriptions.sms", "subscriptions.sms.marketing", "subscriptions.sms.marketing.can_receive_sms_marketing", "subscriptions.sms.marketing.consent", "subscriptions.sms.marketing.consent_timestamp", "subscriptions.sms.marketing.method", "subscriptions.sms.marketing.method_detail", "subscriptions.sms.marketing.last_updated", "subscriptions.sms.transactional", "subscriptions.sms.transactional.can_receive_sms_transactional", "subscriptions.sms.transactional.consent", "subscriptions.sms.transactional.consent_timestamp", "subscriptions.sms.transactional.method", "subscriptions.sms.transactional.method_detail", "subscriptions.sms.transactional.last_updated", "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", "predictive_analytics", "predictive_analytics.historic_clv", "predictive_analytics.predicted_clv", "predictive_analytics.total_clv", "predictive_analytics.historic_number_of_orders", "predictive_analytics.predicted_number_of_orders", "predictive_analytics.average_days_between_orders", "predictive_analytics.average_order_value", "predictive_analytics.churn_probability", "predictive_analytics.expected_date_of_next_order"]
  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
  if @api_client.config.client_side_validation && !opts[:'page_size'].nil? && opts[:'page_size'] > 100
    fail ArgumentError, 'invalid value for "opts[:"page_size"]" when calling SegmentsApi.get_profiles_for_segment, must be smaller than or equal to 100.'
  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 SegmentsApi.get_profiles_for_segment, must be greater than or equal to 1.'
  end

  allowable_values = ["joined_group_at", "-joined_group_at"]
  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/segments/{id}/profiles'.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?
  query_params[:'filter'] = opts[:'filter'] if !opts[:'filter'].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'] || "2025-04-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 => :"SegmentsApi.get_profiles_for_segment",
    :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: SegmentsApi#get_profiles_for_segment\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

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

Get Segment Get a segment with the given segment ID.
*Rate limits*:
Burst: ‘75/s`
Steady: `700/m`
Rate limits when using the `additional-fields=profile_count` parameter in your API request:
Burst: `1/s`
Steady: `15/m`
To learn more about how the `additional-fields` parameter impacts rate limits, check out our [Rate limits, status codes, and errors](developers.klaviyo.com/en/v2025-04-15/docs/rate_limits_and_error_handling) guide. Scopes: `segments:read`

Parameters:

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

    the optional parameters

Options Hash (opts):

Returns:

  • (Hash<String, Object>)


531
532
533
534
# File 'lib/klaviyo-api-sdk/api/segments_api.rb', line 531

def get_segment(id, opts = {})
  data, _status_code, _headers = get_segment_with_http_info(id, opts)
  data
end

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

Get Segment Get a segment with the given segment ID.&lt;br&gt;&lt;br&gt;*Rate limits*:&lt;br&gt;Burst: &#x60;75/s&#x60;&lt;br&gt;Steady: &#x60;700/m&#x60;&lt;br&gt;&lt;br&gt;Rate limits when using the &#x60;additional-fields&#x3D;profile_count&#x60; parameter in your API request:&lt;br&gt;Burst: &#x60;1/s&#x60;&lt;br&gt;Steady: &#x60;15/m&#x60;&lt;br&gt;&lt;br&gt;To learn more about how the &#x60;additional-fields&#x60; parameter impacts rate limits, check out our [Rate limits, status codes, and errors](developers.klaviyo.com/en/v2025-04-15/docs/rate_limits_and_error_handling) guide. Scopes: &#x60;segments: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



546
547
548
549
550
551
552
553
554
555
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
615
616
617
618
619
# File 'lib/klaviyo-api-sdk/api/segments_api.rb', line 546

def get_segment_with_http_info(id, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: SegmentsApi.get_segment ...'
  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 SegmentsApi.get_segment"
  end
  allowable_values = ["profile_count"]
  if @api_client.config.client_side_validation && opts[:'additional_fields_segment'] && !opts[:'additional_fields_segment'].all? { |item| allowable_values.include?(item) }
    fail ArgumentError, "invalid value for \"additional_fields_segment\", must include one of #{allowable_values}"
  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", "definition", "definition.condition_groups", "created", "updated", "is_active", "is_processing", "is_starred", "profile_count"]
  if @api_client.config.client_side_validation && opts[:'fields_segment'] && !opts[:'fields_segment'].all? { |item| allowable_values.include?(item) }
    fail ArgumentError, "invalid value for \"fields_segment\", must include one of #{allowable_values}"
  end
  allowable_values = ["name"]
  if @api_client.config.client_side_validation && opts[:'fields_tag'] && !opts[:'fields_tag'].all? { |item| allowable_values.include?(item) }
    fail ArgumentError, "invalid value for \"fields_tag\", must include one of #{allowable_values}"
  end
  allowable_values = ["flow-triggers", "tags"]
  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/segments/{id}'.sub('{' + 'id' + '}', CGI.escape(id.to_s))

  # query parameters
  query_params = opts[:query_params] || {}
  query_params[:'additional-fields[segment]'] = @api_client.build_collection_param(opts[:'additional_fields_segment'], :csv) if !opts[:'additional_fields_segment'].nil?
  query_params[:'fields[flow]'] = @api_client.build_collection_param(opts[:'fields_flow'], :csv) if !opts[:'fields_flow'].nil?
  query_params[:'fields[segment]'] = @api_client.build_collection_param(opts[:'fields_segment'], :csv) if !opts[:'fields_segment'].nil?
  query_params[:'fields[tag]'] = @api_client.build_collection_param(opts[:'fields_tag'], :csv) if !opts[:'fields_tag'].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-04-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 => :"SegmentsApi.get_segment",
    :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: SegmentsApi#get_segment\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

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

Get Segments Get all segments in an account. Filter to request a subset of all segments. Segments can be filtered by ‘name`, `created`, and `updated` fields. Returns a maximum of 10 results per page.
*Rate limits*:
Burst: `75/s`
Steady: `700/m` Scopes: `segments:read`

Parameters:

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

    the optional parameters

Options Hash (opts):

Returns:

  • (Hash<String, Object>)


632
633
634
635
# File 'lib/klaviyo-api-sdk/api/segments_api.rb', line 632

def get_segments(opts = {})
  data, _status_code, _headers = get_segments_with_http_info(opts)
  data
end

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

Get Segments Get all segments in an account. Filter to request a subset of all segments. Segments can be filtered by &#x60;name&#x60;, &#x60;created&#x60;, and &#x60;updated&#x60; fields. Returns a maximum of 10 results per page.&lt;br&gt;&lt;br&gt;*Rate limits*:&lt;br&gt;Burst: &#x60;75/s&#x60;&lt;br&gt;Steady: &#x60;700/m&#x60; Scopes: &#x60;segments: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



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

def get_segments_with_http_info(opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: SegmentsApi.get_segments ...'
  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", "definition", "definition.condition_groups", "created", "updated", "is_active", "is_processing", "is_starred"]
  if @api_client.config.client_side_validation && opts[:'fields_segment'] && !opts[:'fields_segment'].all? { |item| allowable_values.include?(item) }
    fail ArgumentError, "invalid value for \"fields_segment\", must include one of #{allowable_values}"
  end
  allowable_values = ["name"]
  if @api_client.config.client_side_validation && opts[:'fields_tag'] && !opts[:'fields_tag'].all? { |item| allowable_values.include?(item) }
    fail ArgumentError, "invalid value for \"fields_tag\", must include one of #{allowable_values}"
  end
  allowable_values = ["flow-triggers", "tags"]
  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
  allowable_values = ["created", "-created", "id", "-id", "name", "-name", "updated", "-updated"]
  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/segments'

  # 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[segment]'] = @api_client.build_collection_param(opts[:'fields_segment'], :csv) if !opts[:'fields_segment'].nil?
  query_params[:'fields[tag]'] = @api_client.build_collection_param(opts[:'fields_tag'], :csv) if !opts[:'fields_tag'].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[:'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'] || "2025-04-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 => :"SegmentsApi.get_segments",
    :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: SegmentsApi#get_segments\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

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

Get Tag IDs for Segment If ‘related_resource` is `tags`, returns the tag IDs of all tags associated with the given segment ID.
*Rate limits*:
Burst: `3/s`
Steady: `60/m` Scopes: `segments:read` `tags:read`

Parameters:

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

    the optional parameters

Returns:

  • (Hash<String, Object>)


726
727
728
729
# File 'lib/klaviyo-api-sdk/api/segments_api.rb', line 726

def get_tag_ids_for_segment(id, opts = {})
  data, _status_code, _headers = get_tag_ids_for_segment_with_http_info(id, opts)
  data
end

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

Get Tag IDs for Segment If &#x60;related_resource&#x60; is &#x60;tags&#x60;, returns the tag IDs of all tags associated with the given segment 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;segments:read&#x60; &#x60;tags: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



739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
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
# File 'lib/klaviyo-api-sdk/api/segments_api.rb', line 739

def get_tag_ids_for_segment_with_http_info(id, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: SegmentsApi.get_tag_ids_for_segment ...'
  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 SegmentsApi.get_tag_ids_for_segment"
  end
  # resource path
  local_var_path = '/api/segments/{id}/relationships/tags'.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-04-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 => :"SegmentsApi.get_tag_ids_for_segment",
    :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: SegmentsApi#get_tag_ids_for_segment\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

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

Get Tags for Segment Return all tags associated with the given segment ID.
*Rate limits*:
Burst: ‘3/s`
Steady: `60/m` Scopes: `segments:read` `tags:read`

Parameters:

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

    the optional parameters

Options Hash (opts):

Returns:

  • (Hash<String, Object>)


798
799
800
801
# File 'lib/klaviyo-api-sdk/api/segments_api.rb', line 798

def get_tags_for_segment(id, opts = {})
  data, _status_code, _headers = get_tags_for_segment_with_http_info(id, opts)
  data
end

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

Get Tags for Segment Return all tags associated with the given segment 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;segments:read&#x60; &#x60;tags: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



812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
# File 'lib/klaviyo-api-sdk/api/segments_api.rb', line 812

def get_tags_for_segment_with_http_info(id, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: SegmentsApi.get_tags_for_segment ...'
  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 SegmentsApi.get_tags_for_segment"
  end
  allowable_values = ["name"]
  if @api_client.config.client_side_validation && opts[:'fields_tag'] && !opts[:'fields_tag'].all? { |item| allowable_values.include?(item) }
    fail ArgumentError, "invalid value for \"fields_tag\", must include one of #{allowable_values}"
  end
  # resource path
  local_var_path = '/api/segments/{id}/tags'.sub('{' + 'id' + '}', CGI.escape(id.to_s))

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

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

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

Update Segment Update a segment with the given segment ID.
*Rate limits*:
Burst: ‘1/s`
Steady: `15/m`
Daily: `100/d` Scopes: `segments:write`

Parameters:

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

    the optional parameters

Returns:

  • (Hash<String, Object>)


876
877
878
879
# File 'lib/klaviyo-api-sdk/api/segments_api.rb', line 876

def update_segment(id, segment_partial_update_query, opts = {})
  data, _status_code, _headers = update_segment_with_http_info(id, segment_partial_update_query, opts)
  data
end

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

Update Segment Update a segment with the given segment 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;100/d&#x60; Scopes: &#x60;segments:write&#x60;

Parameters:

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

    the optional parameters

Returns:

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

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



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
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
# File 'lib/klaviyo-api-sdk/api/segments_api.rb', line 887

def update_segment_with_http_info(id, segment_partial_update_query, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: SegmentsApi.update_segment ...'
  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 SegmentsApi.update_segment"
  end
  # verify the required parameter 'segment_partial_update_query' is set
  if @api_client.config.client_side_validation && segment_partial_update_query.nil?
    fail ArgumentError, "Missing the required parameter 'segment_partial_update_query' when calling SegmentsApi.update_segment"
  end
  # resource path
  local_var_path = '/api/segments/{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-04-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(segment_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 => :"SegmentsApi.update_segment",
    :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: SegmentsApi#update_segment\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end