=begin
#Klaviyo API
#The Klaviyo REST API. Please visit https://developers.klaviyo.com for more details.
The version of the OpenAPI document: 2023-12-15
Contact: developers@klaviyo.com
Generated by: https://openapi-generator.tech
OpenAPI Generator version: 6.2.1
=end
require 'cgi'
module KlaviyoAPI
class CouponsApi
attr_accessor :api_client
def initialize(api_client = ApiClient.default)
@api_client = api_client
end
# Create Coupon
# Creates a new coupon.
*Rate limits*:
Burst: `3/s`
Steady: `60/m` **Scopes:** `coupons:write`
# @param coupon_create_query [CouponCreateQuery]
# @param [Hash] opts the optional parameters
# @return [Hash]
def create_coupon(coupon_create_query, opts = {})
data, _status_code, _headers = create_coupon_with_http_info(coupon_create_query, opts)
data
end
# Create Coupon
# Creates a new coupon.<br><br>*Rate limits*:<br>Burst: `3/s`<br>Steady: `60/m` **Scopes:** `coupons:write`
# @param coupon_create_query [CouponCreateQuery]
# @param [Hash] opts the optional parameters
# @return [Array<(Hash, Integer, Hash)>] Hash data, response status code and response headers
def create_coupon_with_http_info(coupon_create_query, opts = {})
if @api_client.config.debugging
@api_client.config.logger.debug 'Calling API: CouponsApi.create_coupon ...'
end
# verify the required parameter 'coupon_create_query' is set
if @api_client.config.client_side_validation && coupon_create_query.nil?
fail ArgumentError, "Missing the required parameter 'coupon_create_query' when calling CouponsApi.create_coupon"
end
# resource path
local_var_path = '/api/coupons/'
# query parameters
query_params = opts[:query_params] || {}
# header parameters
header_params = opts[:header_params] || {}
# klaviyo api revision
header_params['revision'] = ENV['API_REVISION'] || "2023-12-15"
# 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(coupon_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 => :"CouponsApi.create_coupon",
: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: CouponsApi#create_coupon\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
end
return data, status_code, headers
end
# Create Coupon Code
# Synchronously creates a coupon code for the given coupon.
*Rate limits*:
Burst: `350/s`
Steady: `3500/m` **Scopes:** `coupon-codes:write`
# @param coupon_code_create_query [CouponCodeCreateQuery]
# @param [Hash] opts the optional parameters
# @return [Hash]
def create_coupon_code(coupon_code_create_query, opts = {})
data, _status_code, _headers = create_coupon_code_with_http_info(coupon_code_create_query, opts)
data
end
# Create Coupon Code
# Synchronously creates a coupon code for the given coupon.<br><br>*Rate limits*:<br>Burst: `350/s`<br>Steady: `3500/m` **Scopes:** `coupon-codes:write`
# @param coupon_code_create_query [CouponCodeCreateQuery]
# @param [Hash] opts the optional parameters
# @return [Array<(Hash, Integer, Hash)>] Hash data, response status code and response headers
def create_coupon_code_with_http_info(coupon_code_create_query, opts = {})
if @api_client.config.debugging
@api_client.config.logger.debug 'Calling API: CouponsApi.create_coupon_code ...'
end
# verify the required parameter 'coupon_code_create_query' is set
if @api_client.config.client_side_validation && coupon_code_create_query.nil?
fail ArgumentError, "Missing the required parameter 'coupon_code_create_query' when calling CouponsApi.create_coupon_code"
end
# resource path
local_var_path = '/api/coupon-codes/'
# query parameters
query_params = opts[:query_params] || {}
# header parameters
header_params = opts[:header_params] || {}
# klaviyo api revision
header_params['revision'] = ENV['API_REVISION'] || "2023-12-15"
# 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(coupon_code_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 => :"CouponsApi.create_coupon_code",
: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: CouponsApi#create_coupon_code\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
end
return data, status_code, headers
end
# Delete Coupon
# Delete the coupon with the given coupon ID.
*Rate limits*:
Burst: `3/s`
Steady: `60/m` **Scopes:** `coupons:write`
# @param id [String] The internal id of a Coupon is equivalent to its external id stored within an integration.
# @param [Hash] opts the optional parameters
# @return [nil]
def delete_coupon(id, opts = {})
delete_coupon_with_http_info(id, opts)
nil
end
# Delete Coupon
# Delete the coupon with the given coupon ID.<br><br>*Rate limits*:<br>Burst: `3/s`<br>Steady: `60/m` **Scopes:** `coupons:write`
# @param id [String] The internal id of a Coupon is equivalent to its external id stored within an integration.
# @param [Hash] opts the optional parameters
# @return [Array<(nil, Integer, Hash)>] nil, response status code and response headers
def delete_coupon_with_http_info(id, opts = {})
if @api_client.config.debugging
@api_client.config.logger.debug 'Calling API: CouponsApi.delete_coupon ...'
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 CouponsApi.delete_coupon"
end
# resource path
local_var_path = '/api/coupons/{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'] || "2023-12-15"
# 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 => :"CouponsApi.delete_coupon",
: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: CouponsApi#delete_coupon\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
end
return data, status_code, headers
end
# Delete Coupon Code
# Deletes a coupon code specified by the given identifier synchronously. If a profile has been assigned to the coupon code, an exception will be raised
*Rate limits*:
Burst: `350/s`
Steady: `3500/m` **Scopes:** `coupon-codes:write`
# @param id [String] The id of a coupon code is a combination of its unique code and the id of the coupon it is associated with.
# @param [Hash] opts the optional parameters
# @return [nil]
def delete_coupon_code(id, opts = {})
delete_coupon_code_with_http_info(id, opts)
nil
end
# Delete Coupon Code
# Deletes a coupon code specified by the given identifier synchronously. If a profile has been assigned to the coupon code, an exception will be raised<br><br>*Rate limits*:<br>Burst: `350/s`<br>Steady: `3500/m` **Scopes:** `coupon-codes:write`
# @param id [String] The id of a coupon code is a combination of its unique code and the id of the coupon it is associated with.
# @param [Hash] opts the optional parameters
# @return [Array<(nil, Integer, Hash)>] nil, response status code and response headers
def delete_coupon_code_with_http_info(id, opts = {})
if @api_client.config.debugging
@api_client.config.logger.debug 'Calling API: CouponsApi.delete_coupon_code ...'
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 CouponsApi.delete_coupon_code"
end
# resource path
local_var_path = '/api/coupon-codes/{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'] || "2023-12-15"
# 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 => :"CouponsApi.delete_coupon_code",
: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: CouponsApi#delete_coupon_code\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
end
return data, status_code, headers
end
# Get Coupon
# Get a specific coupon with the given coupon ID.
*Rate limits*:
Burst: `75/s`
Steady: `700/m` **Scopes:** `coupons:read`
# @param id [String] The internal id of a Coupon is equivalent to its external id stored within an integration.
# @param [Hash] opts the optional parameters
# @option opts [Array] :fields_coupon For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#sparse-fieldsets
# @return [Hash]
def get_coupon(id, opts = {})
data, _status_code, _headers = get_coupon_with_http_info(id, opts)
data
end
# Get Coupon
# Get a specific coupon with the given coupon ID.<br><br>*Rate limits*:<br>Burst: `75/s`<br>Steady: `700/m` **Scopes:** `coupons:read`
# @param id [String] The internal id of a Coupon is equivalent to its external id stored within an integration.
# @param [Hash] opts the optional parameters
# @option opts [Array] :fields_coupon For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#sparse-fieldsets
# @return [Array<(Hash, Integer, Hash)>] Hash data, response status code and response headers
def get_coupon_with_http_info(id, opts = {})
if @api_client.config.debugging
@api_client.config.logger.debug 'Calling API: CouponsApi.get_coupon ...'
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 CouponsApi.get_coupon"
end
allowable_values = ["external_id", "description"]
if @api_client.config.client_side_validation && opts[:'fields_coupon'] && !opts[:'fields_coupon'].all? { |item| allowable_values.include?(item) }
fail ArgumentError, "invalid value for \"fields_coupon\", must include one of #{allowable_values}"
end
# resource path
local_var_path = '/api/coupons/{id}/'.sub('{' + 'id' + '}', CGI.escape(id.to_s))
# query parameters
query_params = opts[:query_params] || {}
query_params[:'fields[coupon]'] = @api_client.build_collection_param(opts[:'fields_coupon'], :csv) if !opts[:'fields_coupon'].nil?
# header parameters
header_params = opts[:header_params] || {}
# klaviyo api revision
header_params['revision'] = ENV['API_REVISION'] || "2023-12-15"
# 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 => :"CouponsApi.get_coupon",
: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: CouponsApi#get_coupon\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
end
return data, status_code, headers
end
# Get Coupon Code
# Returns a Coupon Code specified by the given identifier.
*Rate limits*:
Burst: `350/s`
Steady: `3500/m` **Scopes:** `coupon-codes:read`
# @param id [String] The id of a coupon code is a combination of its unique code and the id of the coupon it is associated with.
# @param [Hash] opts the optional parameters
# @option opts [Array] :fields_coupon_code For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#sparse-fieldsets
# @option opts [Array] :fields_coupon For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#sparse-fieldsets
# @option opts [Array] :include For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#relationships
# @return [Hash]
def get_coupon_code(id, opts = {})
data, _status_code, _headers = get_coupon_code_with_http_info(id, opts)
data
end
# Get Coupon Code
# Returns a Coupon Code specified by the given identifier.<br><br>*Rate limits*:<br>Burst: `350/s`<br>Steady: `3500/m` **Scopes:** `coupon-codes:read`
# @param id [String] The id of a coupon code is a combination of its unique code and the id of the coupon it is associated with.
# @param [Hash] opts the optional parameters
# @option opts [Array] :fields_coupon_code For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#sparse-fieldsets
# @option opts [Array] :fields_coupon For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#sparse-fieldsets
# @option opts [Array] :include For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#relationships
# @return [Array<(Hash, Integer, Hash)>] Hash data, response status code and response headers
def get_coupon_code_with_http_info(id, opts = {})
if @api_client.config.debugging
@api_client.config.logger.debug 'Calling API: CouponsApi.get_coupon_code ...'
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 CouponsApi.get_coupon_code"
end
allowable_values = ["unique_code", "expires_at", "status"]
if @api_client.config.client_side_validation && opts[:'fields_coupon_code'] && !opts[:'fields_coupon_code'].all? { |item| allowable_values.include?(item) }
fail ArgumentError, "invalid value for \"fields_coupon_code\", must include one of #{allowable_values}"
end
allowable_values = ["external_id", "description"]
if @api_client.config.client_side_validation && opts[:'fields_coupon'] && !opts[:'fields_coupon'].all? { |item| allowable_values.include?(item) }
fail ArgumentError, "invalid value for \"fields_coupon\", must include one of #{allowable_values}"
end
allowable_values = ["coupon"]
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/coupon-codes/{id}/'.sub('{' + 'id' + '}', CGI.escape(id.to_s))
# query parameters
query_params = opts[:query_params] || {}
query_params[:'fields[coupon-code]'] = @api_client.build_collection_param(opts[:'fields_coupon_code'], :csv) if !opts[:'fields_coupon_code'].nil?
query_params[:'fields[coupon]'] = @api_client.build_collection_param(opts[:'fields_coupon'], :csv) if !opts[:'fields_coupon'].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['API_REVISION'] || "2023-12-15"
# 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 => :"CouponsApi.get_coupon_code",
: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: CouponsApi#get_coupon_code\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
end
return data, status_code, headers
end
# Get Coupon Code Bulk Create Job
# Get a coupon code bulk create job with the given job ID.
*Rate limits*:
Burst: `75/s`
Steady: `700/m` **Scopes:** `coupon-codes:read`
# @param job_id [String] ID of the job to retrieve.
# @param [Hash] opts the optional parameters
# @option opts [Array] :fields_coupon_code_bulk_create_job For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#sparse-fieldsets
# @option opts [Array] :fields_coupon_code For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#sparse-fieldsets
# @option opts [Array] :include For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#relationships
# @return [Hash]
def get_coupon_code_bulk_create_job(job_id, opts = {})
data, _status_code, _headers = get_coupon_code_bulk_create_job_with_http_info(job_id, opts)
data
end
# Get Coupon Code Bulk Create Job
# Get a coupon code bulk create job with the given job ID.<br><br>*Rate limits*:<br>Burst: `75/s`<br>Steady: `700/m` **Scopes:** `coupon-codes:read`
# @param job_id [String] ID of the job to retrieve.
# @param [Hash] opts the optional parameters
# @option opts [Array] :fields_coupon_code_bulk_create_job For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#sparse-fieldsets
# @option opts [Array] :fields_coupon_code For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#sparse-fieldsets
# @option opts [Array] :include For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#relationships
# @return [Array<(Hash, Integer, Hash)>] Hash data, response status code and response headers
def get_coupon_code_bulk_create_job_with_http_info(job_id, opts = {})
if @api_client.config.debugging
@api_client.config.logger.debug 'Calling API: CouponsApi.get_coupon_code_bulk_create_job ...'
end
# verify the required parameter 'job_id' is set
if @api_client.config.client_side_validation && job_id.nil?
fail ArgumentError, "Missing the required parameter 'job_id' when calling CouponsApi.get_coupon_code_bulk_create_job"
end
allowable_values = ["status", "created_at", "total_count", "completed_count", "failed_count", "completed_at", "errors", "expires_at"]
if @api_client.config.client_side_validation && opts[:'fields_coupon_code_bulk_create_job'] && !opts[:'fields_coupon_code_bulk_create_job'].all? { |item| allowable_values.include?(item) }
fail ArgumentError, "invalid value for \"fields_coupon_code_bulk_create_job\", must include one of #{allowable_values}"
end
allowable_values = ["unique_code", "expires_at", "status"]
if @api_client.config.client_side_validation && opts[:'fields_coupon_code'] && !opts[:'fields_coupon_code'].all? { |item| allowable_values.include?(item) }
fail ArgumentError, "invalid value for \"fields_coupon_code\", must include one of #{allowable_values}"
end
allowable_values = ["coupon-codes"]
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/coupon-code-bulk-create-jobs/{job_id}/'.sub('{' + 'job_id' + '}', CGI.escape(job_id.to_s))
# query parameters
query_params = opts[:query_params] || {}
query_params[:'fields[coupon-code-bulk-create-job]'] = @api_client.build_collection_param(opts[:'fields_coupon_code_bulk_create_job'], :csv) if !opts[:'fields_coupon_code_bulk_create_job'].nil?
query_params[:'fields[coupon-code]'] = @api_client.build_collection_param(opts[:'fields_coupon_code'], :csv) if !opts[:'fields_coupon_code'].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['API_REVISION'] || "2023-12-15"
# 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 => :"CouponsApi.get_coupon_code_bulk_create_job",
: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: CouponsApi#get_coupon_code_bulk_create_job\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
end
return data, status_code, headers
end
# Get Coupon Code Bulk Create Jobs
# Get all coupon code bulk create jobs. Returns a maximum of 100 jobs per request.
*Rate limits*:
Burst: `75/s`
Steady: `700/m` **Scopes:** `coupon-codes:read`
# @param [Hash] opts the optional parameters
# @option opts [Array] :fields_coupon_code_bulk_create_job For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#sparse-fieldsets
# @option opts [String] :filter For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#filtering<br>Allowed field(s)/operator(s):<br>`status`: `equals`
# @option opts [String] :page_cursor For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#pagination
# @return [Hash]
def get_coupon_code_bulk_create_jobs(opts = {})
data, _status_code, _headers = get_coupon_code_bulk_create_jobs_with_http_info(opts)
data
end
# Get Coupon Code Bulk Create Jobs
# Get all coupon code bulk create jobs. Returns a maximum of 100 jobs per request.<br><br>*Rate limits*:<br>Burst: `75/s`<br>Steady: `700/m` **Scopes:** `coupon-codes:read`
# @param [Hash] opts the optional parameters
# @option opts [Array] :fields_coupon_code_bulk_create_job For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#sparse-fieldsets
# @option opts [String] :filter For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#filtering<br>Allowed field(s)/operator(s):<br>`status`: `equals`
# @option opts [String] :page_cursor For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#pagination
# @return [Array<(Hash, Integer, Hash)>] Hash data, response status code and response headers
def get_coupon_code_bulk_create_jobs_with_http_info(opts = {})
if @api_client.config.debugging
@api_client.config.logger.debug 'Calling API: CouponsApi.get_coupon_code_bulk_create_jobs ...'
end
allowable_values = ["status", "created_at", "total_count", "completed_count", "failed_count", "completed_at", "errors", "expires_at"]
if @api_client.config.client_side_validation && opts[:'fields_coupon_code_bulk_create_job'] && !opts[:'fields_coupon_code_bulk_create_job'].all? { |item| allowable_values.include?(item) }
fail ArgumentError, "invalid value for \"fields_coupon_code_bulk_create_job\", must include one of #{allowable_values}"
end
# resource path
local_var_path = '/api/coupon-code-bulk-create-jobs/'
# query parameters
query_params = opts[:query_params] || {}
query_params[:'fields[coupon-code-bulk-create-job]'] = @api_client.build_collection_param(opts[:'fields_coupon_code_bulk_create_job'], :csv) if !opts[:'fields_coupon_code_bulk_create_job'].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'] || "2023-12-15"
# 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 => :"CouponsApi.get_coupon_code_bulk_create_jobs",
: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: CouponsApi#get_coupon_code_bulk_create_jobs\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
end
return data, status_code, headers
end
# Get Coupon Code Relationships Coupon
# Gets a list of coupon code relationships associated with the given coupon id
*Rate limits*:
Burst: `75/s`
Steady: `700/m` **Scopes:** `coupon-codes:read`
# @param id [String]
# @param [Hash] opts the optional parameters
# @option opts [String] :page_cursor For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#pagination
# @return [Hash]
def get_coupon_code_relationships_coupon(id, opts = {})
data, _status_code, _headers = get_coupon_code_relationships_coupon_with_http_info(id, opts)
data
end
# Get Coupon Code Relationships Coupon
# Gets a list of coupon code relationships associated with the given coupon id<br><br>*Rate limits*:<br>Burst: `75/s`<br>Steady: `700/m` **Scopes:** `coupon-codes:read`
# @param id [String]
# @param [Hash] opts the optional parameters
# @option opts [String] :page_cursor For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#pagination
# @return [Array<(Hash, Integer, Hash)>] Hash data, response status code and response headers
def get_coupon_code_relationships_coupon_with_http_info(id, opts = {})
if @api_client.config.debugging
@api_client.config.logger.debug 'Calling API: CouponsApi.get_coupon_code_relationships_coupon ...'
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 CouponsApi.get_coupon_code_relationships_coupon"
end
# resource path
local_var_path = '/api/coupons/{id}/relationships/coupon-codes/'.sub('{' + 'id' + '}', CGI.escape(id.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'] || "2023-12-15"
# 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 => :"CouponsApi.get_coupon_code_relationships_coupon",
: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: CouponsApi#get_coupon_code_relationships_coupon\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
end
return data, status_code, headers
end
# Get Coupon Codes
# Gets a list of coupon codes associated with a coupon/coupons or a profile/profiles. A coupon/coupons or a profile/profiles must be provided as required filter params.
*Rate limits*:
Burst: `350/s`
Steady: `3500/m` **Scopes:** `coupon-codes:read`
# @param [Hash] opts the optional parameters
# @option opts [Array] :fields_coupon_code For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#sparse-fieldsets
# @option opts [Array] :fields_coupon For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#sparse-fieldsets
# @option opts [String] :filter For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#filtering<br>Allowed field(s)/operator(s):<br>`expires_at`: `greater-or-equal`, `greater-than`, `less-or-equal`, `less-than`<br>`status`: `equals`<br>`coupon.id`: `any`, `equals`<br>`profile.id`: `any`, `equals`
# @option opts [Array] :include For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#relationships
# @option opts [String] :page_cursor For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#pagination
# @return [Hash]
def get_coupon_codes(opts = {})
data, _status_code, _headers = get_coupon_codes_with_http_info(opts)
data
end
# Get Coupon Codes
# Gets a list of coupon codes associated with a coupon/coupons or a profile/profiles. A coupon/coupons or a profile/profiles must be provided as required filter params.<br><br>*Rate limits*:<br>Burst: `350/s`<br>Steady: `3500/m` **Scopes:** `coupon-codes:read`
# @param [Hash] opts the optional parameters
# @option opts [Array] :fields_coupon_code For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#sparse-fieldsets
# @option opts [Array] :fields_coupon For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#sparse-fieldsets
# @option opts [String] :filter For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#filtering<br>Allowed field(s)/operator(s):<br>`expires_at`: `greater-or-equal`, `greater-than`, `less-or-equal`, `less-than`<br>`status`: `equals`<br>`coupon.id`: `any`, `equals`<br>`profile.id`: `any`, `equals`
# @option opts [Array] :include For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#relationships
# @option opts [String] :page_cursor For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#pagination
# @return [Array<(Hash, Integer, Hash)>] Hash data, response status code and response headers
def get_coupon_codes_with_http_info(opts = {})
if @api_client.config.debugging
@api_client.config.logger.debug 'Calling API: CouponsApi.get_coupon_codes ...'
end
allowable_values = ["unique_code", "expires_at", "status"]
if @api_client.config.client_side_validation && opts[:'fields_coupon_code'] && !opts[:'fields_coupon_code'].all? { |item| allowable_values.include?(item) }
fail ArgumentError, "invalid value for \"fields_coupon_code\", must include one of #{allowable_values}"
end
allowable_values = ["external_id", "description"]
if @api_client.config.client_side_validation && opts[:'fields_coupon'] && !opts[:'fields_coupon'].all? { |item| allowable_values.include?(item) }
fail ArgumentError, "invalid value for \"fields_coupon\", must include one of #{allowable_values}"
end
allowable_values = ["coupon"]
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/coupon-codes/'
# query parameters
query_params = opts[:query_params] || {}
query_params[:'fields[coupon-code]'] = @api_client.build_collection_param(opts[:'fields_coupon_code'], :csv) if !opts[:'fields_coupon_code'].nil?
query_params[:'fields[coupon]'] = @api_client.build_collection_param(opts[:'fields_coupon'], :csv) if !opts[:'fields_coupon'].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?
# header parameters
header_params = opts[:header_params] || {}
# klaviyo api revision
header_params['revision'] = ENV['API_REVISION'] || "2023-12-15"
# 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 => :"CouponsApi.get_coupon_codes",
: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: CouponsApi#get_coupon_codes\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
end
return data, status_code, headers
end
# Get Coupon Codes For Coupon
# Gets a list of coupon codes associated with the given coupon id
*Rate limits*:
Burst: `75/s`
Steady: `700/m` **Scopes:** `coupon-codes:read`
# @param id [String]
# @param [Hash] opts the optional parameters
# @option opts [Array] :fields_coupon_code For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#sparse-fieldsets
# @option opts [String] :filter For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#filtering<br>Allowed field(s)/operator(s):<br>`expires_at`: `greater-or-equal`, `greater-than`, `less-or-equal`, `less-than`<br>`status`: `equals`<br>`coupon.id`: `any`, `equals`<br>`profile.id`: `any`, `equals`
# @option opts [String] :page_cursor For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#pagination
# @return [Hash]
def get_coupon_codes_for_coupon(id, opts = {})
data, _status_code, _headers = get_coupon_codes_for_coupon_with_http_info(id, opts)
data
end
# Get Coupon Codes For Coupon
# Gets a list of coupon codes associated with the given coupon id<br><br>*Rate limits*:<br>Burst: `75/s`<br>Steady: `700/m` **Scopes:** `coupon-codes:read`
# @param id [String]
# @param [Hash] opts the optional parameters
# @option opts [Array] :fields_coupon_code For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#sparse-fieldsets
# @option opts [String] :filter For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#filtering<br>Allowed field(s)/operator(s):<br>`expires_at`: `greater-or-equal`, `greater-than`, `less-or-equal`, `less-than`<br>`status`: `equals`<br>`coupon.id`: `any`, `equals`<br>`profile.id`: `any`, `equals`
# @option opts [String] :page_cursor For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#pagination
# @return [Array<(Hash, Integer, Hash)>] Hash data, response status code and response headers
def get_coupon_codes_for_coupon_with_http_info(id, opts = {})
if @api_client.config.debugging
@api_client.config.logger.debug 'Calling API: CouponsApi.get_coupon_codes_for_coupon ...'
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 CouponsApi.get_coupon_codes_for_coupon"
end
allowable_values = ["unique_code", "expires_at", "status"]
if @api_client.config.client_side_validation && opts[:'fields_coupon_code'] && !opts[:'fields_coupon_code'].all? { |item| allowable_values.include?(item) }
fail ArgumentError, "invalid value for \"fields_coupon_code\", must include one of #{allowable_values}"
end
# resource path
local_var_path = '/api/coupons/{id}/coupon-codes/'.sub('{' + 'id' + '}', CGI.escape(id.to_s))
# query parameters
query_params = opts[:query_params] || {}
query_params[:'fields[coupon-code]'] = @api_client.build_collection_param(opts[:'fields_coupon_code'], :csv) if !opts[:'fields_coupon_code'].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'] || "2023-12-15"
# 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 => :"CouponsApi.get_coupon_codes_for_coupon",
: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: CouponsApi#get_coupon_codes_for_coupon\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
end
return data, status_code, headers
end
# Get Coupon For Coupon Code
# Gets a list of coupon codes associated with the given coupon id
*Rate limits*:
Burst: `75/s`
Steady: `700/m` **Scopes:** `coupons:read`
# @param id [String]
# @param [Hash] opts the optional parameters
# @option opts [Array] :fields_coupon For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#sparse-fieldsets
# @return [Hash]
def get_coupon_for_coupon_code(id, opts = {})
data, _status_code, _headers = get_coupon_for_coupon_code_with_http_info(id, opts)
data
end
# Get Coupon For Coupon Code
# Gets a list of coupon codes associated with the given coupon id<br><br>*Rate limits*:<br>Burst: `75/s`<br>Steady: `700/m` **Scopes:** `coupons:read`
# @param id [String]
# @param [Hash] opts the optional parameters
# @option opts [Array] :fields_coupon For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#sparse-fieldsets
# @return [Array<(Hash, Integer, Hash)>] Hash data, response status code and response headers
def get_coupon_for_coupon_code_with_http_info(id, opts = {})
if @api_client.config.debugging
@api_client.config.logger.debug 'Calling API: CouponsApi.get_coupon_for_coupon_code ...'
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 CouponsApi.get_coupon_for_coupon_code"
end
allowable_values = ["external_id", "description"]
if @api_client.config.client_side_validation && opts[:'fields_coupon'] && !opts[:'fields_coupon'].all? { |item| allowable_values.include?(item) }
fail ArgumentError, "invalid value for \"fields_coupon\", must include one of #{allowable_values}"
end
# resource path
local_var_path = '/api/coupon-codes/{id}/coupon/'.sub('{' + 'id' + '}', CGI.escape(id.to_s))
# query parameters
query_params = opts[:query_params] || {}
query_params[:'fields[coupon]'] = @api_client.build_collection_param(opts[:'fields_coupon'], :csv) if !opts[:'fields_coupon'].nil?
# header parameters
header_params = opts[:header_params] || {}
# klaviyo api revision
header_params['revision'] = ENV['API_REVISION'] || "2023-12-15"
# 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 => :"CouponsApi.get_coupon_for_coupon_code",
: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: CouponsApi#get_coupon_for_coupon_code\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
end
return data, status_code, headers
end
# Get Coupon Relationships Coupon Codes
# Gets the coupon relationship associated with the given coupon code id
*Rate limits*:
Burst: `75/s`
Steady: `700/m` **Scopes:** `coupons:read`
# @param id [String]
# @param [Hash] opts the optional parameters
# @return [Hash]
def get_coupon_relationships_coupon_codes(id, opts = {})
data, _status_code, _headers = get_coupon_relationships_coupon_codes_with_http_info(id, opts)
data
end
# Get Coupon Relationships Coupon Codes
# Gets the coupon relationship associated with the given coupon code id<br><br>*Rate limits*:<br>Burst: `75/s`<br>Steady: `700/m` **Scopes:** `coupons:read`
# @param id [String]
# @param [Hash] opts the optional parameters
# @return [Array<(Hash, Integer, Hash)>] Hash data, response status code and response headers
def get_coupon_relationships_coupon_codes_with_http_info(id, opts = {})
if @api_client.config.debugging
@api_client.config.logger.debug 'Calling API: CouponsApi.get_coupon_relationships_coupon_codes ...'
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 CouponsApi.get_coupon_relationships_coupon_codes"
end
# resource path
local_var_path = '/api/coupon-codes/{id}/relationships/coupon/'.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'] || "2023-12-15"
# 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 => :"CouponsApi.get_coupon_relationships_coupon_codes",
: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: CouponsApi#get_coupon_relationships_coupon_codes\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
end
return data, status_code, headers
end
# Get Coupons
# Get all coupons in an account. To learn more, see our [Coupons API guide](https://developers.klaviyo.com/en/docs/use_klaviyos_coupons_api).
*Rate limits*:
Burst: `75/s`
Steady: `700/m` **Scopes:** `coupons:read`
# @param [Hash] opts the optional parameters
# @option opts [Array] :fields_coupon For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#sparse-fieldsets
# @option opts [String] :page_cursor For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#pagination
# @return [Hash]
def get_coupons(opts = {})
data, _status_code, _headers = get_coupons_with_http_info(opts)
data
end
# Get Coupons
# Get all coupons in an account. To learn more, see our [Coupons API guide](https://developers.klaviyo.com/en/docs/use_klaviyos_coupons_api).<br><br>*Rate limits*:<br>Burst: `75/s`<br>Steady: `700/m` **Scopes:** `coupons:read`
# @param [Hash] opts the optional parameters
# @option opts [Array] :fields_coupon For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#sparse-fieldsets
# @option opts [String] :page_cursor For more information please visit https://developers.klaviyo.com/en/v2023-12-15/reference/api-overview#pagination
# @return [Array<(Hash, Integer, Hash)>] Hash data, response status code and response headers
def get_coupons_with_http_info(opts = {})
if @api_client.config.debugging
@api_client.config.logger.debug 'Calling API: CouponsApi.get_coupons ...'
end
allowable_values = ["external_id", "description"]
if @api_client.config.client_side_validation && opts[:'fields_coupon'] && !opts[:'fields_coupon'].all? { |item| allowable_values.include?(item) }
fail ArgumentError, "invalid value for \"fields_coupon\", must include one of #{allowable_values}"
end
# resource path
local_var_path = '/api/coupons/'
# query parameters
query_params = opts[:query_params] || {}
query_params[:'fields[coupon]'] = @api_client.build_collection_param(opts[:'fields_coupon'], :csv) if !opts[:'fields_coupon'].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'] || "2023-12-15"
# 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 => :"CouponsApi.get_coupons",
: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: CouponsApi#get_coupons\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
end
return data, status_code, headers
end
# Spawn Coupon Code Bulk Create Job
# Create a coupon-code-bulk-create-job to bulk create a list of coupon codes. Max number of jobs queued at once we allow for is 100.
*Rate limits*:
Burst: `75/s`
Steady: `700/m` **Scopes:** `coupon-codes:write`
# @param coupon_code_create_job_create_query [CouponCodeCreateJobCreateQuery]
# @param [Hash] opts the optional parameters
# @return [Hash]
def spawn_coupon_code_bulk_create_job(coupon_code_create_job_create_query, opts = {})
data, _status_code, _headers = spawn_coupon_code_bulk_create_job_with_http_info(coupon_code_create_job_create_query, opts)
data
end
# Spawn Coupon Code Bulk Create Job
# Create a coupon-code-bulk-create-job to bulk create a list of coupon codes. Max number of jobs queued at once we allow for is 100.<br><br>*Rate limits*:<br>Burst: `75/s`<br>Steady: `700/m` **Scopes:** `coupon-codes:write`
# @param coupon_code_create_job_create_query [CouponCodeCreateJobCreateQuery]
# @param [Hash] opts the optional parameters
# @return [Array<(Hash, Integer, Hash)>] Hash data, response status code and response headers
def spawn_coupon_code_bulk_create_job_with_http_info(coupon_code_create_job_create_query, opts = {})
if @api_client.config.debugging
@api_client.config.logger.debug 'Calling API: CouponsApi.spawn_coupon_code_bulk_create_job ...'
end
# verify the required parameter 'coupon_code_create_job_create_query' is set
if @api_client.config.client_side_validation && coupon_code_create_job_create_query.nil?
fail ArgumentError, "Missing the required parameter 'coupon_code_create_job_create_query' when calling CouponsApi.spawn_coupon_code_bulk_create_job"
end
# resource path
local_var_path = '/api/coupon-code-bulk-create-jobs/'
# query parameters
query_params = opts[:query_params] || {}
# header parameters
header_params = opts[:header_params] || {}
# klaviyo api revision
header_params['revision'] = ENV['API_REVISION'] || "2023-12-15"
# 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(coupon_code_create_job_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 => :"CouponsApi.spawn_coupon_code_bulk_create_job",
: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: CouponsApi#spawn_coupon_code_bulk_create_job\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
end
return data, status_code, headers
end
# Update Coupon
# *Rate limits*:
Burst: `3/s`
Steady: `60/m` **Scopes:** `coupons:write`
# @param id [String] The internal id of a Coupon is equivalent to its external id stored within an integration.
# @param coupon_update_query [CouponUpdateQuery]
# @param [Hash] opts the optional parameters
# @return [Hash]
def update_coupon(id, coupon_update_query, opts = {})
data, _status_code, _headers = update_coupon_with_http_info(id, coupon_update_query, opts)
data
end
# Update Coupon
# *Rate limits*:<br>Burst: `3/s`<br>Steady: `60/m` **Scopes:** `coupons:write`
# @param id [String] The internal id of a Coupon is equivalent to its external id stored within an integration.
# @param coupon_update_query [CouponUpdateQuery]
# @param [Hash] opts the optional parameters
# @return [Array<(Hash, Integer, Hash)>] Hash data, response status code and response headers
def update_coupon_with_http_info(id, coupon_update_query, opts = {})
if @api_client.config.debugging
@api_client.config.logger.debug 'Calling API: CouponsApi.update_coupon ...'
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 CouponsApi.update_coupon"
end
# verify the required parameter 'coupon_update_query' is set
if @api_client.config.client_side_validation && coupon_update_query.nil?
fail ArgumentError, "Missing the required parameter 'coupon_update_query' when calling CouponsApi.update_coupon"
end
# resource path
local_var_path = '/api/coupons/{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'] || "2023-12-15"
# 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(coupon_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 => :"CouponsApi.update_coupon",
: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: CouponsApi#update_coupon\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
end
return data, status_code, headers
end
# Update Coupon Code
# Updates a coupon code specified by the given identifier synchronously. We allow updating the 'status' and 'expires_at' of coupon codes.
*Rate limits*:
Burst: `350/s`
Steady: `3500/m` **Scopes:** `coupon-codes:write`
# @param id [String] The id of a coupon code is a combination of its unique code and the id of the coupon it is associated with.
# @param coupon_code_update_query [CouponCodeUpdateQuery]
# @param [Hash] opts the optional parameters
# @return [Hash]
def update_coupon_code(id, coupon_code_update_query, opts = {})
data, _status_code, _headers = update_coupon_code_with_http_info(id, coupon_code_update_query, opts)
data
end
# Update Coupon Code
# Updates a coupon code specified by the given identifier synchronously. We allow updating the 'status' and 'expires_at' of coupon codes.<br><br>*Rate limits*:<br>Burst: `350/s`<br>Steady: `3500/m` **Scopes:** `coupon-codes:write`
# @param id [String] The id of a coupon code is a combination of its unique code and the id of the coupon it is associated with.
# @param coupon_code_update_query [CouponCodeUpdateQuery]
# @param [Hash] opts the optional parameters
# @return [Array<(Hash, Integer, Hash)>] Hash data, response status code and response headers
def update_coupon_code_with_http_info(id, coupon_code_update_query, opts = {})
if @api_client.config.debugging
@api_client.config.logger.debug 'Calling API: CouponsApi.update_coupon_code ...'
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 CouponsApi.update_coupon_code"
end
# verify the required parameter 'coupon_code_update_query' is set
if @api_client.config.client_side_validation && coupon_code_update_query.nil?
fail ArgumentError, "Missing the required parameter 'coupon_code_update_query' when calling CouponsApi.update_coupon_code"
end
# resource path
local_var_path = '/api/coupon-codes/{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'] || "2023-12-15"
# 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(coupon_code_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 => :"CouponsApi.update_coupon_code",
: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: CouponsApi#update_coupon_code\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
end
return data, status_code, headers
end
end
end