Klaviyo Ruby SDK Beta

Note: If you would like to request beta access to the new APIs, please fill out this brief form and you will be contacted by Klaviyo's product team once the beta release is available.

  • SDK version: 1.0.1.20220907

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_sdk_beta.gemspec

Then install the gem locally:

gem install ./klaviyo_sdk_beta-1.0.1.20220907.gem

Finally add this to the Gemfile:

gem 'klaviyo_sdk_beta', '~> 1.0.1.20220907'

To install directly from rubygems:

gem install klaviyo_sdk_beta

Usage Example

To load the gem

# Load the gem
require 'klaviyo_sdk_beta'

# Setup authorization
KlaviyoBeta.configure do |config|
  config.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: ['id','title']
}

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

Error Handling

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

begin
  result = KlaviyoBeta::Catalogs.get_catalog_items(opts)
rescue KlaviyoBeta::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
    }
    }
    }
    KlaviyoBeta::Catalogs.create_catalog_item(body)
    

Catalogs

Create Catalog Category

KlaviyoBeta::Catalogs.create_catalog_category(body)

Create Catalog Category Relationships

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

Create Catalog Item

KlaviyoBeta::Catalogs.create_catalog_item(body)

Create Catalog Item Relationships

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

Create Catalog Variant

KlaviyoBeta::Catalogs.create_catalog_variant(body)

Delete Catalog Category

KlaviyoBeta::Catalogs.delete_catalog_category(id)

Delete Catalog Category Relationships

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

Delete Catalog Item

KlaviyoBeta::Catalogs.delete_catalog_item(id)

Delete Catalog Item Relationships

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

Delete Catalog Variant

KlaviyoBeta::Catalogs.delete_catalog_variant(id)

Get Catalog Categories

KlaviyoBeta::Catalogs.get_catalog_categories(opts)

Get Catalog Category

KlaviyoBeta::Catalogs.get_catalog_category(id, opts)

Get Catalog Category Items

KlaviyoBeta::Catalogs.get_catalog_category_items(category_id, opts)

Get Catalog Category Relationships

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

Get Catalog Item

KlaviyoBeta::Catalogs.get_catalog_item(id, opts)

Get Catalog Item Categories

KlaviyoBeta::Catalogs.get_catalog_item_categories(item_id, opts)

Get Catalog Item Relationships

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

Get Catalog Item Variants

KlaviyoBeta::Catalogs.get_catalog_item_variants(item_id, opts)

Get Catalog Items

KlaviyoBeta::Catalogs.get_catalog_items(opts)

Get Catalog Variant

KlaviyoBeta::Catalogs.get_catalog_variant(id, opts)

Get Catalog Variants

KlaviyoBeta::Catalogs.get_catalog_variants(opts)

Get Create Categories Job

KlaviyoBeta::Catalogs.get_create_categories_job(job_id, opts)

Get Create Categories Jobs

KlaviyoBeta::Catalogs.get_create_categories_jobs(opts)

Get Create Items Job

KlaviyoBeta::Catalogs.get_create_items_job(job_id, opts)

Get Create Items Jobs

KlaviyoBeta::Catalogs.get_create_items_jobs(opts)

Get Create Variants Job

KlaviyoBeta::Catalogs.get_create_variants_job(job_id, opts)

Get Create Variants Jobs

KlaviyoBeta::Catalogs.get_create_variants_jobs(opts)

Get Delete Categories Job

KlaviyoBeta::Catalogs.get_delete_categories_job(job_id, opts)

Get Delete Categories Jobs

KlaviyoBeta::Catalogs.get_delete_categories_jobs(opts)

Get Delete Items Job

KlaviyoBeta::Catalogs.get_delete_items_job(job_id, opts)

Get Delete Items Jobs

KlaviyoBeta::Catalogs.get_delete_items_jobs(opts)

Get Delete Variants Job

KlaviyoBeta::Catalogs.get_delete_variants_job(job_id, opts)

Get Delete Variants Jobs

KlaviyoBeta::Catalogs.get_delete_variants_jobs(opts)

Get Update Categories Job

KlaviyoBeta::Catalogs.get_update_categories_job(job_id, opts)

Get Update Categories Jobs

KlaviyoBeta::Catalogs.get_update_categories_jobs(opts)

Get Update Items Job

KlaviyoBeta::Catalogs.get_update_items_job(job_id, opts)

Get Update Items Jobs

KlaviyoBeta::Catalogs.get_update_items_jobs(opts)

Get Update Variants Job

KlaviyoBeta::Catalogs.get_update_variants_job(job_id, opts)

Get Update Variants Jobs

KlaviyoBeta::Catalogs.get_update_variants_jobs(opts)

Spawn Create Categories Job

KlaviyoBeta::Catalogs.spawn_create_categories_job(body)

Spawn Create Items Job

KlaviyoBeta::Catalogs.spawn_create_items_job(body)

Spawn Create Variants Job

KlaviyoBeta::Catalogs.spawn_create_variants_job(body)

Spawn Delete Categories Job

KlaviyoBeta::Catalogs.spawn_delete_categories_job(body)

Spawn Delete Items Job

KlaviyoBeta::Catalogs.spawn_delete_items_job(body)

Spawn Delete Variants Job

KlaviyoBeta::Catalogs.spawn_delete_variants_job(body)

Spawn Update Categories Job

KlaviyoBeta::Catalogs.spawn_update_categories_job(body)

Spawn Update Items Job

KlaviyoBeta::Catalogs.spawn_update_items_job(body)

Spawn Update Variants Job

KlaviyoBeta::Catalogs.spawn_update_variants_job(body)

Update Catalog Category

KlaviyoBeta::Catalogs.update_catalog_category(id, body)

Update Catalog Category Relationships

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

Update Catalog Item

KlaviyoBeta::Catalogs.update_catalog_item(id, body)

Update Catalog Item Relationships

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

Update Catalog Variant

KlaviyoBeta::Catalogs.update_catalog_variant(id, body)

Client

Create Client Event

KlaviyoBeta::Client.create_client_event(company_id, body)

Create Client Profile

KlaviyoBeta::Client.create_client_profile(company_id, body)

Create Client Subscription

KlaviyoBeta::Client.create_client_subscription(company_id, body)

Events

Create Event

KlaviyoBeta::Events.create_event(body)

Get Event

KlaviyoBeta::Events.get_event(id, opts)

Get Event Metrics

KlaviyoBeta::Events.get_event_metrics(id, opts)

Get Event Profiles

KlaviyoBeta::Events.get_event_profiles(id, opts)

Get Event Relationships

KlaviyoBeta::Events.get_event_relationships(id, related_resource)

Get Events

KlaviyoBeta::Events.get_events(opts)

Flows

Get Flow

KlaviyoBeta::Flows.get_flow(id, opts)

Get Flow Action

KlaviyoBeta::Flows.get_flow_action(id, opts)

Get Flow Action Flow

KlaviyoBeta::Flows.get_flow_action_flow(action_id, opts)

Get Flow Action Messages

KlaviyoBeta::Flows.get_flow_action_messages(action_id, opts)

Get Flow Action Relationships

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

Get Flow Flow Actions

KlaviyoBeta::Flows.get_flow_flow_actions(flow_id, opts)

Get Flow Message

KlaviyoBeta::Flows.get_flow_message(id, opts)

Get Flow Message Action

KlaviyoBeta::Flows.get_flow_message_action(message_id, opts)

Get Flow Message Relationships

KlaviyoBeta::Flows.get_flow_message_relationships(id, related_resource)

Get Flow Relationships

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

Get Flows

KlaviyoBeta::Flows.get_flows(opts)

Update Flow

KlaviyoBeta::Flows.update_flow(id, body)

Lists

Create List

KlaviyoBeta::Lists.create_list(body)

Add Profile to List

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

Delete List

KlaviyoBeta::Lists.delete_list(id)

Remove Profile from List

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

Get List

KlaviyoBeta::Lists.get_list(id, opts)

Get List Profiles

KlaviyoBeta::Lists.get_list_profiles(list_id, opts)

Get List Profile Relationships

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

Get Lists

KlaviyoBeta::Lists.get_lists(opts)

Update List

KlaviyoBeta::Lists.update_list(id, body)

Metrics

Get Metric

KlaviyoBeta::Metrics.get_metric(id, opts)

Get Metric Aggregate

KlaviyoBeta::Metrics.get_metric_aggregate(body)

Get Metrics

KlaviyoBeta::Metrics.get_metrics(opts)

Profiles

Create Profile

KlaviyoBeta::Profiles.create_profile(body)

Get Profile

KlaviyoBeta::Profiles.get_profile(id, opts)

Get Profile Lists

KlaviyoBeta::Profiles.get_profile_lists(profile_id, opts)

Get Profile Relationships

KlaviyoBeta::Profiles.get_profile_relationships(id, related_resource)

Get Profile Segments

KlaviyoBeta::Profiles.get_profile_segments(profile_id, opts)

Get Profiles

KlaviyoBeta::Profiles.get_profiles(opts)

Subscribe Profiles

KlaviyoBeta::Profiles.subscribe_profiles(body)

Suppress Profiles

KlaviyoBeta::Profiles.suppress_profiles(body)

Unsubscribe Profiles

KlaviyoBeta::Profiles.unsubscribe_profiles(body)

Unsuppress Profiles

KlaviyoBeta::Profiles.unsuppress_profiles(body)

Update Profile

KlaviyoBeta::Profiles.update_profile(id, body)

Segments

Get Segment

KlaviyoBeta::Segments.get_segment(id, opts)

Get Segment Profiles

KlaviyoBeta::Segments.get_segment_profiles(segment_id, opts)

Get Segment Relationships

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

Get Segments

KlaviyoBeta::Segments.get_segments(opts)

Update Segment

KlaviyoBeta::Segments.update_segment(id, body)

Templates

Create Template

KlaviyoBeta::Templates.create_template(body)

Create Template Clone

KlaviyoBeta::Templates.create_template_clone(id, body)

Create Template Render

KlaviyoBeta::Templates.create_template_render(id, body)

Delete Template

KlaviyoBeta::Templates.delete_template(id)

Get Template

KlaviyoBeta::Templates.get_template(id, opts)

Get Templates

KlaviyoBeta::Templates.get_templates(opts)

Update Template

KlaviyoBeta::Templates.update_template(id, body)

Appendix

Per Request API key

opts = {
  query_params: {
    'api_key': 'your-api-key',
  },
  debug_auth_names: []
}

response = KlaviyoBeta::Catalogs.get_catalog_items(opts)