# 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/{id}/profiles/ | Get Segment Profiles |
| [**get_segment_relationships_profiles**](SegmentsApi.md#get_segment_relationships_profiles) | **GET** /api/segments/{id}/relationships/profiles/ | Get Segment Relationships Profiles |
| [**get_segment_relationships_tags**](SegmentsApi.md#get_segment_relationships_tags) | **GET** /api/segments/{id}/relationships/tags/ | Get Segment Relationships Tags |
| [**get_segment_tags**](SegmentsApi.md#get_segment_tags) | **GET** /api/segments/{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: `75/s`
Steady: `700/m`
Rate limits when using the `additional-fields[segment]=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](https://developers.klaviyo.com/en/v2023-12-15/docs/rate_limits_and_error_handling) guide. **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 = {
additional_fields_segment: ['profile_count'], # Array | Request additional fields not included by default in the response. Supported values: 'profile_count'
fields_segment: ['name'], # Array | For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#sparse-fieldsets
fields_tag: ['name'], # Array | For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#sparse-fieldsets
include: ['tags'] # Array | For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#relationships
}
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** | | |
| **additional_fields_segment** | [**Array<String>**](String.md) | Request additional fields not included by default in the response. Supported values: 'profile_count' | [optional] |
| **fields_segment** | [**Array<String>**](String.md) | For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#sparse-fieldsets | [optional] |
| **fields_tag** | [**Array<String>**](String.md) | For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#sparse-fieldsets | [optional] |
| **include** | [**Array<String>**](String.md) | For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#relationships | [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(id, opts)
Get Segment Profiles
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`
### 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 = {
additional_fields_profile: ['subscriptions'], # Array | Request additional fields not included by default in the response. Supported values: 'subscriptions', 'predictive_analytics'
fields_profile: ['email'], # Array | For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#sparse-fieldsets
filter: 'filter_example', # String | For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#filtering
Allowed field(s)/operator(s):
`email`: `any`, `equals`
`phone_number`: `any`, `equals`
`push_token`: `any`, `equals`
`_kx`: `equals`
`joined_group_at`: `greater-or-equal`, `greater-than`, `less-or-equal`, `less-than`
page_cursor: 'page_cursor_example', # String | For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#pagination
page_size: 56, # Integer | Default: 20. Min: 1. Max: 100.
sort: 'joined_group_at' # String | For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#sorting
}
begin
# Get Segment Profiles
result = api_instance.get_segment_profiles(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(id, opts)
```ruby
begin
# Get Segment Profiles
data, status_code, headers = api_instance.get_segment_profiles_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_profiles_with_http_info: #{e}"
end
```
### Parameters
| Name | Type | Description | Notes |
| ---- | ---- | ----------- | ----- |
| **id** | **String** | | |
| **additional_fields_profile** | [**Array<String>**](String.md) | Request additional fields not included by default in the response. Supported values: 'subscriptions', 'predictive_analytics' | [optional] |
| **fields_profile** | [**Array<String>**](String.md) | For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#sparse-fieldsets | [optional] |
| **filter** | **String** | For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#filtering<br>Allowed field(s)/operator(s):<br>`email`: `any`, `equals`<br>`phone_number`: `any`, `equals`<br>`push_token`: `any`, `equals`<br>`_kx`: `equals`<br>`joined_group_at`: `greater-or-equal`, `greater-than`, `less-or-equal`, `less-than` | [optional] |
| **page_cursor** | **String** | For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#pagination | [optional] |
| **page_size** | **Integer** | Default: 20. Min: 1. Max: 100. | [optional][default to 20] |
| **sort** | **String** | For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#sorting | [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_profiles
> Hash<String, Object> get_segment_relationships_profiles(id, opts)
Get Segment Relationships Profiles
Get all profile membership [relationships](https://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`
### 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 = {
filter: 'filter_example', # String | For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#filtering
Allowed field(s)/operator(s):
`email`: `any`, `equals`
`phone_number`: `any`, `equals`
`push_token`: `any`, `equals`
`_kx`: `equals`
`joined_group_at`: `greater-or-equal`, `greater-than`, `less-or-equal`, `less-than`
page_cursor: 'page_cursor_example', # String | For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#pagination
page_size: 56, # Integer | Default: 20. Min: 1. Max: 1000.
sort: 'joined_group_at' # String | For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#sorting
}
begin
# Get Segment Relationships Profiles
result = api_instance.get_segment_relationships_profiles(id, opts)
p result
rescue KlaviyoAPI::ApiError => e
puts "Error when calling SegmentsApi->get_segment_relationships_profiles: #{e}"
end
```
#### Using the get_segment_relationships_profiles_with_http_info variant
This returns an Array which contains the response data, status code and headers.
> get_segment_relationships_profiles_with_http_info(id, opts)
```ruby
begin
# Get Segment Relationships Profiles
data, status_code, headers = api_instance.get_segment_relationships_profiles_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_relationships_profiles_with_http_info: #{e}"
end
```
### Parameters
| Name | Type | Description | Notes |
| ---- | ---- | ----------- | ----- |
| **id** | **String** | | |
| **filter** | **String** | For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#filtering<br>Allowed field(s)/operator(s):<br>`email`: `any`, `equals`<br>`phone_number`: `any`, `equals`<br>`push_token`: `any`, `equals`<br>`_kx`: `equals`<br>`joined_group_at`: `greater-or-equal`, `greater-than`, `less-or-equal`, `less-than` | [optional] |
| **page_cursor** | **String** | For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#pagination | [optional] |
| **page_size** | **Integer** | Default: 20. Min: 1. Max: 1000. | [optional][default to 20] |
| **sort** | **String** | For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#sorting | [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_tags
> Hash<String, Object> get_segment_relationships_tags(id)
Get Segment Relationships Tags
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`
### 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 |
begin
# Get Segment Relationships Tags
result = api_instance.get_segment_relationships_tags(id)
p result
rescue KlaviyoAPI::ApiError => e
puts "Error when calling SegmentsApi->get_segment_relationships_tags: #{e}"
end
```
#### Using the get_segment_relationships_tags_with_http_info variant
This returns an Array which contains the response data, status code and headers.
> get_segment_relationships_tags_with_http_info(id)
```ruby
begin
# Get Segment Relationships Tags
data, status_code, headers = api_instance.get_segment_relationships_tags_with_http_info(id)
p status_code # => 2xx
p headers # => { ... }
p data # => Hash<String, Object>
rescue KlaviyoAPI::ApiError => e
puts "Error when calling SegmentsApi->get_segment_relationships_tags_with_http_info: #{e}"
end
```
### Parameters
| Name | Type | Description | Notes |
| ---- | ---- | ----------- | ----- |
| **id** | **String** | | |
### 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(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
id = 'id_example' # String |
opts = {
fields_tag: ['name'] # Array | For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#sparse-fieldsets
}
begin
# Get Segment Tags
result = api_instance.get_segment_tags(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(id, opts)
```ruby
begin
# Get Segment Tags
data, status_code, headers = api_instance.get_segment_tags_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_tags_with_http_info: #{e}"
end
```
### Parameters
| Name | Type | Description | Notes |
| ---- | ---- | ----------- | ----- |
| **id** | **String** | | |
| **fields_tag** | [**Array<String>**](String.md) | For more information please visit https://developers.klaviyo.com/en/v2023-12-15/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: `75/s`
Steady: `700/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-12-15/reference/api-overview#sparse-fieldsets
fields_tag: ['name'], # Array | For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#sparse-fieldsets
filter: 'filter_example', # String | For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#filtering
Allowed field(s)/operator(s):
`name`: `any`, `equals`
`id`: `any`, `equals`
`created`: `greater-than`
`updated`: `greater-than`
include: ['tags'], # Array | For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#relationships
page_cursor: 'page_cursor_example' # String | For more information please visit https://developers.klaviyo.com/en/v2023-12-15/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-12-15/reference/api-overview#sparse-fieldsets | [optional] |
| **fields_tag** | [**Array<String>**](String.md) | For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#sparse-fieldsets | [optional] |
| **filter** | **String** | For more information please visit https://developers.klaviyo.com/en/v2023-12-15/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] |
| **include** | [**Array<String>**](String.md) | For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#relationships | [optional] |
| **page_cursor** | **String** | For more information please visit https://developers.klaviyo.com/en/v2023-12-15/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::SegmentPartialUpdateQueryResourceObject.new({type: KlaviyoAPI::SegmentEnum::SEGMENT, id: 'id_example', attributes: KlaviyoAPI::SegmentPartialUpdateQueryResourceObjectAttributes.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