=begin
#Klaviyo API
#The Klaviyo REST API. Please visit https://developers.klaviyo.com for more details.
The version of the OpenAPI document: 2022-10-17
Contact: developers@klaviyo.com
Generated by: https://openapi-generator.tech
OpenAPI Generator version: 6.0.1
=end
require 'cgi'
module KlaviyoAPI
class ListsApi
attr_accessor :api_client
def initialize(api_client = ApiClient.default)
@api_client = api_client
end
# Create List
# Create a new list.
*Rate limits*:
Burst: `10/s`
Steady: `150/m` **Scopes:** `List Write`
# @param list_create_query [ListCreateQuery]
# @param [Hash] opts the optional parameters
# @return [Hash]
def create_list(list_create_query, opts = {})
data, _status_code, _headers = create_list_with_http_info(list_create_query, opts)
data
end
# Create List
# Create a new list.<br><br>*Rate limits*:<br>Burst: `10/s`<br>Steady: `150/m` **Scopes:** `List Write`
# @param list_create_query [ListCreateQuery]
# @param [Hash] opts the optional parameters
# @return [Array<(Hash, Integer, Hash)>] Hash data, response status code and response headers
def create_list_with_http_info(list_create_query, opts = {})
if @api_client.config.debugging
@api_client.config.logger.debug 'Calling API: ListsApi.create_list ...'
end
# verify the required parameter 'list_create_query' is set
if @api_client.config.client_side_validation && list_create_query.nil?
fail ArgumentError, "Missing the required parameter 'list_create_query' when calling ListsApi.create_list"
end
# resource path
local_var_path = '/api/lists/'
# query parameters
query_params = opts[:query_params] || {}
# header parameters
header_params = opts[:header_params] || {}
# klaviyo api revision
header_params['revision'] = ENV['API_REVISION'] || "2022-10-17"
# HTTP header 'Accept' (if needed)
header_params['Accept'] = @api_client.select_header_accept(['application/json'])
# HTTP header 'Content-Type'
content_type = @api_client.select_header_content_type(['application/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(list_create_query)
# return_type
return_type = opts[:debug_return_type] || 'Hash'
# auth_names
auth_names = opts[:debug_auth_names] || ['Klaviyo-API-Key']
new_options = opts.merge(
:operation => :"ListsApi.create_list",
: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: ListsApi#create_list\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
end
return data, status_code, headers
end
# Add Profile to List
# Add a profile to a list with the given list ID.
*Rate limits*:
Burst: `10/s`
Steady: `150/m` **Scopes:** `List Write` `Profiles Write`
# @param id [String]
# @param related_resource [String]
# @param list_members_add_query [ListMembersAddQuery]
# @param [Hash] opts the optional parameters
# @return [nil]
def create_list_relationships(id, related_resource, list_members_add_query, opts = {})
create_list_relationships_with_http_info(id, related_resource, list_members_add_query, opts)
nil
end
# Add Profile to List
# Add a profile to a list with the given list ID.<br><br>*Rate limits*:<br>Burst: `10/s`<br>Steady: `150/m` **Scopes:** `List Write` `Profiles Write`
# @param id [String]
# @param related_resource [String]
# @param list_members_add_query [ListMembersAddQuery]
# @param [Hash] opts the optional parameters
# @return [Array<(nil, Integer, Hash)>] nil, response status code and response headers
def create_list_relationships_with_http_info(id, related_resource, list_members_add_query, opts = {})
if @api_client.config.debugging
@api_client.config.logger.debug 'Calling API: ListsApi.create_list_relationships ...'
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 ListsApi.create_list_relationships"
end
# verify the required parameter 'related_resource' is set
if @api_client.config.client_side_validation && related_resource.nil?
fail ArgumentError, "Missing the required parameter 'related_resource' when calling ListsApi.create_list_relationships"
end
# verify enum value
allowable_values = ["profiles"]
if @api_client.config.client_side_validation && !allowable_values.include?(related_resource)
fail ArgumentError, "invalid value for \"related_resource\", must be one of #{allowable_values}"
end
# verify the required parameter 'list_members_add_query' is set
if @api_client.config.client_side_validation && list_members_add_query.nil?
fail ArgumentError, "Missing the required parameter 'list_members_add_query' when calling ListsApi.create_list_relationships"
end
# resource path
local_var_path = '/api/lists/{id}/relationships/{related_resource}/'.sub('{' + 'id' + '}', CGI.escape(id.to_s)).sub('{' + 'related_resource' + '}', CGI.escape(related_resource.to_s))
# query parameters
query_params = opts[:query_params] || {}
# header parameters
header_params = opts[:header_params] || {}
# klaviyo api revision
header_params['revision'] = ENV['API_REVISION'] || "2022-10-17"
# HTTP header 'Accept' (if needed)
header_params['Accept'] = @api_client.select_header_accept(['application/json'])
# HTTP header 'Content-Type'
content_type = @api_client.select_header_content_type(['application/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(list_members_add_query)
# return_type
return_type = opts[:debug_return_type]
# auth_names
auth_names = opts[:debug_auth_names] || ['Klaviyo-API-Key']
new_options = opts.merge(
:operation => :"ListsApi.create_list_relationships",
: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: ListsApi#create_list_relationships\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
end
return data, status_code, headers
end
# Delete List
# Delete a list with the given list ID.
*Rate limits*:
Burst: `10/s`
Steady: `150/m` **Scopes:** `List Write`
# @param id [String]
# @param [Hash] opts the optional parameters
# @return [nil]
def delete_list(id, opts = {})
delete_list_with_http_info(id, opts)
nil
end
# Delete List
# Delete a list with the given list ID.<br><br>*Rate limits*:<br>Burst: `10/s`<br>Steady: `150/m` **Scopes:** `List Write`
# @param id [String]
# @param [Hash] opts the optional parameters
# @return [Array<(nil, Integer, Hash)>] nil, response status code and response headers
def delete_list_with_http_info(id, opts = {})
if @api_client.config.debugging
@api_client.config.logger.debug 'Calling API: ListsApi.delete_list ...'
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 ListsApi.delete_list"
end
# resource path
local_var_path = '/api/lists/{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['API_REVISION'] || "2022-10-17"
# HTTP header 'Accept' (if needed)
header_params['Accept'] = @api_client.select_header_accept(['application/json'])
# form parameters
form_params = opts[:form_params] || {}
# http body (model)
post_body = opts[:debug_body]
# return_type
return_type = opts[:debug_return_type]
# auth_names
auth_names = opts[:debug_auth_names] || ['Klaviyo-API-Key']
new_options = opts.merge(
:operation => :"ListsApi.delete_list",
: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: ListsApi#delete_list\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
end
return data, status_code, headers
end
# Remove Profile from List
# Remove a profile from a list with the given list ID.
*Rate limits*:
Burst: `10/s`
Steady: `150/m` **Scopes:** `List Write` `Profiles Write`
# @param id [String]
# @param related_resource [String]
# @param list_members_delete_query [ListMembersDeleteQuery]
# @param [Hash] opts the optional parameters
# @return [nil]
def delete_list_relationships(id, related_resource, list_members_delete_query, opts = {})
delete_list_relationships_with_http_info(id, related_resource, list_members_delete_query, opts)
nil
end
# Remove Profile from List
# Remove a profile from a list with the given list ID.<br><br>*Rate limits*:<br>Burst: `10/s`<br>Steady: `150/m` **Scopes:** `List Write` `Profiles Write`
# @param id [String]
# @param related_resource [String]
# @param list_members_delete_query [ListMembersDeleteQuery]
# @param [Hash] opts the optional parameters
# @return [Array<(nil, Integer, Hash)>] nil, response status code and response headers
def delete_list_relationships_with_http_info(id, related_resource, list_members_delete_query, opts = {})
if @api_client.config.debugging
@api_client.config.logger.debug 'Calling API: ListsApi.delete_list_relationships ...'
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 ListsApi.delete_list_relationships"
end
# verify the required parameter 'related_resource' is set
if @api_client.config.client_side_validation && related_resource.nil?
fail ArgumentError, "Missing the required parameter 'related_resource' when calling ListsApi.delete_list_relationships"
end
# verify enum value
allowable_values = ["profiles"]
if @api_client.config.client_side_validation && !allowable_values.include?(related_resource)
fail ArgumentError, "invalid value for \"related_resource\", must be one of #{allowable_values}"
end
# verify the required parameter 'list_members_delete_query' is set
if @api_client.config.client_side_validation && list_members_delete_query.nil?
fail ArgumentError, "Missing the required parameter 'list_members_delete_query' when calling ListsApi.delete_list_relationships"
end
# resource path
local_var_path = '/api/lists/{id}/relationships/{related_resource}/'.sub('{' + 'id' + '}', CGI.escape(id.to_s)).sub('{' + 'related_resource' + '}', CGI.escape(related_resource.to_s))
# query parameters
query_params = opts[:query_params] || {}
# header parameters
header_params = opts[:header_params] || {}
# klaviyo api revision
header_params['revision'] = ENV['API_REVISION'] || "2022-10-17"
# HTTP header 'Accept' (if needed)
header_params['Accept'] = @api_client.select_header_accept(['application/json'])
# HTTP header 'Content-Type'
content_type = @api_client.select_header_content_type(['application/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(list_members_delete_query)
# return_type
return_type = opts[:debug_return_type]
# auth_names
auth_names = opts[:debug_auth_names] || ['Klaviyo-API-Key']
new_options = opts.merge(
:operation => :"ListsApi.delete_list_relationships",
: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: ListsApi#delete_list_relationships\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
end
return data, status_code, headers
end
# Get List
# Get a list with the given list ID.
*Rate limits*:
Burst: `10/s`
Steady: `150/m` **Scopes:** `List Write`
# @param id [String]
# @param [Hash] opts the optional parameters
# @option opts [Array] :fields_list For more information please visit https://developers.klaviyo.com/en/v2022-10-17/reference/api-overview#sparse-fieldsets
# @return [Hash]
def get_list(id, opts = {})
data, _status_code, _headers = get_list_with_http_info(id, opts)
data
end
# Get List
# Get a list with the given list ID.<br><br>*Rate limits*:<br>Burst: `10/s`<br>Steady: `150/m` **Scopes:** `List Write`
# @param id [String]
# @param [Hash] opts the optional parameters
# @option opts [Array] :fields_list For more information please visit https://developers.klaviyo.com/en/v2022-10-17/reference/api-overview#sparse-fieldsets
# @return [Array<(Hash, Integer, Hash)>] Hash data, response status code and response headers
def get_list_with_http_info(id, opts = {})
if @api_client.config.debugging
@api_client.config.logger.debug 'Calling API: ListsApi.get_list ...'
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 ListsApi.get_list"
end
allowable_values = ["name", "created", "updated"]
if @api_client.config.client_side_validation && opts[:'fields_list'] && !opts[:'fields_list'].all? { |item| allowable_values.include?(item) }
fail ArgumentError, "invalid value for \"fields_list\", must include one of #{allowable_values}"
end
# resource path
local_var_path = '/api/lists/{id}/'.sub('{' + 'id' + '}', CGI.escape(id.to_s))
# query parameters
query_params = opts[:query_params] || {}
query_params[:'fields[list]'] = @api_client.build_collection_param(opts[:'fields_list'], :csv) if !opts[:'fields_list'].nil?
# header parameters
header_params = opts[:header_params] || {}
# klaviyo api revision
header_params['revision'] = ENV['API_REVISION'] || "2022-10-17"
# HTTP header 'Accept' (if needed)
header_params['Accept'] = @api_client.select_header_accept(['application/json'])
# form parameters
form_params = opts[:form_params] || {}
# http body (model)
post_body = opts[:debug_body]
# return_type
return_type = opts[:debug_return_type] || 'Hash'
# auth_names
auth_names = opts[:debug_auth_names] || ['Klaviyo-API-Key']
new_options = opts.merge(
:operation => :"ListsApi.get_list",
: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: ListsApi#get_list\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
end
return data, status_code, headers
end
# Get List Profiles
# Get all profiles within a list with the given list ID. Use filters to narrow your results. Returns a maximum of 10 results per page, which can be paginated with [cursor-based pagination](https://developers.klaviyo.com/en/v2022-10-17/reference/api_overview#pagination).
*Rate limits*:
Burst: `10/s`
Steady: `150/m` **Scopes:** `List Read` `Profiles Read`
# @param list_id [String]
# @param [Hash] opts the optional parameters
# @option opts [Array] :fields_profile For more information please visit https://developers.klaviyo.com/en/v2022-10-17/reference/api-overview#sparse-fieldsets
# @option opts [String] :filter For more information please visit https://developers.klaviyo.com/en/v2022-10-17/reference/api-overview#filtering<br>Allowed field(s)/operator(s):<br>`email`: `any`<br>`phone_number`: `any`<br>`push_token`: `any`<br>`_kx`: `equals`
# @option opts [String] :page_cursor For more information please visit https://developers.klaviyo.com/en/v2022-10-17/reference/api-overview#pagination
# @return [Hash]
def get_list_profiles(list_id, opts = {})
data, _status_code, _headers = get_list_profiles_with_http_info(list_id, opts)
data
end
# Get List Profiles
# Get all profiles within a list with the given list ID. Use filters to narrow your results. Returns a maximum of 10 results per page, which can be paginated with [cursor-based pagination](https://developers.klaviyo.com/en/v2022-10-17/reference/api_overview#pagination).<br><br>*Rate limits*:<br>Burst: `10/s`<br>Steady: `150/m` **Scopes:** `List Read` `Profiles Read`
# @param list_id [String]
# @param [Hash] opts the optional parameters
# @option opts [Array] :fields_profile For more information please visit https://developers.klaviyo.com/en/v2022-10-17/reference/api-overview#sparse-fieldsets
# @option opts [String] :filter For more information please visit https://developers.klaviyo.com/en/v2022-10-17/reference/api-overview#filtering<br>Allowed field(s)/operator(s):<br>`email`: `any`<br>`phone_number`: `any`<br>`push_token`: `any`<br>`_kx`: `equals`
# @option opts [String] :page_cursor For more information please visit https://developers.klaviyo.com/en/v2022-10-17/reference/api-overview#pagination
# @return [Array<(Hash, Integer, Hash)>] Hash data, response status code and response headers
def get_list_profiles_with_http_info(list_id, opts = {})
if @api_client.config.debugging
@api_client.config.logger.debug 'Calling API: ListsApi.get_list_profiles ...'
end
# verify the required parameter 'list_id' is set
if @api_client.config.client_side_validation && list_id.nil?
fail ArgumentError, "Missing the required parameter 'list_id' when calling ListsApi.get_list_profiles"
end
allowable_values = ["email", "phone_number", "external_id", "anonymous_id", "first_name", "last_name", "organization", "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", "properties"]
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/lists/{list_id}/profiles/'.sub('{' + 'list_id' + '}', CGI.escape(list_id.to_s))
# query parameters
query_params = opts[:query_params] || {}
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?
# header parameters
header_params = opts[:header_params] || {}
# klaviyo api revision
header_params['revision'] = ENV['API_REVISION'] || "2022-10-17"
# HTTP header 'Accept' (if needed)
header_params['Accept'] = @api_client.select_header_accept(['application/json'])
# form parameters
form_params = opts[:form_params] || {}
# http body (model)
post_body = opts[:debug_body]
# return_type
return_type = opts[:debug_return_type] || 'Hash'
# auth_names
auth_names = opts[:debug_auth_names] || ['Klaviyo-API-Key']
new_options = opts.merge(
:operation => :"ListsApi.get_list_profiles",
: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: ListsApi#get_list_profiles\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
end
return data, status_code, headers
end
# Get List Profile Relationships
# Get profile membership [relationships](https://developers.klaviyo.com/en/v2022-10-17/reference/api_overview#relationships) for a list with the given list ID. Returns a maximum of 10 results per page, which can be paginated with [cursor-based pagination](https://developers.klaviyo.com/en/v2022-10-17/reference/api_overview#pagination).
*Rate limits*:
Burst: `10/s`
Steady: `150/m` **Scopes:** `List Read` `Profiles Read`
# @param id [String]
# @param related_resource [String]
# @param [Hash] opts the optional parameters
# @option opts [String] :page_cursor For more information please visit https://developers.klaviyo.com/en/v2022-10-17/reference/api-overview#pagination
# @return [Hash]
def get_list_relationships(id, related_resource, opts = {})
data, _status_code, _headers = get_list_relationships_with_http_info(id, related_resource, opts)
data
end
# Get List Profile Relationships
# Get profile membership [relationships](https://developers.klaviyo.com/en/v2022-10-17/reference/api_overview#relationships) for a list with the given list ID. Returns a maximum of 10 results per page, which can be paginated with [cursor-based pagination](https://developers.klaviyo.com/en/v2022-10-17/reference/api_overview#pagination).<br><br>*Rate limits*:<br>Burst: `10/s`<br>Steady: `150/m` **Scopes:** `List Read` `Profiles Read`
# @param id [String]
# @param related_resource [String]
# @param [Hash] opts the optional parameters
# @option opts [String] :page_cursor For more information please visit https://developers.klaviyo.com/en/v2022-10-17/reference/api-overview#pagination
# @return [Array<(Hash, Integer, Hash)>] Hash data, response status code and response headers
def get_list_relationships_with_http_info(id, related_resource, opts = {})
if @api_client.config.debugging
@api_client.config.logger.debug 'Calling API: ListsApi.get_list_relationships ...'
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 ListsApi.get_list_relationships"
end
# verify the required parameter 'related_resource' is set
if @api_client.config.client_side_validation && related_resource.nil?
fail ArgumentError, "Missing the required parameter 'related_resource' when calling ListsApi.get_list_relationships"
end
# verify enum value
allowable_values = ["profiles"]
if @api_client.config.client_side_validation && !allowable_values.include?(related_resource)
fail ArgumentError, "invalid value for \"related_resource\", must be one of #{allowable_values}"
end
# resource path
local_var_path = '/api/lists/{id}/relationships/{related_resource}/'.sub('{' + 'id' + '}', CGI.escape(id.to_s)).sub('{' + 'related_resource' + '}', CGI.escape(related_resource.to_s))
# query parameters
query_params = opts[:query_params] || {}
query_params[:'page[cursor]'] = opts[:'page_cursor'] if !opts[:'page_cursor'].nil?
# header parameters
header_params = opts[:header_params] || {}
# klaviyo api revision
header_params['revision'] = ENV['API_REVISION'] || "2022-10-17"
# HTTP header 'Accept' (if needed)
header_params['Accept'] = @api_client.select_header_accept(['application/json'])
# form parameters
form_params = opts[:form_params] || {}
# http body (model)
post_body = opts[:debug_body]
# return_type
return_type = opts[:debug_return_type] || 'Hash'
# auth_names
auth_names = opts[:debug_auth_names] || ['Klaviyo-API-Key']
new_options = opts.merge(
:operation => :"ListsApi.get_list_relationships",
: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: ListsApi#get_list_relationships\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
end
return data, status_code, headers
end
# Get Lists
# Get all lists in an account. Use filters to narrow your results. Returns a maximum of 10 results per page, which can be paginated with [cursor-based pagination](https://developers.klaviyo.com/en/v2022-10-17/reference/api_overview#pagination).
*Rate limits*:
Burst: `10/s`
Steady: `150/m` **Scopes:** `List Read`
# @param [Hash] opts the optional parameters
# @option opts [Array] :fields_list For more information please visit https://developers.klaviyo.com/en/v2022-10-17/reference/api-overview#sparse-fieldsets
# @option opts [String] :filter For more information please visit https://developers.klaviyo.com/en/v2022-10-17/reference/api-overview#filtering<br>Allowed field(s)/operator(s):<br>`name`: `any`, `equals`<br>`created`: `greater-than`<br>`updated`: `greater-than`
# @option opts [String] :page_cursor For more information please visit https://developers.klaviyo.com/en/v2022-10-17/reference/api-overview#pagination
# @return [Hash]
def get_lists(opts = {})
data, _status_code, _headers = get_lists_with_http_info(opts)
data
end
# Get Lists
# Get all lists in an account. Use filters to narrow your results. Returns a maximum of 10 results per page, which can be paginated with [cursor-based pagination](https://developers.klaviyo.com/en/v2022-10-17/reference/api_overview#pagination).<br><br>*Rate limits*:<br>Burst: `10/s`<br>Steady: `150/m` **Scopes:** `List Read`
# @param [Hash] opts the optional parameters
# @option opts [Array] :fields_list For more information please visit https://developers.klaviyo.com/en/v2022-10-17/reference/api-overview#sparse-fieldsets
# @option opts [String] :filter For more information please visit https://developers.klaviyo.com/en/v2022-10-17/reference/api-overview#filtering<br>Allowed field(s)/operator(s):<br>`name`: `any`, `equals`<br>`created`: `greater-than`<br>`updated`: `greater-than`
# @option opts [String] :page_cursor For more information please visit https://developers.klaviyo.com/en/v2022-10-17/reference/api-overview#pagination
# @return [Array<(Hash, Integer, Hash)>] Hash data, response status code and response headers
def get_lists_with_http_info(opts = {})
if @api_client.config.debugging
@api_client.config.logger.debug 'Calling API: ListsApi.get_lists ...'
end
allowable_values = ["name", "created", "updated"]
if @api_client.config.client_side_validation && opts[:'fields_list'] && !opts[:'fields_list'].all? { |item| allowable_values.include?(item) }
fail ArgumentError, "invalid value for \"fields_list\", must include one of #{allowable_values}"
end
# resource path
local_var_path = '/api/lists/'
# query parameters
query_params = opts[:query_params] || {}
query_params[:'fields[list]'] = @api_client.build_collection_param(opts[:'fields_list'], :csv) if !opts[:'fields_list'].nil?
query_params[:'filter'] = opts[:'filter'] if !opts[:'filter'].nil?
query_params[:'page[cursor]'] = opts[:'page_cursor'] if !opts[:'page_cursor'].nil?
# header parameters
header_params = opts[:header_params] || {}
# klaviyo api revision
header_params['revision'] = ENV['API_REVISION'] || "2022-10-17"
# HTTP header 'Accept' (if needed)
header_params['Accept'] = @api_client.select_header_accept(['application/json'])
# form parameters
form_params = opts[:form_params] || {}
# http body (model)
post_body = opts[:debug_body]
# return_type
return_type = opts[:debug_return_type] || 'Hash'
# auth_names
auth_names = opts[:debug_auth_names] || ['Klaviyo-API-Key']
new_options = opts.merge(
:operation => :"ListsApi.get_lists",
: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: ListsApi#get_lists\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
end
return data, status_code, headers
end
# Update List
# Update the name of a list with the given list ID.
*Rate limits*:
Burst: `10/s`
Steady: `150/m` **Scopes:** `List Write`
# @param id [String]
# @param list_partial_update_query [ListPartialUpdateQuery]
# @param [Hash] opts the optional parameters
# @return [Hash]
def update_list(id, list_partial_update_query, opts = {})
data, _status_code, _headers = update_list_with_http_info(id, list_partial_update_query, opts)
data
end
# Update List
# Update the name of a list with the given list ID.<br><br>*Rate limits*:<br>Burst: `10/s`<br>Steady: `150/m` **Scopes:** `List Write`
# @param id [String]
# @param list_partial_update_query [ListPartialUpdateQuery]
# @param [Hash] opts the optional parameters
# @return [Array<(Hash, Integer, Hash)>] Hash data, response status code and response headers
def update_list_with_http_info(id, list_partial_update_query, opts = {})
if @api_client.config.debugging
@api_client.config.logger.debug 'Calling API: ListsApi.update_list ...'
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 ListsApi.update_list"
end
# verify the required parameter 'list_partial_update_query' is set
if @api_client.config.client_side_validation && list_partial_update_query.nil?
fail ArgumentError, "Missing the required parameter 'list_partial_update_query' when calling ListsApi.update_list"
end
# resource path
local_var_path = '/api/lists/{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['API_REVISION'] || "2022-10-17"
# HTTP header 'Accept' (if needed)
header_params['Accept'] = @api_client.select_header_accept(['application/json'])
# HTTP header 'Content-Type'
content_type = @api_client.select_header_content_type(['application/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(list_partial_update_query)
# return_type
return_type = opts[:debug_return_type] || 'Hash'
# auth_names
auth_names = opts[:debug_auth_names] || ['Klaviyo-API-Key']
new_options = opts.merge(
:operation => :"ListsApi.update_list",
: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: ListsApi#update_list\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
end
return data, status_code, headers
end
end
end