class Multiwoven::Integrations::Destination::Klaviyo::Client
def write(sync_config, records, _action = "destination_insert")
def write(sync_config, records, _action = "destination_insert") connection_config = sync_config.destination.connection_specification.with_indifferent_access connection_config = connection_config.with_indifferent_access url = sync_config.stream.url request_method = sync_config.stream.request_method write_success = 0 write_failure = 0 records.each do |record| # pre process payload # Add hardcode values into payload record["data"] ||= {} record["data"]["type"] = sync_config.stream.name response = Multiwoven::Integrations::Core::HttpClient.request( url, request_method, payload: record, headers: auth_headers(connection_config["private_api_key"]) ) if success?(response) write_success += 1 else write_failure += 1 end rescue StandardError => e handle_exception(e, { context: "KLAVIYO:RECORD:WRITE:FAILURE", type: "error", sync_id: sync_config.sync_id, sync_run_id: sync_config.sync_run_id }) write_failure += 1 end tracker = Multiwoven::Integrations::Protocol::TrackingMessage.new( success: write_success, failed: write_failure ) tracker.to_multiwoven_message rescue StandardError => e # TODO: Handle rate limiting seperately handle_exception(e, { context: "KLAVIYO:RECORD:WRITE:FAILURE", type: "error", sync_id: sync_config.sync_id, sync_run_id: sync_config.sync_run_id }) end