=begin #Klaviyo API #The Klaviyo REST API. Please visit https://developers.klaviyo.com for more details. The version of the OpenAPI document: 2024-07-15 Contact: developers@klaviyo.com Generated by: https://openapi-generator.tech OpenAPI Generator version: 6.2.1 =end require 'cgi' module KlaviyoAPI class TemplatesApi attr_accessor :api_client def initialize(api_client = ApiClient.default) @api_client = api_client end # Create Template # Create a new custom HTML template. If there are 1,000 or more templates in an account, creation will fail as there is a limit of 1,000 templates that can be created via the API. Request specific fields using [sparse fieldsets](https://developers.klaviyo.com/en/reference/api_overview#sparse-fieldsets).

*Rate limits*:
Burst: `10/s`
Steady: `150/m` **Scopes:** `templates:write` # @param template_create_query [TemplateCreateQuery] # @param [Hash] opts the optional parameters # @return [Hash] def create_template(template_create_query, opts = {}) data, _status_code, _headers = create_template_with_http_info(template_create_query, opts) data end # Create Template # Create a new custom HTML template. If there are 1,000 or more templates in an account, creation will fail as there is a limit of 1,000 templates that can be created via the API. Request specific fields using [sparse fieldsets](https://developers.klaviyo.com/en/reference/api_overview#sparse-fieldsets).<br><br>*Rate limits*:<br>Burst: `10/s`<br>Steady: `150/m` **Scopes:** `templates:write` # @param template_create_query [TemplateCreateQuery] # @param [Hash] opts the optional parameters # @return [Array<(Hash, Integer, Hash)>] Hash data, response status code and response headers def create_template_with_http_info(template_create_query, opts = {}) if @api_client.config.debugging @api_client.config.logger.debug 'Calling API: TemplatesApi.create_template ...' end # verify the required parameter 'template_create_query' is set if @api_client.config.client_side_validation && template_create_query.nil? fail ArgumentError, "Missing the required parameter 'template_create_query' when calling TemplatesApi.create_template" end # resource path local_var_path = '/api/templates/' # query parameters query_params = opts[:query_params] || {} # header parameters header_params = opts[:header_params] || {} # klaviyo api revision header_params['revision'] = ENV['KLAVIYO_API_REVISION'] || ENV['API_REVISION'] || "2024-07-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(template_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 => :"TemplatesApi.create_template", :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: TemplatesApi#create_template\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end return data, status_code, headers end # Create Template Clone # Create a clone of a template with the given template ID. If there are 1,000 or more templates in an account, cloning will fail as there is a limit of 1,000 templates that can be created via the API.

*Rate limits*:
Burst: `10/s`
Steady: `150/m` **Scopes:** `templates:write` # @param template_clone_query [TemplateCloneQuery] # @param [Hash] opts the optional parameters # @return [Hash] def create_template_clone(template_clone_query, opts = {}) data, _status_code, _headers = create_template_clone_with_http_info(template_clone_query, opts) data end # Create Template Clone # Create a clone of a template with the given template ID. If there are 1,000 or more templates in an account, cloning will fail as there is a limit of 1,000 templates that can be created via the API.<br><br>*Rate limits*:<br>Burst: `10/s`<br>Steady: `150/m` **Scopes:** `templates:write` # @param template_clone_query [TemplateCloneQuery] # @param [Hash] opts the optional parameters # @return [Array<(Hash, Integer, Hash)>] Hash data, response status code and response headers def create_template_clone_with_http_info(template_clone_query, opts = {}) if @api_client.config.debugging @api_client.config.logger.debug 'Calling API: TemplatesApi.create_template_clone ...' end # verify the required parameter 'template_clone_query' is set if @api_client.config.client_side_validation && template_clone_query.nil? fail ArgumentError, "Missing the required parameter 'template_clone_query' when calling TemplatesApi.create_template_clone" end # resource path local_var_path = '/api/template-clone/' # query parameters query_params = opts[:query_params] || {} # header parameters header_params = opts[:header_params] || {} # klaviyo api revision header_params['revision'] = ENV['KLAVIYO_API_REVISION'] || ENV['API_REVISION'] || "2024-07-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(template_clone_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 => :"TemplatesApi.create_template_clone", :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: TemplatesApi#create_template_clone\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end return data, status_code, headers end # Create Template Render # Render a template with the given template ID and context attribute. Returns the HTML and plain text versions of the email template. **Request body parameters** (nested under `attributes`): * `return_fields`: Request specific fields using [sparse fieldsets](https://developers.klaviyo.com/en/reference/api_overview#sparse-fieldsets). * `context`: This is the context your email template will be rendered with. You must pass in a `context` object as a JSON object. Email templates are rendered with contexts in a similar manner to Django templates. Nested template variables can be referenced via dot notation. Template variables without corresponding `context` values are treated as `FALSE` and output nothing. Ex. `{ \"name\" : \"George Washington\", \"state\" : \"VA\" }`

*Rate limits*:
Burst: `3/s`
Steady: `60/m` **Scopes:** `templates:read` # @param template_render_query [TemplateRenderQuery] # @param [Hash] opts the optional parameters # @return [Hash] def create_template_render(template_render_query, opts = {}) data, _status_code, _headers = create_template_render_with_http_info(template_render_query, opts) data end # Create Template Render # Render a template with the given template ID and context attribute. Returns the HTML and plain text versions of the email template. **Request body parameters** (nested under `attributes`): * `return_fields`: Request specific fields using [sparse fieldsets](https://developers.klaviyo.com/en/reference/api_overview#sparse-fieldsets). * `context`: This is the context your email template will be rendered with. You must pass in a `context` object as a JSON object. Email templates are rendered with contexts in a similar manner to Django templates. Nested template variables can be referenced via dot notation. Template variables without corresponding `context` values are treated as `FALSE` and output nothing. Ex. `{ \"name\" : \"George Washington\", \"state\" : \"VA\" }`<br><br>*Rate limits*:<br>Burst: `3/s`<br>Steady: `60/m` **Scopes:** `templates:read` # @param template_render_query [TemplateRenderQuery] # @param [Hash] opts the optional parameters # @return [Array<(Hash, Integer, Hash)>] Hash data, response status code and response headers def create_template_render_with_http_info(template_render_query, opts = {}) if @api_client.config.debugging @api_client.config.logger.debug 'Calling API: TemplatesApi.create_template_render ...' end # verify the required parameter 'template_render_query' is set if @api_client.config.client_side_validation && template_render_query.nil? fail ArgumentError, "Missing the required parameter 'template_render_query' when calling TemplatesApi.create_template_render" end # resource path local_var_path = '/api/template-render/' # query parameters query_params = opts[:query_params] || {} # header parameters header_params = opts[:header_params] || {} # klaviyo api revision header_params['revision'] = ENV['KLAVIYO_API_REVISION'] || ENV['API_REVISION'] || "2024-07-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(template_render_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 => :"TemplatesApi.create_template_render", :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: TemplatesApi#create_template_render\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end return data, status_code, headers end # Delete Template # Delete a template with the given template ID.

*Rate limits*:
Burst: `10/s`
Steady: `150/m` **Scopes:** `templates:write` # @param id [String] The ID of template # @param [Hash] opts the optional parameters # @return [nil] def delete_template(id, opts = {}) delete_template_with_http_info(id, opts) nil end # Delete Template # Delete a template with the given template ID.<br><br>*Rate limits*:<br>Burst: `10/s`<br>Steady: `150/m` **Scopes:** `templates:write` # @param id [String] The ID of template # @param [Hash] opts the optional parameters # @return [Array<(nil, Integer, Hash)>] nil, response status code and response headers def delete_template_with_http_info(id, opts = {}) if @api_client.config.debugging @api_client.config.logger.debug 'Calling API: TemplatesApi.delete_template ...' 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 TemplatesApi.delete_template" end # resource path local_var_path = '/api/templates/{id}/'.sub('{' + 'id' + '}', CGI.escape(id.to_s)) # query parameters query_params = opts[:query_params] || {} # header parameters header_params = opts[:header_params] || {} # klaviyo api revision header_params['revision'] = ENV['KLAVIYO_API_REVISION'] || ENV['API_REVISION'] || "2024-07-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 => :"TemplatesApi.delete_template", :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: TemplatesApi#delete_template\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end return data, status_code, headers end # Get Template # Get a template with the given template ID.

*Rate limits*:
Burst: `10/s`
Steady: `150/m` **Scopes:** `templates:read` # @param id [String] The ID of template # @param [Hash] opts the optional parameters # @option opts [Array] :fields_template For more information please visit https://developers.klaviyo.com/en/v2024-07-15/reference/api-overview#sparse-fieldsets # @return [Hash] def get_template(id, opts = {}) data, _status_code, _headers = get_template_with_http_info(id, opts) data end # Get Template # Get a template with the given template ID.<br><br>*Rate limits*:<br>Burst: `10/s`<br>Steady: `150/m` **Scopes:** `templates:read` # @param id [String] The ID of template # @param [Hash] opts the optional parameters # @option opts [Array] :fields_template For more information please visit https://developers.klaviyo.com/en/v2024-07-15/reference/api-overview#sparse-fieldsets # @return [Array<(Hash, Integer, Hash)>] Hash data, response status code and response headers def get_template_with_http_info(id, opts = {}) if @api_client.config.debugging @api_client.config.logger.debug 'Calling API: TemplatesApi.get_template ...' 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 TemplatesApi.get_template" end allowable_values = ["name", "editor_type", "html", "text", "created", "updated"] if @api_client.config.client_side_validation && opts[:'fields_template'] && !opts[:'fields_template'].all? { |item| allowable_values.include?(item) } fail ArgumentError, "invalid value for \"fields_template\", must include one of #{allowable_values}" end # resource path local_var_path = '/api/templates/{id}/'.sub('{' + 'id' + '}', CGI.escape(id.to_s)) # query parameters query_params = opts[:query_params] || {} query_params[:'fields[template]'] = @api_client.build_collection_param(opts[:'fields_template'], :csv) if !opts[:'fields_template'].nil? # header parameters header_params = opts[:header_params] || {} # klaviyo api revision header_params['revision'] = ENV['KLAVIYO_API_REVISION'] || ENV['API_REVISION'] || "2024-07-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 => :"TemplatesApi.get_template", :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: TemplatesApi#get_template\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end return data, status_code, headers end # Get Templates # Get all templates in an account. Filter to request a subset of all templates. Templates can be sorted by the following fields, in ascending and descending order: `id`, `name`, `created`, `updated` Returns a maximum of 10 results per page.

*Rate limits*:
Burst: `10/s`
Steady: `150/m` **Scopes:** `templates:read` # @param [Hash] opts the optional parameters # @option opts [Array] :fields_template For more information please visit https://developers.klaviyo.com/en/v2024-07-15/reference/api-overview#sparse-fieldsets # @option opts [String] :filter For more information please visit https://developers.klaviyo.com/en/v2024-07-15/reference/api-overview#filtering<br>Allowed field(s)/operator(s):<br>`id`: `any`, `equals`<br>`name`: `any`, `equals`<br>`created`: `equals`, `greater-or-equal`, `greater-than`, `less-or-equal`, `less-than`<br>`updated`: `equals`, `greater-or-equal`, `greater-than`, `less-or-equal`, `less-than` # @option opts [String] :page_cursor For more information please visit https://developers.klaviyo.com/en/v2024-07-15/reference/api-overview#pagination # @option opts [String] :sort For more information please visit https://developers.klaviyo.com/en/v2024-07-15/reference/api-overview#sorting # @return [Hash] def get_templates(opts = {}) data, _status_code, _headers = get_templates_with_http_info(opts) data end # Get Templates # Get all templates in an account. Filter to request a subset of all templates. Templates can be sorted by the following fields, in ascending and descending order: `id`, `name`, `created`, `updated` Returns a maximum of 10 results per page.<br><br>*Rate limits*:<br>Burst: `10/s`<br>Steady: `150/m` **Scopes:** `templates:read` # @param [Hash] opts the optional parameters # @option opts [Array] :fields_template For more information please visit https://developers.klaviyo.com/en/v2024-07-15/reference/api-overview#sparse-fieldsets # @option opts [String] :filter For more information please visit https://developers.klaviyo.com/en/v2024-07-15/reference/api-overview#filtering<br>Allowed field(s)/operator(s):<br>`id`: `any`, `equals`<br>`name`: `any`, `equals`<br>`created`: `equals`, `greater-or-equal`, `greater-than`, `less-or-equal`, `less-than`<br>`updated`: `equals`, `greater-or-equal`, `greater-than`, `less-or-equal`, `less-than` # @option opts [String] :page_cursor For more information please visit https://developers.klaviyo.com/en/v2024-07-15/reference/api-overview#pagination # @option opts [String] :sort For more information please visit https://developers.klaviyo.com/en/v2024-07-15/reference/api-overview#sorting # @return [Array<(Hash, Integer, Hash)>] Hash data, response status code and response headers def get_templates_with_http_info(opts = {}) if @api_client.config.debugging @api_client.config.logger.debug 'Calling API: TemplatesApi.get_templates ...' end allowable_values = ["name", "editor_type", "html", "text", "created", "updated"] if @api_client.config.client_side_validation && opts[:'fields_template'] && !opts[:'fields_template'].all? { |item| allowable_values.include?(item) } fail ArgumentError, "invalid value for \"fields_template\", must include one of #{allowable_values}" end allowable_values = ["created", "-created", "id", "-id", "name", "-name", "updated", "-updated"] if @api_client.config.client_side_validation && opts[:'sort'] && !allowable_values.include?(opts[:'sort']) fail ArgumentError, "invalid value for \"sort\", must be one of #{allowable_values}" end # resource path local_var_path = '/api/templates/' # query parameters query_params = opts[:query_params] || {} query_params[:'fields[template]'] = @api_client.build_collection_param(opts[:'fields_template'], :csv) if !opts[:'fields_template'].nil? query_params[:'filter'] = opts[:'filter'] if !opts[:'filter'].nil? query_params[:'page[cursor]'] = opts[:'page_cursor'] if !opts[:'page_cursor'].nil? query_params[:'sort'] = opts[:'sort'] if !opts[:'sort'].nil? # header parameters header_params = opts[:header_params] || {} # klaviyo api revision header_params['revision'] = ENV['KLAVIYO_API_REVISION'] || ENV['API_REVISION'] || "2024-07-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 => :"TemplatesApi.get_templates", :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: TemplatesApi#get_templates\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end return data, status_code, headers end # Update Template # Update a template with the given template ID. Does not currently update drag & drop templates.

*Rate limits*:
Burst: `10/s`
Steady: `150/m` **Scopes:** `templates:write` # @param id [String] The ID of template # @param template_update_query [TemplateUpdateQuery] # @param [Hash] opts the optional parameters # @return [Hash] def update_template(id, template_update_query, opts = {}) data, _status_code, _headers = update_template_with_http_info(id, template_update_query, opts) data end # Update Template # Update a template with the given template ID. Does not currently update drag & drop templates.<br><br>*Rate limits*:<br>Burst: `10/s`<br>Steady: `150/m` **Scopes:** `templates:write` # @param id [String] The ID of template # @param template_update_query [TemplateUpdateQuery] # @param [Hash] opts the optional parameters # @return [Array<(Hash, Integer, Hash)>] Hash data, response status code and response headers def update_template_with_http_info(id, template_update_query, opts = {}) if @api_client.config.debugging @api_client.config.logger.debug 'Calling API: TemplatesApi.update_template ...' 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 TemplatesApi.update_template" end # verify the required parameter 'template_update_query' is set if @api_client.config.client_side_validation && template_update_query.nil? fail ArgumentError, "Missing the required parameter 'template_update_query' when calling TemplatesApi.update_template" end # resource path local_var_path = '/api/templates/{id}/'.sub('{' + 'id' + '}', CGI.escape(id.to_s)) # query parameters query_params = opts[:query_params] || {} # header parameters header_params = opts[:header_params] || {} # klaviyo api revision header_params['revision'] = ENV['KLAVIYO_API_REVISION'] || ENV['API_REVISION'] || "2024-07-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(template_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 => :"TemplatesApi.update_template", :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: TemplatesApi#update_template\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end return data, status_code, headers end end end