# KlaviyoAPI::TemplatesApi All URIs are relative to *https://a.klaviyo.com* | Method | HTTP request | Description | | ------ | ------------ | ----------- | | [**create_template**](TemplatesApi.md#create_template) | **POST** /api/templates/ | Create Template | | [**create_template_clone**](TemplatesApi.md#create_template_clone) | **POST** /api/template-clone/ | Create Template Clone | | [**create_template_render**](TemplatesApi.md#create_template_render) | **POST** /api/template-render/ | Create Template Render | | [**delete_template**](TemplatesApi.md#delete_template) | **DELETE** /api/templates/{id}/ | Delete Template | | [**get_template**](TemplatesApi.md#get_template) | **GET** /api/templates/{id}/ | Get Template | | [**get_templates**](TemplatesApi.md#get_templates) | **GET** /api/templates/ | Get Templates | | [**update_template**](TemplatesApi.md#update_template) | **PATCH** /api/templates/{id}/ | Update Template | ## create_template > Hash<String, Object> create_template(template_create_query) 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:** `template:write` ### Examples ```ruby require 'time' require 'klaviyo-api-sdk' # setup authorization KlaviyoAPI.configure do |config| # Configure API key authorization: Klaviyo-API-Key config.api_key['Klaviyo-API-Key'] = 'YOUR API KEY' # Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil) # config.api_key_prefix['Klaviyo-API-Key'] = 'Bearer' end api_instance = KlaviyoAPI::TemplatesApi.new template_create_query = KlaviyoAPI::TemplateCreateQuery.new({data: KlaviyoAPI::TemplateCreateQueryResourceObject.new({type: KlaviyoAPI::TemplateEnum::TEMPLATE, attributes: KlaviyoAPI::TemplateCreateQueryResourceObjectAttributes.new({name: 'Monthly Newsletter Template', editor_type: 'editor_type_example'})})}) # TemplateCreateQuery | begin # Create Template result = api_instance.create_template(template_create_query) p result rescue KlaviyoAPI::ApiError => e puts "Error when calling TemplatesApi->create_template: #{e}" end ``` #### Using the create_template_with_http_info variant This returns an Array which contains the response data, status code and headers. > create_template_with_http_info(template_create_query) ```ruby begin # Create Template data, status_code, headers = api_instance.create_template_with_http_info(template_create_query) p status_code # => 2xx p headers # => { ... } p data # => Hash<String, Object> rescue KlaviyoAPI::ApiError => e puts "Error when calling TemplatesApi->create_template_with_http_info: #{e}" end ``` ### Parameters | Name | Type | Description | Notes | | ---- | ---- | ----------- | ----- | | **template_create_query** | [**TemplateCreateQuery**](TemplateCreateQuery.md) | | | ### Return type **Hash<String, Object>** ### Authorization [Klaviyo-API-Key](../README.md#Klaviyo-API-Key) ### HTTP request headers - **Content-Type**: application/json - **Accept**: application/json ## create_template_clone > Hash<String, Object> create_template_clone(template_clone_query) Create Template Clone Create a clone of a template with the given template ID.

*Rate limits*:
Burst: `10/s`
Steady: `150/m` **Scopes:** `template:write` ### Examples ```ruby require 'time' require 'klaviyo-api-sdk' # setup authorization KlaviyoAPI.configure do |config| # Configure API key authorization: Klaviyo-API-Key config.api_key['Klaviyo-API-Key'] = 'YOUR API KEY' # Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil) # config.api_key_prefix['Klaviyo-API-Key'] = 'Bearer' end api_instance = KlaviyoAPI::TemplatesApi.new template_clone_query = KlaviyoAPI::TemplateCloneQuery.new({data: KlaviyoAPI::TemplateCloneQueryResourceObject.new({type: KlaviyoAPI::TemplateEnum::TEMPLATE, attributes: KlaviyoAPI::TemplateCloneQueryResourceObjectAttributes.new({id: 'id_example'})})}) # TemplateCloneQuery | begin # Create Template Clone result = api_instance.create_template_clone(template_clone_query) p result rescue KlaviyoAPI::ApiError => e puts "Error when calling TemplatesApi->create_template_clone: #{e}" end ``` #### Using the create_template_clone_with_http_info variant This returns an Array which contains the response data, status code and headers. > create_template_clone_with_http_info(template_clone_query) ```ruby begin # Create Template Clone data, status_code, headers = api_instance.create_template_clone_with_http_info(template_clone_query) p status_code # => 2xx p headers # => { ... } p data # => Hash<String, Object> rescue KlaviyoAPI::ApiError => e puts "Error when calling TemplatesApi->create_template_clone_with_http_info: #{e}" end ``` ### Parameters | Name | Type | Description | Notes | | ---- | ---- | ----------- | ----- | | **template_clone_query** | [**TemplateCloneQuery**](TemplateCloneQuery.md) | | | ### Return type **Hash<String, Object>** ### Authorization [Klaviyo-API-Key](../README.md#Klaviyo-API-Key) ### HTTP request headers - **Content-Type**: application/json - **Accept**: application/json ## create_template_render > Hash<String, Object> create_template_render(template_render_query) 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` ### Examples ```ruby require 'time' require 'klaviyo-api-sdk' # setup authorization KlaviyoAPI.configure do |config| # Configure API key authorization: Klaviyo-API-Key config.api_key['Klaviyo-API-Key'] = 'YOUR API KEY' # Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil) # config.api_key_prefix['Klaviyo-API-Key'] = 'Bearer' end api_instance = KlaviyoAPI::TemplatesApi.new template_render_query = KlaviyoAPI::TemplateRenderQuery.new({data: KlaviyoAPI::TemplateRenderQueryResourceObject.new({type: KlaviyoAPI::TemplateEnum::TEMPLATE, attributes: KlaviyoAPI::TemplateRenderQueryResourceObjectAttributes.new({id: 'id_example', context: {"first_name":"Jane","last_name":"Smith"}})})}) # TemplateRenderQuery | begin # Create Template Render result = api_instance.create_template_render(template_render_query) p result rescue KlaviyoAPI::ApiError => e puts "Error when calling TemplatesApi->create_template_render: #{e}" end ``` #### Using the create_template_render_with_http_info variant This returns an Array which contains the response data, status code and headers. > create_template_render_with_http_info(template_render_query) ```ruby begin # Create Template Render data, status_code, headers = api_instance.create_template_render_with_http_info(template_render_query) p status_code # => 2xx p headers # => { ... } p data # => Hash<String, Object> rescue KlaviyoAPI::ApiError => e puts "Error when calling TemplatesApi->create_template_render_with_http_info: #{e}" end ``` ### Parameters | Name | Type | Description | Notes | | ---- | ---- | ----------- | ----- | | **template_render_query** | [**TemplateRenderQuery**](TemplateRenderQuery.md) | | | ### Return type **Hash<String, Object>** ### Authorization [Klaviyo-API-Key](../README.md#Klaviyo-API-Key) ### HTTP request headers - **Content-Type**: application/json - **Accept**: application/json ## delete_template > delete_template(id) Delete Template Delete a template with the given template ID.

*Rate limits*:
Burst: `10/s`
Steady: `150/m` **Scopes:** `template:write` ### Examples ```ruby require 'time' require 'klaviyo-api-sdk' # setup authorization KlaviyoAPI.configure do |config| # Configure API key authorization: Klaviyo-API-Key config.api_key['Klaviyo-API-Key'] = 'YOUR API KEY' # Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil) # config.api_key_prefix['Klaviyo-API-Key'] = 'Bearer' end api_instance = KlaviyoAPI::TemplatesApi.new id = 'id_example' # String | The ID of template begin # Delete Template api_instance.delete_template(id) rescue KlaviyoAPI::ApiError => e puts "Error when calling TemplatesApi->delete_template: #{e}" end ``` #### Using the delete_template_with_http_info variant This returns an Array which contains the response data (`nil` in this case), status code and headers. > delete_template_with_http_info(id) ```ruby begin # Delete Template data, status_code, headers = api_instance.delete_template_with_http_info(id) p status_code # => 2xx p headers # => { ... } p data # => nil rescue KlaviyoAPI::ApiError => e puts "Error when calling TemplatesApi->delete_template_with_http_info: #{e}" end ``` ### Parameters | Name | Type | Description | Notes | | ---- | ---- | ----------- | ----- | | **id** | **String** | The ID of template | | ### Return type nil (empty response body) ### Authorization [Klaviyo-API-Key](../README.md#Klaviyo-API-Key) ### HTTP request headers - **Content-Type**: Not defined - **Accept**: application/json ## get_template > Hash<String, Object> get_template(id, opts) Get Template Get a template with the given template ID.

*Rate limits*:
Burst: `10/s`
Steady: `150/m` **Scopes:** `templates:read` ### Examples ```ruby require 'time' require 'klaviyo-api-sdk' # setup authorization KlaviyoAPI.configure do |config| # Configure API key authorization: Klaviyo-API-Key config.api_key['Klaviyo-API-Key'] = 'YOUR API KEY' # Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil) # config.api_key_prefix['Klaviyo-API-Key'] = 'Bearer' end api_instance = KlaviyoAPI::TemplatesApi.new id = 'id_example' # String | The ID of template opts = { fields_template: ['name'] # Array | For more information please visit https://developers.klaviyo.com/en/v2023-08-15/reference/api-overview#sparse-fieldsets } begin # Get Template result = api_instance.get_template(id, opts) p result rescue KlaviyoAPI::ApiError => e puts "Error when calling TemplatesApi->get_template: #{e}" end ``` #### Using the get_template_with_http_info variant This returns an Array which contains the response data, status code and headers. > get_template_with_http_info(id, opts) ```ruby begin # Get Template data, status_code, headers = api_instance.get_template_with_http_info(id, opts) p status_code # => 2xx p headers # => { ... } p data # => Hash<String, Object> rescue KlaviyoAPI::ApiError => e puts "Error when calling TemplatesApi->get_template_with_http_info: #{e}" end ``` ### Parameters | Name | Type | Description | Notes | | ---- | ---- | ----------- | ----- | | **id** | **String** | The ID of template | | | **fields_template** | [**Array<String>**](String.md) | For more information please visit https://developers.klaviyo.com/en/v2023-08-15/reference/api-overview#sparse-fieldsets | [optional] | ### Return type **Hash<String, Object>** ### Authorization [Klaviyo-API-Key](../README.md#Klaviyo-API-Key) ### HTTP request headers - **Content-Type**: Not defined - **Accept**: application/json ## get_templates > Hash<String, Object> get_templates(opts) 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` ### Examples ```ruby require 'time' require 'klaviyo-api-sdk' # setup authorization KlaviyoAPI.configure do |config| # Configure API key authorization: Klaviyo-API-Key config.api_key['Klaviyo-API-Key'] = 'YOUR API KEY' # Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil) # config.api_key_prefix['Klaviyo-API-Key'] = 'Bearer' end api_instance = KlaviyoAPI::TemplatesApi.new opts = { fields_template: ['name'], # Array | For more information please visit https://developers.klaviyo.com/en/v2023-08-15/reference/api-overview#sparse-fieldsets filter: 'filter_example', # String | For more information please visit https://developers.klaviyo.com/en/v2023-08-15/reference/api-overview#filtering
Allowed field(s)/operator(s):
`id`: `any`, `equals`
`name`: `any`, `equals`
`created`: `equals`, `greater-or-equal`, `greater-than`, `less-or-equal`, `less-than`
`updated`: `equals`, `greater-or-equal`, `greater-than`, `less-or-equal`, `less-than` page_cursor: 'page_cursor_example', # String | For more information please visit https://developers.klaviyo.com/en/v2023-08-15/reference/api-overview#pagination sort: 'created' # String | For more information please visit https://developers.klaviyo.com/en/v2023-08-15/reference/api-overview#sorting } begin # Get Templates result = api_instance.get_templates(opts) p result rescue KlaviyoAPI::ApiError => e puts "Error when calling TemplatesApi->get_templates: #{e}" end ``` #### Using the get_templates_with_http_info variant This returns an Array which contains the response data, status code and headers. > get_templates_with_http_info(opts) ```ruby begin # Get Templates data, status_code, headers = api_instance.get_templates_with_http_info(opts) p status_code # => 2xx p headers # => { ... } p data # => Hash<String, Object> rescue KlaviyoAPI::ApiError => e puts "Error when calling TemplatesApi->get_templates_with_http_info: #{e}" end ``` ### Parameters | Name | Type | Description | Notes | | ---- | ---- | ----------- | ----- | | **fields_template** | [**Array<String>**](String.md) | For more information please visit https://developers.klaviyo.com/en/v2023-08-15/reference/api-overview#sparse-fieldsets | [optional] | | **filter** | **String** | For more information please visit https://developers.klaviyo.com/en/v2023-08-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` | [optional] | | **page_cursor** | **String** | For more information please visit https://developers.klaviyo.com/en/v2023-08-15/reference/api-overview#pagination | [optional] | | **sort** | **String** | For more information please visit https://developers.klaviyo.com/en/v2023-08-15/reference/api-overview#sorting | [optional] | ### Return type **Hash<String, Object>** ### Authorization [Klaviyo-API-Key](../README.md#Klaviyo-API-Key) ### HTTP request headers - **Content-Type**: Not defined - **Accept**: application/json ## update_template > Hash<String, Object> update_template(id, template_update_query) 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:** `template:write` ### Examples ```ruby require 'time' require 'klaviyo-api-sdk' # setup authorization KlaviyoAPI.configure do |config| # Configure API key authorization: Klaviyo-API-Key config.api_key['Klaviyo-API-Key'] = 'YOUR API KEY' # Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil) # config.api_key_prefix['Klaviyo-API-Key'] = 'Bearer' end api_instance = KlaviyoAPI::TemplatesApi.new id = 'id_example' # String | The ID of template template_update_query = KlaviyoAPI::TemplateUpdateQuery.new({data: KlaviyoAPI::TemplateUpdateQueryResourceObject.new({type: KlaviyoAPI::TemplateEnum::TEMPLATE, id: 'id_example', attributes: KlaviyoAPI::TemplateUpdateQueryResourceObjectAttributes.new})}) # TemplateUpdateQuery | begin # Update Template result = api_instance.update_template(id, template_update_query) p result rescue KlaviyoAPI::ApiError => e puts "Error when calling TemplatesApi->update_template: #{e}" end ``` #### Using the update_template_with_http_info variant This returns an Array which contains the response data, status code and headers. > update_template_with_http_info(id, template_update_query) ```ruby begin # Update Template data, status_code, headers = api_instance.update_template_with_http_info(id, template_update_query) p status_code # => 2xx p headers # => { ... } p data # => Hash<String, Object> rescue KlaviyoAPI::ApiError => e puts "Error when calling TemplatesApi->update_template_with_http_info: #{e}" end ``` ### Parameters | Name | Type | Description | Notes | | ---- | ---- | ----------- | ----- | | **id** | **String** | The ID of template | | | **template_update_query** | [**TemplateUpdateQuery**](TemplateUpdateQuery.md) | | | ### Return type **Hash<String, Object>** ### Authorization [Klaviyo-API-Key](../README.md#Klaviyo-API-Key) ### HTTP request headers - **Content-Type**: application/json - **Accept**: application/json