Klaviyo Ruby SDK

  • SDK version: 1.0.0
  • API revision: 2022-10-17

Helpful Resources

Design & Approach

This SDK is a thin wrapper around our API. See our API Reference for full documentation on API behavior.

Organization

This SDK is organized into the following resources:

  • Catalogs

  • Client

  • Events

  • Flows

  • Lists

  • Metrics

  • Profiles

  • Segments

  • Templates

Installation

Build

To build the Ruby code into a gem:

gem build klaviyo-api-sdk.gemspec

Then install the gem locally:

gem install ./klaviyo-api-sdk-1.0.0.gem

Finally add this to the Gemfile:

gem 'klaviyo-api-sdk', '~> 1.0.0'

To install directly from rubygems:

gem install klaviyo-api-sdk

Usage Example

To load the gem

# Load the gem
require 'klaviyo-api-sdk'

# Setup authorization
KlaviyoAPI.configure do |config|
  config.api_key['Klaviyo-API-Key'] = 'Klaviyo-API-Key your-api-key'
  #config.max_retries = 5 # optional
  #config.max_delay = 60 # optional
end

NOTE:

  • The SDK retries on resolvable errors, namely: rate limits (common) and server errors on klaviyo (rare).
  • max_retry denotes number of attempts the client will make in order to execute the request successfully.
  • max_delay denotes total delay (in seconds) across all attempts.

To call the get_catalog_items operation:

opts = {
  include: ['variants'],
  sort: 'created',
  filter: 'equals(published,false)',
  fields_catalog_item: ['external_id','title']
}

begin
  result = KlaviyoAPI::Catalogs.get_catalog_items(opts)
end

Error Handling

This SDK throws an ApiException error when the server returns a non-2XX response.

begin
  result = KlaviyoAPI::Catalogs.get_catalog_items(opts)
rescue KlaviyoAPI::ApiError => e
  puts "Error when calling get_catalog_items #{e}"
end

Comprehensive list of Operations & Parameters

NOTE:

  • Organization: Resource groups and operation_ids are listed in alphabetical order, first by Resource name, then by OpenAPI Summary. Operation summaries are those listed in the right side bar of the API Reference.
  • For example values / data types, as well as whether parameters are required/optional, please reference the corresponding API Reference link.
  • Some args are required for the API call to succeed, the API docs above are the source of truth regarding which params are required.

Method signatures

  • get operations can be passed an optional opts object (e.g. get_list_profiles(opts)). opts describes the available options for fetching data (some operations only support a subset of these or none). i.e.

    opts = {
    include: ['variants'],
    sort: '-created',
    filter: 'equals(published,false)',
    page_cursor: 'page_cursor_example',
    fields_catalog_item: ['external_id','title'],
    fields_catalog_variant: ['external_id','title']
    }
    

    **Note, for parameters that use square brackets such as page[cursor] or fields[catalog-item] ruby will replace the square brackets [] with _ underscores.

  • For create, update & some delete operations (i.e. create_catalog_item or update_catalog_item or delete_catalog_category_relationships) the body object is required in the method signature (i.e. create_catalog_item(body)).

    body = {
    data: {
    type: "catalog-item",
    attributes: {
      external_id: "catalog-item-test",
      title: "Catalog Item Test",
      description: "this is a description",
      url: "http://catalog-item.klaviyo.com",
      published: true
    }
    }
    }
    KlaviyoAPI::Catalogs.create_catalog_item(body)
    

Catalogs

Create Catalog Category

KlaviyoAPI::Catalogs.create_catalog_category(body)

Create Catalog Category Relationships

KlaviyoAPI::Catalogs.create_catalog_category_relationships(id, related_resource, body)

Create Catalog Item

KlaviyoAPI::Catalogs.create_catalog_item(body)

Create Catalog Item Relationships

KlaviyoAPI::Catalogs.create_catalog_item_relationships(id, related_resource, body)

Create Catalog Variant

KlaviyoAPI::Catalogs.create_catalog_variant(body)

Delete Catalog Category

KlaviyoAPI::Catalogs.delete_catalog_category(id)

Delete Catalog Category Relationships

KlaviyoAPI::Catalogs.delete_catalog_category_relationships(id, related_resource, body)

Delete Catalog Item

KlaviyoAPI::Catalogs.delete_catalog_item(id)

Delete Catalog Item Relationships

KlaviyoAPI::Catalogs.delete_catalog_item_relationships(id, related_resource, body)

Delete Catalog Variant

KlaviyoAPI::Catalogs.delete_catalog_variant(id)

Get Catalog Categories

KlaviyoAPI::Catalogs.get_catalog_categories(opts)

Get Catalog Category

KlaviyoAPI::Catalogs.get_catalog_category(id, opts)

Get Catalog Category Items

KlaviyoAPI::Catalogs.get_catalog_category_items(category_id, opts)

Get Catalog Category Relationships

KlaviyoAPI::Catalogs.get_catalog_category_relationships(id, related_resource, opts)

Get Catalog Item

KlaviyoAPI::Catalogs.get_catalog_item(id, opts)

Get Catalog Item Categories

KlaviyoAPI::Catalogs.get_catalog_item_categories(item_id, opts)

Get Catalog Item Relationships

KlaviyoAPI::Catalogs.get_catalog_item_relationships(id, related_resource, opts)

Get Catalog Item Variants

KlaviyoAPI::Catalogs.get_catalog_item_variants(item_id, opts)

Get Catalog Items

KlaviyoAPI::Catalogs.get_catalog_items(opts)

Get Catalog Variant

KlaviyoAPI::Catalogs.get_catalog_variant(id, opts)

Get Catalog Variants

KlaviyoAPI::Catalogs.get_catalog_variants(opts)

Get Create Categories Job

KlaviyoAPI::Catalogs.get_create_categories_job(job_id, opts)

Get Create Categories Jobs

KlaviyoAPI::Catalogs.get_create_categories_jobs(opts)

Get Create Items Job

KlaviyoAPI::Catalogs.get_create_items_job(job_id, opts)

Get Create Items Jobs

KlaviyoAPI::Catalogs.get_create_items_jobs(opts)

Get Create Variants Job

KlaviyoAPI::Catalogs.get_create_variants_job(job_id, opts)

Get Create Variants Jobs

KlaviyoAPI::Catalogs.get_create_variants_jobs(opts)

Get Delete Categories Job

KlaviyoAPI::Catalogs.get_delete_categories_job(job_id, opts)

Get Delete Categories Jobs

KlaviyoAPI::Catalogs.get_delete_categories_jobs(opts)

Get Delete Items Job

KlaviyoAPI::Catalogs.get_delete_items_job(job_id, opts)

Get Delete Items Jobs

KlaviyoAPI::Catalogs.get_delete_items_jobs(opts)

Get Delete Variants Job

KlaviyoAPI::Catalogs.get_delete_variants_job(job_id, opts)

Get Delete Variants Jobs

KlaviyoAPI::Catalogs.get_delete_variants_jobs(opts)

Get Update Categories Job

KlaviyoAPI::Catalogs.get_update_categories_job(job_id, opts)

Get Update Categories Jobs

KlaviyoAPI::Catalogs.get_update_categories_jobs(opts)

Get Update Items Job

KlaviyoAPI::Catalogs.get_update_items_job(job_id, opts)

Get Update Items Jobs

KlaviyoAPI::Catalogs.get_update_items_jobs(opts)

Get Update Variants Job

KlaviyoAPI::Catalogs.get_update_variants_job(job_id, opts)

Get Update Variants Jobs

KlaviyoAPI::Catalogs.get_update_variants_jobs(opts)

Spawn Create Categories Job

KlaviyoAPI::Catalogs.spawn_create_categories_job(body)

Spawn Create Items Job

KlaviyoAPI::Catalogs.spawn_create_items_job(body)

Spawn Create Variants Job

KlaviyoAPI::Catalogs.spawn_create_variants_job(body)

Spawn Delete Categories Job

KlaviyoAPI::Catalogs.spawn_delete_categories_job(body)

Spawn Delete Items Job

KlaviyoAPI::Catalogs.spawn_delete_items_job(body)

Spawn Delete Variants Job

KlaviyoAPI::Catalogs.spawn_delete_variants_job(body)

Spawn Update Categories Job

KlaviyoAPI::Catalogs.spawn_update_categories_job(body)

Spawn Update Items Job

KlaviyoAPI::Catalogs.spawn_update_items_job(body)

Spawn Update Variants Job

KlaviyoAPI::Catalogs.spawn_update_variants_job(body)

Update Catalog Category

KlaviyoAPI::Catalogs.update_catalog_category(id, body)

Update Catalog Category Relationships

KlaviyoAPI::Catalogs.update_catalog_category_relationships(id, related_resource, body)

Update Catalog Item

KlaviyoAPI::Catalogs.update_catalog_item(id, body)

Update Catalog Item Relationships

KlaviyoAPI::Catalogs.update_catalog_item_relationships(id, related_resource, body)

Update Catalog Variant

KlaviyoAPI::Catalogs.update_catalog_variant(id, body)

Client

Create Client Event

KlaviyoAPI::Client.create_client_event(company_id, body)

Create Client Profile

KlaviyoAPI::Client.create_client_profile(company_id, body)

Create Client Subscription

KlaviyoAPI::Client.create_client_subscription(company_id, body)

Events

Create Event

KlaviyoAPI::Events.create_event(body)

Get Event

KlaviyoAPI::Events.get_event(id, opts)

Get Event Metrics

KlaviyoAPI::Events.get_event_metrics(id, opts)

Get Event Profiles

KlaviyoAPI::Events.get_event_profiles(id, opts)

Get Event Relationships

KlaviyoAPI::Events.get_event_relationships(id, related_resource)

Get Events

KlaviyoAPI::Events.get_events(opts)

Flows

Get Flow

KlaviyoAPI::Flows.get_flow(id, opts)

Get Flow Action

KlaviyoAPI::Flows.get_flow_action(id, opts)

Get Flow For Flow Action

KlaviyoAPI::Flows.get_flow_action_flow(action_id, opts)

Get Messages For Flow Action

KlaviyoAPI::Flows.get_flow_action_messages(action_id, opts)

Get Flow Action Relationships

KlaviyoAPI::Flows.get_flow_action_relationships(id, related_resource, opts)

Get Flow Actions For Flow

KlaviyoAPI::Flows.get_flow_flow_actions(flow_id, opts)

Get Flow Message

KlaviyoAPI::Flows.get_flow_message(id, opts)

Get Flow Action For Message

KlaviyoAPI::Flows.get_flow_message_action(message_id, opts)

Get Flow Message Relationships

KlaviyoAPI::Flows.get_flow_message_relationships(id, related_resource)

Get Flow Relationships

KlaviyoAPI::Flows.get_flow_relationships(id, related_resource, opts)

Get Flows

KlaviyoAPI::Flows.get_flows(opts)

Update Flow Status

KlaviyoAPI::Flows.update_flow(id, body)

Lists

Create List

KlaviyoAPI::Lists.create_list(body)

Add Profile to List

KlaviyoAPI::Lists.create_list_relationships(id, related_resource, body)

Delete List

KlaviyoAPI::Lists.delete_list(id)

Remove Profile from List

KlaviyoAPI::Lists.delete_list_relationships(id, related_resource, body)

Get List

KlaviyoAPI::Lists.get_list(id, opts)

Get List Profiles

KlaviyoAPI::Lists.get_list_profiles(list_id, opts)

Get List Profile Relationships

KlaviyoAPI::Lists.get_list_relationships(id, related_resource, opts)

Get Lists

KlaviyoAPI::Lists.get_lists(opts)

Update List

KlaviyoAPI::Lists.update_list(id, body)

Metrics

Get Metric

KlaviyoAPI::Metrics.get_metric(id, opts)

Get Metrics

KlaviyoAPI::Metrics.get_metrics(opts)

Query Metric Aggregates

KlaviyoAPI::Metrics.query_metric_aggregates(body)

Profiles

Create Profile

KlaviyoAPI::Profiles.create_profile(body)

Get Profile

KlaviyoAPI::Profiles.get_profile(id, opts)

Get Profile Lists

KlaviyoAPI::Profiles.get_profile_lists(profile_id, opts)

Get Profile Relationships

KlaviyoAPI::Profiles.get_profile_relationships(id, related_resource)

Get Profile Segments

KlaviyoAPI::Profiles.get_profile_segments(profile_id, opts)

Get Profiles

KlaviyoAPI::Profiles.get_profiles(opts)

Subscribe Profiles

KlaviyoAPI::Profiles.subscribe_profiles(body)

Suppress Profiles

KlaviyoAPI::Profiles.suppress_profiles(body)

Unsubscribe Profiles

KlaviyoAPI::Profiles.unsubscribe_profiles(body)

Unsuppress Profiles

KlaviyoAPI::Profiles.unsuppress_profiles(body)

Update Profile

KlaviyoAPI::Profiles.update_profile(id, body)

Segments

Get Segment

KlaviyoAPI::Segments.get_segment(id, opts)

Get Segment Profiles

KlaviyoAPI::Segments.get_segment_profiles(segment_id, opts)

Get Segment Relationships

KlaviyoAPI::Segments.get_segment_relationships(id, related_resource, opts)

Get Segments

KlaviyoAPI::Segments.get_segments(opts)

Update Segment

KlaviyoAPI::Segments.update_segment(id, body)

Templates

Create Template

KlaviyoAPI::Templates.create_template(body)

Create Template Clone

KlaviyoAPI::Templates.create_template_clone(id, body)

Create Template Render

KlaviyoAPI::Templates.create_template_render(id, body)

Delete Template

KlaviyoAPI::Templates.delete_template(id)

Get Template

KlaviyoAPI::Templates.get_template(id, opts)

Get Templates

KlaviyoAPI::Templates.get_templates(opts)

Update Template

KlaviyoAPI::Templates.update_template(id, body)

Appendix

Per Request API key

opts = {
  header_params: {
    'Authorization': 'Klaviyo-API-Key your-api-key',
  },
  debug_auth_names: []
}

response = KlaviyoAPI::Catalogs.get_catalog_items(opts)