# KlaviyoAPI::SegmentsApi All URIs are relative to *https://a.klaviyo.com* | Method | HTTP request | Description | | ------ | ------------ | ----------- | | [**get_segment**](SegmentsApi.md#get_segment) | **GET** /api/segments/{id}/ | Get Segment | | [**get_segment_profiles**](SegmentsApi.md#get_segment_profiles) | **GET** /api/segments/{segment_id}/profiles/ | Get Segment Profiles | | [**get_segment_relationships**](SegmentsApi.md#get_segment_relationships) | **GET** /api/segments/{id}/relationships/{related_resource}/ | Get Segment Relationships | | [**get_segment_tags**](SegmentsApi.md#get_segment_tags) | **GET** /api/segments/{segment_id}/tags/ | Get Segment Tags | | [**get_segments**](SegmentsApi.md#get_segments) | **GET** /api/segments/ | Get Segments | | [**update_segment**](SegmentsApi.md#update_segment) | **PATCH** /api/segments/{id}/ | Update Segment | ## get_segment > Hash<String, Object> get_segment(id, opts) Get Segment Get a segment with the given segment ID.

*Rate limits*:
Burst: `10/s`
Steady: `150/m` **Scopes:** `Segments Read` ### Examples ```ruby require 'time' require 'klaviyo-api-sdk' # setup authorization KlaviyoAPI.configure do |config| # Configure API key authorization: Klaviyo-API-Key config.api_key['Klaviyo-API-Key'] = 'YOUR API KEY' # Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil) # config.api_key_prefix['Klaviyo-API-Key'] = 'Bearer' end api_instance = KlaviyoAPI::SegmentsApi.new id = 'id_example' # String | opts = { fields_segment: ['name'] # Array | For more information please visit https://developers.klaviyo.com/en/v2023-02-22/reference/api-overview#sparse-fieldsets } begin # Get Segment result = api_instance.get_segment(id, opts) p result rescue KlaviyoAPI::ApiError => e puts "Error when calling SegmentsApi->get_segment: #{e}" end ``` #### Using the get_segment_with_http_info variant This returns an Array which contains the response data, status code and headers. > get_segment_with_http_info(id, opts) ```ruby begin # Get Segment data, status_code, headers = api_instance.get_segment_with_http_info(id, opts) p status_code # => 2xx p headers # => { ... } p data # => Hash<String, Object> rescue KlaviyoAPI::ApiError => e puts "Error when calling SegmentsApi->get_segment_with_http_info: #{e}" end ``` ### Parameters | Name | Type | Description | Notes | | ---- | ---- | ----------- | ----- | | **id** | **String** | | | | **fields_segment** | [**Array<String>**](String.md) | For more information please visit https://developers.klaviyo.com/en/v2023-02-22/reference/api-overview#sparse-fieldsets | [optional] | ### Return type **Hash<String, Object>** ### Authorization [Klaviyo-API-Key](../README.md#Klaviyo-API-Key) ### HTTP request headers - **Content-Type**: Not defined - **Accept**: application/json ## get_segment_profiles > Hash<String, Object> get_segment_profiles(segment_id, opts) Get Segment Profiles Get all profiles within the given segment ID. Filter to request a subset of all profiles. Profiles can be filtered by `email`, `phone_number`, and `push_token` fields. You can adjust the number of results per page via the `page[size]` query parameter, e.g. `?page[size]=25`. **Default**: 20. **Max**: 100.

*Rate limits*:
Burst: `10/s`
Steady: `150/m` **Scopes:** `Profiles Read` `Segments Read` ### Examples ```ruby require 'time' require 'klaviyo-api-sdk' # setup authorization KlaviyoAPI.configure do |config| # Configure API key authorization: Klaviyo-API-Key config.api_key['Klaviyo-API-Key'] = 'YOUR API KEY' # Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil) # config.api_key_prefix['Klaviyo-API-Key'] = 'Bearer' end api_instance = KlaviyoAPI::SegmentsApi.new segment_id = 'segment_id_example' # String | opts = { fields_profile: ['email'], # Array | For more information please visit https://developers.klaviyo.com/en/v2023-02-22/reference/api-overview#sparse-fieldsets filter: 'filter_example', # String | For more information please visit https://developers.klaviyo.com/en/v2023-02-22/reference/api-overview#filtering
Allowed field(s)/operator(s):
`email`: `any`
`phone_number`: `any`
`push_token`: `any`
`_kx`: `equals` page_cursor: 'page_cursor_example' # String | For more information please visit https://developers.klaviyo.com/en/v2023-02-22/reference/api-overview#pagination } begin # Get Segment Profiles result = api_instance.get_segment_profiles(segment_id, opts) p result rescue KlaviyoAPI::ApiError => e puts "Error when calling SegmentsApi->get_segment_profiles: #{e}" end ``` #### Using the get_segment_profiles_with_http_info variant This returns an Array which contains the response data, status code and headers. > get_segment_profiles_with_http_info(segment_id, opts) ```ruby begin # Get Segment Profiles data, status_code, headers = api_instance.get_segment_profiles_with_http_info(segment_id, opts) p status_code # => 2xx p headers # => { ... } p data # => Hash<String, Object> rescue KlaviyoAPI::ApiError => e puts "Error when calling SegmentsApi->get_segment_profiles_with_http_info: #{e}" end ``` ### Parameters | Name | Type | Description | Notes | | ---- | ---- | ----------- | ----- | | **segment_id** | **String** | | | | **fields_profile** | [**Array<String>**](String.md) | For more information please visit https://developers.klaviyo.com/en/v2023-02-22/reference/api-overview#sparse-fieldsets | [optional] | | **filter** | **String** | For more information please visit https://developers.klaviyo.com/en/v2023-02-22/reference/api-overview#filtering<br>Allowed field(s)/operator(s):<br>`email`: `any`<br>`phone_number`: `any`<br>`push_token`: `any`<br>`_kx`: `equals` | [optional] | | **page_cursor** | **String** | For more information please visit https://developers.klaviyo.com/en/v2023-02-22/reference/api-overview#pagination | [optional] | ### Return type **Hash<String, Object>** ### Authorization [Klaviyo-API-Key](../README.md#Klaviyo-API-Key) ### HTTP request headers - **Content-Type**: Not defined - **Accept**: application/json ## get_segment_relationships > Hash<String, Object> get_segment_relationships(id, related_resource, opts) Get Segment Relationships Get all profile membership [relationships](https://developers.klaviyo.com/en/reference/api_overview#relationships) for the given segment ID. You can adjust the number of results per page via the `page[size]` query parameter, e.g. `?page[size]=25`. **Default**: 20. **Max**: 100.

*Rate limits*:
Burst: `10/s`
Steady: `150/m` **Scopes:** `Profiles Read` `Segments Read` ### Examples ```ruby require 'time' require 'klaviyo-api-sdk' # setup authorization KlaviyoAPI.configure do |config| # Configure API key authorization: Klaviyo-API-Key config.api_key['Klaviyo-API-Key'] = 'YOUR API KEY' # Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil) # config.api_key_prefix['Klaviyo-API-Key'] = 'Bearer' end api_instance = KlaviyoAPI::SegmentsApi.new id = 'id_example' # String | related_resource = 'profiles' # String | opts = { page_cursor: 'page_cursor_example' # String | For more information please visit https://developers.klaviyo.com/en/v2023-02-22/reference/api-overview#pagination } begin # Get Segment Relationships result = api_instance.get_segment_relationships(id, related_resource, opts) p result rescue KlaviyoAPI::ApiError => e puts "Error when calling SegmentsApi->get_segment_relationships: #{e}" end ``` #### Using the get_segment_relationships_with_http_info variant This returns an Array which contains the response data, status code and headers. > get_segment_relationships_with_http_info(id, related_resource, opts) ```ruby begin # Get Segment Relationships data, status_code, headers = api_instance.get_segment_relationships_with_http_info(id, related_resource, opts) p status_code # => 2xx p headers # => { ... } p data # => Hash<String, Object> rescue KlaviyoAPI::ApiError => e puts "Error when calling SegmentsApi->get_segment_relationships_with_http_info: #{e}" end ``` ### Parameters | Name | Type | Description | Notes | | ---- | ---- | ----------- | ----- | | **id** | **String** | | | | **related_resource** | **String** | | | | **page_cursor** | **String** | For more information please visit https://developers.klaviyo.com/en/v2023-02-22/reference/api-overview#pagination | [optional] | ### Return type **Hash<String, Object>** ### Authorization [Klaviyo-API-Key](../README.md#Klaviyo-API-Key) ### HTTP request headers - **Content-Type**: Not defined - **Accept**: application/json ## get_segment_tags > Hash<String, Object> get_segment_tags(segment_id, opts) Get Segment Tags Return all tags associated with the given segment ID.

*Rate limits*:
Burst: `3/s`
Steady: `60/m` **Scopes:** `Segments Read` `Tags Read` ### Examples ```ruby require 'time' require 'klaviyo-api-sdk' # setup authorization KlaviyoAPI.configure do |config| # Configure API key authorization: Klaviyo-API-Key config.api_key['Klaviyo-API-Key'] = 'YOUR API KEY' # Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil) # config.api_key_prefix['Klaviyo-API-Key'] = 'Bearer' end api_instance = KlaviyoAPI::SegmentsApi.new segment_id = 'segment_id_example' # String | opts = { fields_tag: ['name'] # Array | For more information please visit https://developers.klaviyo.com/en/v2023-02-22/reference/api-overview#sparse-fieldsets } begin # Get Segment Tags result = api_instance.get_segment_tags(segment_id, opts) p result rescue KlaviyoAPI::ApiError => e puts "Error when calling SegmentsApi->get_segment_tags: #{e}" end ``` #### Using the get_segment_tags_with_http_info variant This returns an Array which contains the response data, status code and headers. > get_segment_tags_with_http_info(segment_id, opts) ```ruby begin # Get Segment Tags data, status_code, headers = api_instance.get_segment_tags_with_http_info(segment_id, opts) p status_code # => 2xx p headers # => { ... } p data # => Hash<String, Object> rescue KlaviyoAPI::ApiError => e puts "Error when calling SegmentsApi->get_segment_tags_with_http_info: #{e}" end ``` ### Parameters | Name | Type | Description | Notes | | ---- | ---- | ----------- | ----- | | **segment_id** | **String** | | | | **fields_tag** | [**Array<String>**](String.md) | For more information please visit https://developers.klaviyo.com/en/v2023-02-22/reference/api-overview#sparse-fieldsets | [optional] | ### Return type **Hash<String, Object>** ### Authorization [Klaviyo-API-Key](../README.md#Klaviyo-API-Key) ### HTTP request headers - **Content-Type**: Not defined - **Accept**: application/json ## get_segments > Hash<String, Object> get_segments(opts) 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: `10/s`
Steady: `150/m` **Scopes:** `Segments Read` ### Examples ```ruby require 'time' require 'klaviyo-api-sdk' # setup authorization KlaviyoAPI.configure do |config| # Configure API key authorization: Klaviyo-API-Key config.api_key['Klaviyo-API-Key'] = 'YOUR API KEY' # Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil) # config.api_key_prefix['Klaviyo-API-Key'] = 'Bearer' end api_instance = KlaviyoAPI::SegmentsApi.new opts = { fields_segment: ['name'], # Array | For more information please visit https://developers.klaviyo.com/en/v2023-02-22/reference/api-overview#sparse-fieldsets filter: 'filter_example', # String | For more information please visit https://developers.klaviyo.com/en/v2023-02-22/reference/api-overview#filtering
Allowed field(s)/operator(s):
`name`: `any`, `equals`
`id`: `any`, `equals`
`created`: `greater-than`
`updated`: `greater-than` page_cursor: 'page_cursor_example' # String | For more information please visit https://developers.klaviyo.com/en/v2023-02-22/reference/api-overview#pagination } begin # Get Segments result = api_instance.get_segments(opts) p result rescue KlaviyoAPI::ApiError => e puts "Error when calling SegmentsApi->get_segments: #{e}" end ``` #### Using the get_segments_with_http_info variant This returns an Array which contains the response data, status code and headers. > get_segments_with_http_info(opts) ```ruby begin # Get Segments data, status_code, headers = api_instance.get_segments_with_http_info(opts) p status_code # => 2xx p headers # => { ... } p data # => Hash<String, Object> rescue KlaviyoAPI::ApiError => e puts "Error when calling SegmentsApi->get_segments_with_http_info: #{e}" end ``` ### Parameters | Name | Type | Description | Notes | | ---- | ---- | ----------- | ----- | | **fields_segment** | [**Array<String>**](String.md) | For more information please visit https://developers.klaviyo.com/en/v2023-02-22/reference/api-overview#sparse-fieldsets | [optional] | | **filter** | **String** | For more information please visit https://developers.klaviyo.com/en/v2023-02-22/reference/api-overview#filtering<br>Allowed field(s)/operator(s):<br>`name`: `any`, `equals`<br>`id`: `any`, `equals`<br>`created`: `greater-than`<br>`updated`: `greater-than` | [optional] | | **page_cursor** | **String** | For more information please visit https://developers.klaviyo.com/en/v2023-02-22/reference/api-overview#pagination | [optional] | ### Return type **Hash<String, Object>** ### Authorization [Klaviyo-API-Key](../README.md#Klaviyo-API-Key) ### HTTP request headers - **Content-Type**: Not defined - **Accept**: application/json ## update_segment > Hash<String, Object> update_segment(id, segment_partial_update_query) Update Segment Update the name of a segment with the given segment ID.

*Rate limits*:
Burst: `10/s`
Steady: `150/m` **Scopes:** `Segments Write` ### Examples ```ruby require 'time' require 'klaviyo-api-sdk' # setup authorization KlaviyoAPI.configure do |config| # Configure API key authorization: Klaviyo-API-Key config.api_key['Klaviyo-API-Key'] = 'YOUR API KEY' # Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil) # config.api_key_prefix['Klaviyo-API-Key'] = 'Bearer' end api_instance = KlaviyoAPI::SegmentsApi.new id = 'id_example' # String | segment_partial_update_query = KlaviyoAPI::SegmentPartialUpdateQuery.new({data: KlaviyoAPI::SegmentPartialUpdateQueryAsSubResource.new({type: 'segment', id: 'id_example', attributes: KlaviyoAPI::SegmentPartialUpdateQueryAsSubResourceAttributes.new({name: 'name_example'})})}) # SegmentPartialUpdateQuery | begin # Update Segment result = api_instance.update_segment(id, segment_partial_update_query) p result rescue KlaviyoAPI::ApiError => e puts "Error when calling SegmentsApi->update_segment: #{e}" end ``` #### Using the update_segment_with_http_info variant This returns an Array which contains the response data, status code and headers. > update_segment_with_http_info(id, segment_partial_update_query) ```ruby begin # Update Segment data, status_code, headers = api_instance.update_segment_with_http_info(id, segment_partial_update_query) p status_code # => 2xx p headers # => { ... } p data # => Hash<String, Object> rescue KlaviyoAPI::ApiError => e puts "Error when calling SegmentsApi->update_segment_with_http_info: #{e}" end ``` ### Parameters | Name | Type | Description | Notes | | ---- | ---- | ----------- | ----- | | **id** | **String** | | | | **segment_partial_update_query** | [**SegmentPartialUpdateQuery**](SegmentPartialUpdateQuery.md) | | | ### Return type **Hash<String, Object>** ### Authorization [Klaviyo-API-Key](../README.md#Klaviyo-API-Key) ### HTTP request headers - **Content-Type**: application/json - **Accept**: application/json