=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 WebhooksApi attr_accessor :api_client def initialize(api_client = ApiClient.default) @api_client = api_client end # Create Webhook # Create a new Webhook

*Rate limits*:
Burst: `1/s`
Steady: `15/m` **Scopes:** `webhooks:write` # @param webhook_create_query [WebhookCreateQuery] # @param [Hash] opts the optional parameters # @return [Hash] def create_webhook(webhook_create_query, opts = {}) data, _status_code, _headers = create_webhook_with_http_info(webhook_create_query, opts) data end # Create Webhook # Create a new Webhook<br><br>*Rate limits*:<br>Burst: `1/s`<br>Steady: `15/m` **Scopes:** `webhooks:write` # @param webhook_create_query [WebhookCreateQuery] # @param [Hash] opts the optional parameters # @return [Array<(Hash, Integer, Hash)>] Hash data, response status code and response headers def create_webhook_with_http_info(webhook_create_query, opts = {}) if @api_client.config.debugging @api_client.config.logger.debug 'Calling API: WebhooksApi.create_webhook ...' end # verify the required parameter 'webhook_create_query' is set if @api_client.config.client_side_validation && webhook_create_query.nil? fail ArgumentError, "Missing the required parameter 'webhook_create_query' when calling WebhooksApi.create_webhook" end # resource path local_var_path = '/api/webhooks/' # 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(webhook_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 => :"WebhooksApi.create_webhook", :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: WebhooksApi#create_webhook\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end return data, status_code, headers end # Delete Webhook # Delete a webhook with the given ID.

*Rate limits*:
Burst: `1/s`
Steady: `15/m` **Scopes:** `webhooks:write` # @param id [String] The ID of the webhook. # @param [Hash] opts the optional parameters # @return [nil] def delete_webhook(id, opts = {}) delete_webhook_with_http_info(id, opts) nil end # Delete Webhook # Delete a webhook with the given ID.<br><br>*Rate limits*:<br>Burst: `1/s`<br>Steady: `15/m` **Scopes:** `webhooks:write` # @param id [String] The ID of the webhook. # @param [Hash] opts the optional parameters # @return [Array<(nil, Integer, Hash)>] nil, response status code and response headers def delete_webhook_with_http_info(id, opts = {}) if @api_client.config.debugging @api_client.config.logger.debug 'Calling API: WebhooksApi.delete_webhook ...' 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 WebhooksApi.delete_webhook" end # resource path local_var_path = '/api/webhooks/{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 => :"WebhooksApi.delete_webhook", :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: WebhooksApi#delete_webhook\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end return data, status_code, headers end # Get Webhook # Get the webhook with the given ID.

*Rate limits*:
Burst: `1/s`
Steady: `15/m` **Scopes:** `webhooks:read` # @param id [String] The ID of the webhook. # @param [Hash] opts the optional parameters # @option opts [Array] :fields_webhook For more information please visit https://developers.klaviyo.com/en/v2024-07-15/reference/api-overview#sparse-fieldsets # @option opts [Array] :include For more information please visit https://developers.klaviyo.com/en/v2024-07-15/reference/api-overview#relationships # @return [Hash] def get_webhook(id, opts = {}) data, _status_code, _headers = get_webhook_with_http_info(id, opts) data end # Get Webhook # Get the webhook with the given ID.<br><br>*Rate limits*:<br>Burst: `1/s`<br>Steady: `15/m` **Scopes:** `webhooks:read` # @param id [String] The ID of the webhook. # @param [Hash] opts the optional parameters # @option opts [Array] :fields_webhook For more information please visit https://developers.klaviyo.com/en/v2024-07-15/reference/api-overview#sparse-fieldsets # @option opts [Array] :include For more information please visit https://developers.klaviyo.com/en/v2024-07-15/reference/api-overview#relationships # @return [Array<(Hash, Integer, Hash)>] Hash data, response status code and response headers def get_webhook_with_http_info(id, opts = {}) if @api_client.config.debugging @api_client.config.logger.debug 'Calling API: WebhooksApi.get_webhook ...' 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 WebhooksApi.get_webhook" end allowable_values = ["name", "description", "endpoint_url", "enabled", "created_at", "updated_at"] if @api_client.config.client_side_validation && opts[:'fields_webhook'] && !opts[:'fields_webhook'].all? { |item| allowable_values.include?(item) } fail ArgumentError, "invalid value for \"fields_webhook\", must include one of #{allowable_values}" end allowable_values = ["webhook-topics"] 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/webhooks/{id}/'.sub('{' + 'id' + '}', CGI.escape(id.to_s)) # query parameters query_params = opts[:query_params] || {} query_params[:'fields[webhook]'] = @api_client.build_collection_param(opts[:'fields_webhook'], :csv) if !opts[:'fields_webhook'].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['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 => :"WebhooksApi.get_webhook", :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: WebhooksApi#get_webhook\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end return data, status_code, headers end # Get Webhook Topic # Get the webhook topic with the given ID.

*Rate limits*:
Burst: `1/s`
Steady: `15/m` **Scopes:** `webhooks:read` # @param id [String] The ID of the webhook topic. # @param [Hash] opts the optional parameters # @return [Hash] def get_webhook_topic(id, opts = {}) data, _status_code, _headers = get_webhook_topic_with_http_info(id, opts) data end # Get Webhook Topic # Get the webhook topic with the given ID.<br><br>*Rate limits*:<br>Burst: `1/s`<br>Steady: `15/m` **Scopes:** `webhooks:read` # @param id [String] The ID of the webhook topic. # @param [Hash] opts the optional parameters # @return [Array<(Hash, Integer, Hash)>] Hash data, response status code and response headers def get_webhook_topic_with_http_info(id, opts = {}) if @api_client.config.debugging @api_client.config.logger.debug 'Calling API: WebhooksApi.get_webhook_topic ...' 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 WebhooksApi.get_webhook_topic" end # resource path local_var_path = '/api/webhook-topics/{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] || 'Hash' # auth_names auth_names = opts[:debug_auth_names] || ['Klaviyo-API-Key'] new_options = opts.merge( :operation => :"WebhooksApi.get_webhook_topic", :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: WebhooksApi#get_webhook_topic\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end return data, status_code, headers end # Get Webhook Topics # Get all webhook topics in a Klaviyo account.

*Rate limits*:
Burst: `1/s`
Steady: `15/m` **Scopes:** `webhooks:read` # @param [Hash] opts the optional parameters # @return [Hash] def get_webhook_topics(opts = {}) data, _status_code, _headers = get_webhook_topics_with_http_info(opts) data end # Get Webhook Topics # Get all webhook topics in a Klaviyo account.<br><br>*Rate limits*:<br>Burst: `1/s`<br>Steady: `15/m` **Scopes:** `webhooks:read` # @param [Hash] opts the optional parameters # @return [Array<(Hash, Integer, Hash)>] Hash data, response status code and response headers def get_webhook_topics_with_http_info(opts = {}) if @api_client.config.debugging @api_client.config.logger.debug 'Calling API: WebhooksApi.get_webhook_topics ...' end # resource path local_var_path = '/api/webhook-topics/' # 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] || 'Hash' # auth_names auth_names = opts[:debug_auth_names] || ['Klaviyo-API-Key'] new_options = opts.merge( :operation => :"WebhooksApi.get_webhook_topics", :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: WebhooksApi#get_webhook_topics\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end return data, status_code, headers end # Get Webhooks # Get all webhooks in an account.

*Rate limits*:
Burst: `1/s`
Steady: `15/m` **Scopes:** `webhooks:read` # @param [Hash] opts the optional parameters # @option opts [Array] :fields_webhook For more information please visit https://developers.klaviyo.com/en/v2024-07-15/reference/api-overview#sparse-fieldsets # @option opts [Array] :include For more information please visit https://developers.klaviyo.com/en/v2024-07-15/reference/api-overview#relationships # @return [Hash] def get_webhooks(opts = {}) data, _status_code, _headers = get_webhooks_with_http_info(opts) data end # Get Webhooks # Get all webhooks in an account.<br><br>*Rate limits*:<br>Burst: `1/s`<br>Steady: `15/m` **Scopes:** `webhooks:read` # @param [Hash] opts the optional parameters # @option opts [Array] :fields_webhook For more information please visit https://developers.klaviyo.com/en/v2024-07-15/reference/api-overview#sparse-fieldsets # @option opts [Array] :include For more information please visit https://developers.klaviyo.com/en/v2024-07-15/reference/api-overview#relationships # @return [Array<(Hash, Integer, Hash)>] Hash data, response status code and response headers def get_webhooks_with_http_info(opts = {}) if @api_client.config.debugging @api_client.config.logger.debug 'Calling API: WebhooksApi.get_webhooks ...' end allowable_values = ["name", "description", "endpoint_url", "enabled", "created_at", "updated_at"] if @api_client.config.client_side_validation && opts[:'fields_webhook'] && !opts[:'fields_webhook'].all? { |item| allowable_values.include?(item) } fail ArgumentError, "invalid value for \"fields_webhook\", must include one of #{allowable_values}" end allowable_values = ["webhook-topics"] 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/webhooks/' # query parameters query_params = opts[:query_params] || {} query_params[:'fields[webhook]'] = @api_client.build_collection_param(opts[:'fields_webhook'], :csv) if !opts[:'fields_webhook'].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['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 => :"WebhooksApi.get_webhooks", :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: WebhooksApi#get_webhooks\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end return data, status_code, headers end # Update Webhook # Update the webhook with the given ID.

*Rate limits*:
Burst: `1/s`
Steady: `15/m` **Scopes:** `webhooks:write` # @param id [String] The ID of the webhook. # @param webhook_partial_update_query [WebhookPartialUpdateQuery] # @param [Hash] opts the optional parameters # @return [Hash] def update_webhook(id, webhook_partial_update_query, opts = {}) data, _status_code, _headers = update_webhook_with_http_info(id, webhook_partial_update_query, opts) data end # Update Webhook # Update the webhook with the given ID.<br><br>*Rate limits*:<br>Burst: `1/s`<br>Steady: `15/m` **Scopes:** `webhooks:write` # @param id [String] The ID of the webhook. # @param webhook_partial_update_query [WebhookPartialUpdateQuery] # @param [Hash] opts the optional parameters # @return [Array<(Hash, Integer, Hash)>] Hash data, response status code and response headers def update_webhook_with_http_info(id, webhook_partial_update_query, opts = {}) if @api_client.config.debugging @api_client.config.logger.debug 'Calling API: WebhooksApi.update_webhook ...' 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 WebhooksApi.update_webhook" end # verify the required parameter 'webhook_partial_update_query' is set if @api_client.config.client_side_validation && webhook_partial_update_query.nil? fail ArgumentError, "Missing the required parameter 'webhook_partial_update_query' when calling WebhooksApi.update_webhook" end # resource path local_var_path = '/api/webhooks/{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(webhook_partial_update_query) # return_type return_type = opts[:debug_return_type] || 'Hash' # auth_names auth_names = opts[:debug_auth_names] || ['Klaviyo-API-Key'] new_options = opts.merge( :operation => :"WebhooksApi.update_webhook", :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: WebhooksApi#update_webhook\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end return data, status_code, headers end end end