Giter Site home page Giter Site logo

klaviyo-api-ruby's Introduction

Klaviyo Ruby SDK

  • SDK version: 6.0.0
  • API revision: 2024-02-15

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:

  • Accounts

  • Campaigns

  • Catalogs

  • Coupons

  • Data Privacy

  • Events

  • Flows

  • Images

  • Lists

  • Metrics

  • Profiles

  • Reporting

  • Segments

  • Tags

  • 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-6.0.0.gem

Finally add this to the Gemfile:

gem 'klaviyo-api-sdk', '~> 6.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

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'], # includes
  sort: '-created', # sorting
  filter: 'equals(published,false)', # filters
  page_cursor: 'page_cursor_example', # cursor pagination
  fields_catalog_item: ['external_id','title'], # sparse fieldset
  fields_catalog_variant: ['external_id','title'], # sparse fieldset
  additional_fields_profile: ['predictive_analytics'], # for endpoints that support predictive analytics such as `get_profile`
}

**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)

For uploading a file using the Images.upload_image_from_file simply pass in an opened file

result = KlaviyoAPI::Images.upload_image_from_file(File.open('test_file.jpg', 'r'))

Optional Parameters and Json Api Features

Here we will go over

  • Pagination
  • Page size
  • Additional Fields
  • Filtering
  • Sparse Fields
  • Sorting
  • Relationships

Quick rule

As a reminder, the optional parameters are named slightly different from how you would make the call without the SDK docs, query parameter names have variables that make bad Ruby names like page[cursor] are transformed to page_cursor.

Cursor based Pagination

All the endpoints that return list of results use cursor base pagination.

Obtain the cursor value from the call you want to get the next page for, then pass it under the page_cursor optional parameter. The page cursor looks like WzE2NDA5OTUyMDAsICIzYzRjeXdGTndadyIsIHRydWVd.

If you were using the api directly you would pass the cursor like:

https://a.klaviyo.com/api/profiles/?page[cursor]=WzE2NTcyMTM4NjQsICIzc042NjRyeHo0ciIsIHRydWVd

The same call in the sdk the call would look like this:

opts = {
  page_cursor: 'WzE2NTcyMTM4NjQsICIzc042NjRyeHo0ciIsIHRydWVd',
}

response = KlaviyoAPI::Profiles.get_profiles(opts)

You get the cursor for the next page from response[:links][:next] returns the entire url of the next call but the sdk will accept the entire link and use only the relevant cursor.

Here is an example of getting the second next and passing in the page cursor:

opts = {
  page_cursor: response[:links][:next], # previous response
}

response = KlaviyoAPI::Profiles.get_profiles(opts)

There are more page cursors than just next, check the endpoint's docs or the response type but often there is first, last, next and prev.

Page Size

Some endpoint you can get a larger or smaller page size by using the page_size parameter.

if you were hitting the api directly this would look like

https://a.klaviyo.com/api/profiles/?page[size]=20

In the SDK this looks like:

opts = {
  page_size: 20,
}

response = KlaviyoAPI::Profiles.get_profiles(opts)

Additional Fields

Additional fields are used to populate part of the response that would be null otherwise. For the getProfile endpoint you can pass in a request to get the predictive analytics of the profile. Using the additional_fields parameter often will change the rate limit of the endpoint so be sure to keep an eye on your usage.

The url would look like:

https://a.klaviyo.com/api/profiles/01GDDKASAP8TKDDA2GRZDSVP4H/?additional-fields[profile]=predictive_analytics

The SDK equivalent is:

profile_id = '01GDDKASAP8TKDDA2GRZDSVP4H'
opts = {
  additional_fields_profile: ["predictive_analytics"]
}

response = KlaviyoAPI::Profiles.get_profile(profile_id, opts)

# If your profile has enough information for predictive analytis it will populate
pp(response[:data][:attributes][:predictive_analytics])

Filtering

Filter by passing the filter as a string as under the optional parameter filter.

Read more about formatting your filter strings in our developer documentation

Here is an example of a filter string for results between two date times: less-than(updated,2023-04-26T00:00:00Z),greater-than(updated,2023-04-19T00:00:00Z)

Here is a code example filter for profiles with the matching emails:

https://a.klaviyo.com/api/profiles/?filter=any(email,["[email protected]","[email protected]"]

For the sdk:

opts = {
  filter: 'any(email,["[email protected]","[email protected]"])'
}

response = KlaviyoAPI::Profiles.get_profiles(opts)

Sparse Fields

If you only want a specific subset of data from a specific query you can use sparse fields to request only the specific properties. The SDK expands the optional sparse fields into their own option, where you can pass a list of the desired items to include.

To get a list of event properties the URL your would use is:

https://a.klaviyo.com/api/events/?fields[event]=event_properties

In the SDK you would use

opts = {
  fields_event: ["event_properties"]
}

response = KlaviyoAPI::Events.get_events(opts)

Sorting

Your can request the results of specific endpoints to be ordered by a given parameter. The direction of the sort can swapped by adding a - in front of the sort key. For example datetime will be ascending while -datetime will be descending.

If you are unsure about the available sort fields you can always check the documentation for the endpoint you are using. For a comprehensive list that links to the documentation for each function check the Endpoints section below.

Get events sorted by oldest to newest datetime.

https://a.klaviyo.com/api/events/?sort=-datetime

and via the sdk

opts = {
  sort: '-datetime'
}

response = KlaviyoAPI::Events.get_events(opts)

Includes

How to add additional information to your API response via additional-fields and the includes parameter. This allows you to get information about two or more objects from a single api call. Using the includes parameter often changes the rate limit of the endpoint so be sure to take note.

Using the URl to get profile information and the information about the lists the profile is in:

https://a.klaviyo.com/api/profiles/01GDDKASAP8TKDDA2GRZDSVP4H/?include=lists

In the sdk:

profile_id = '01GDDKASAP8TKDDA2GRZDSVP4H'
opts = {
  include: ["lists"]
}

response = KlaviyoAPI::Profiles.get_profile(profile_id,opts)

# Profile information is accessed the same way with
pp(response[:data])
# Lists related to the profile with be accessible via the included array
pp(response[:included])

Note about sparse fields and relationships: you can request only specific fields of the included object as well.

profile_id = '01GDDKASAP8TKDDA2GRZDSVP4H'
opts = {
  fields_list: ["name"],
  include: ["lists"]
}

response = KlaviyoAPI::Profiles.get_profile(profile_id,opts)



# Profile information is accessed the same way with
pp(response[:data])
# Lists related to the profile with be accessible via the included array
pp(response[:included])

Relationships

The Klaviyo Api has a series of endpoints to expose the relationships between your different Klaviyo Items. You can read more about relationships in our documentation.

Here are some use cases and their examples:

How to get the list memberships for a profile with the given profile ID.

Via the URL:

https://a.klaviyo.com/api/profiles/01GDDKASAP8TKDDA2GRZDSVP4H/relationships/lists/

and for the SDK:

profile_id = '01GDDKASAP8TKDDA2GRZDSVP4H'

response = KlaviyoAPI::Profiles.get_profile_relationships_lists(profile_id)

For another example:

Get all campaigns associated with the given tag_id.

the URL:

https://a.klaviyo.com/api/tags/9c8db7a0-5ab5-4e3c-9a37-a3224fd14382/relationships/campaigns/

Through the SDK:

tag_id = '9c8db7a0-5ab5-4e3c-9a37-a3224fd14382'

response = KlaviyoAPI::Tags.get_tag_relationships_campaigns(tag_id)

Combining

You can use any combination of the features outlines above in conjunction with one another.

Get events associated with a specific metric, then return just the event properties sorted by oldest to newest datetime.

https://a.klaviyo.com/api/events/?fields[event]=event_properties&filter=equals(metric_id,"URDbLg")&sort=-datetime

or

opts = {
  filter: 'equals(metric_id,"URDbLg")',
  fields_event: ["event_properties"]
}

response = KlaviyoAPI::Events.get_events(opts)

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.

Accounts

KlaviyoAPI::Accounts.get_account(id, opts)
KlaviyoAPI::Accounts.get_accounts(opts)

Campaigns

KlaviyoAPI::Campaigns.create_campaign(body)
KlaviyoAPI::Campaigns.create_campaign_clone(body)
KlaviyoAPI::Campaigns.create_campaign_message_assign_template(body)
KlaviyoAPI::Campaigns.create_campaign_recipient_estimation_job(body)
KlaviyoAPI::Campaigns.create_campaign_send_job(body)
KlaviyoAPI::Campaigns.delete_campaign(id)
KlaviyoAPI::Campaigns.get_campaign(id, opts)
KlaviyoAPI::Campaigns.get_campaign_campaign_messages(id, opts)
KlaviyoAPI::Campaigns.get_campaign_message(id, opts)
KlaviyoAPI::Campaigns.get_campaign_message_campaign(id, opts)
KlaviyoAPI::Campaigns.get_campaign_message_relationships_campaign(id)
KlaviyoAPI::Campaigns.get_campaign_message_relationships_template(id)
KlaviyoAPI::Campaigns.get_campaign_message_template(id, opts)
KlaviyoAPI::Campaigns.get_campaign_recipient_estimation(id, opts)
KlaviyoAPI::Campaigns.get_campaign_recipient_estimation_job(id, opts)
KlaviyoAPI::Campaigns.get_campaign_relationships_campaign_messages(id)
KlaviyoAPI::Campaigns.get_campaign_relationships_tags(id)
KlaviyoAPI::Campaigns.get_campaign_send_job(id, opts)
KlaviyoAPI::Campaigns.get_campaign_tags(id, opts)
KlaviyoAPI::Campaigns.get_campaigns(filter, opts)
KlaviyoAPI::Campaigns.update_campaign(id, body)
KlaviyoAPI::Campaigns.update_campaign_message(id, body)
KlaviyoAPI::Campaigns.update_campaign_send_job(id, body)

Catalogs

KlaviyoAPI::Catalogs.create_back_in_stock_subscription(body)
KlaviyoAPI::Catalogs.create_catalog_category(body)
KlaviyoAPI::Catalogs.create_catalog_category_relationships_items(id, body)
KlaviyoAPI::Catalogs.create_catalog_item(body)
KlaviyoAPI::Catalogs.create_catalog_item_relationships_categories(id, body)
KlaviyoAPI::Catalogs.create_catalog_variant(body)
KlaviyoAPI::Catalogs.delete_catalog_category(id)
KlaviyoAPI::Catalogs.delete_catalog_category_relationships_items(id, body)
KlaviyoAPI::Catalogs.delete_catalog_item(id)
KlaviyoAPI::Catalogs.delete_catalog_item_relationships_categories(id, body)
KlaviyoAPI::Catalogs.delete_catalog_variant(id)
KlaviyoAPI::Catalogs.get_catalog_categories(opts)
KlaviyoAPI::Catalogs.get_catalog_category(id, opts)
KlaviyoAPI::Catalogs.get_catalog_category_items(id, opts)
KlaviyoAPI::Catalogs.get_catalog_category_relationships_items(id, opts)
KlaviyoAPI::Catalogs.get_catalog_item(id, opts)
KlaviyoAPI::Catalogs.get_catalog_item_categories(id, opts)
KlaviyoAPI::Catalogs.get_catalog_item_relationships_categories(id, opts)
KlaviyoAPI::Catalogs.get_catalog_item_variants(id, opts)
KlaviyoAPI::Catalogs.get_catalog_items(opts)
KlaviyoAPI::Catalogs.get_catalog_variant(id, opts)
KlaviyoAPI::Catalogs.get_catalog_variants(opts)
KlaviyoAPI::Catalogs.get_create_categories_job(job_id, opts)
KlaviyoAPI::Catalogs.get_create_categories_jobs(opts)
KlaviyoAPI::Catalogs.get_create_items_job(job_id, opts)
KlaviyoAPI::Catalogs.get_create_items_jobs(opts)
KlaviyoAPI::Catalogs.get_create_variants_job(job_id, opts)
KlaviyoAPI::Catalogs.get_create_variants_jobs(opts)
KlaviyoAPI::Catalogs.get_delete_categories_job(job_id, opts)
KlaviyoAPI::Catalogs.get_delete_categories_jobs(opts)
KlaviyoAPI::Catalogs.get_delete_items_job(job_id, opts)
KlaviyoAPI::Catalogs.get_delete_items_jobs(opts)
KlaviyoAPI::Catalogs.get_delete_variants_job(job_id, opts)
KlaviyoAPI::Catalogs.get_delete_variants_jobs(opts)
KlaviyoAPI::Catalogs.get_update_categories_job(job_id, opts)
KlaviyoAPI::Catalogs.get_update_categories_jobs(opts)
KlaviyoAPI::Catalogs.get_update_items_job(job_id, opts)
KlaviyoAPI::Catalogs.get_update_items_jobs(opts)
KlaviyoAPI::Catalogs.get_update_variants_job(job_id, opts)
KlaviyoAPI::Catalogs.get_update_variants_jobs(opts)
KlaviyoAPI::Catalogs.spawn_create_categories_job(body)
KlaviyoAPI::Catalogs.spawn_create_items_job(body)
KlaviyoAPI::Catalogs.spawn_create_variants_job(body)
KlaviyoAPI::Catalogs.spawn_delete_categories_job(body)
KlaviyoAPI::Catalogs.spawn_delete_items_job(body)
KlaviyoAPI::Catalogs.spawn_delete_variants_job(body)
KlaviyoAPI::Catalogs.spawn_update_categories_job(body)
KlaviyoAPI::Catalogs.spawn_update_items_job(body)
KlaviyoAPI::Catalogs.spawn_update_variants_job(body)
KlaviyoAPI::Catalogs.update_catalog_category(id, body)
KlaviyoAPI::Catalogs.update_catalog_category_relationships_items(id, body)
KlaviyoAPI::Catalogs.update_catalog_item(id, body)
KlaviyoAPI::Catalogs.update_catalog_item_relationships_categories(id, body)
KlaviyoAPI::Catalogs.update_catalog_variant(id, body)

Coupons

KlaviyoAPI::Coupons.create_coupon(body)
KlaviyoAPI::Coupons.create_coupon_code(body)
KlaviyoAPI::Coupons.delete_coupon(id)
KlaviyoAPI::Coupons.delete_coupon_code(id)
KlaviyoAPI::Coupons.get_coupon(id, opts)
KlaviyoAPI::Coupons.get_coupon_code(id, opts)
KlaviyoAPI::Coupons.get_coupon_code_bulk_create_job(job_id, opts)
KlaviyoAPI::Coupons.get_coupon_code_bulk_create_jobs(opts)
KlaviyoAPI::Coupons.get_coupon_code_relationships_coupon(id, opts)
KlaviyoAPI::Coupons.get_coupon_codes(opts)
KlaviyoAPI::Coupons.get_coupon_codes_for_coupon(id, opts)
KlaviyoAPI::Coupons.get_coupon_for_coupon_code(id, opts)
KlaviyoAPI::Coupons.get_coupon_relationships_coupon_codes(id)
KlaviyoAPI::Coupons.get_coupons(opts)
KlaviyoAPI::Coupons.spawn_coupon_code_bulk_create_job(body)
KlaviyoAPI::Coupons.update_coupon(id, body)
KlaviyoAPI::Coupons.update_coupon_code(id, body)

Data Privacy

KlaviyoAPI::DataPrivacy.request_profile_deletion(body)

Events

KlaviyoAPI::Events.create_event(body)
KlaviyoAPI::Events.get_event(id, opts)
KlaviyoAPI::Events.get_event_metric(id, opts)
KlaviyoAPI::Events.get_event_profile(id, opts)
KlaviyoAPI::Events.get_event_relationships_metric(id)
KlaviyoAPI::Events.get_event_relationships_profile(id)
KlaviyoAPI::Events.get_events(opts)

Flows

KlaviyoAPI::Flows.get_flow(id, opts)
KlaviyoAPI::Flows.get_flow_action(id, opts)
KlaviyoAPI::Flows.get_flow_action_flow(id, opts)
KlaviyoAPI::Flows.get_flow_action_messages(id, opts)
KlaviyoAPI::Flows.get_flow_action_relationships_flow(id)
KlaviyoAPI::Flows.get_flow_action_relationships_messages(id, opts)
KlaviyoAPI::Flows.get_flow_flow_actions(id, opts)
KlaviyoAPI::Flows.get_flow_message(id, opts)
KlaviyoAPI::Flows.get_flow_message_action(id, opts)
KlaviyoAPI::Flows.get_flow_message_relationships_action(id)
KlaviyoAPI::Flows.get_flow_message_relationships_template(id)
KlaviyoAPI::Flows.get_flow_message_template(id, opts)
KlaviyoAPI::Flows.get_flow_relationships_flow_actions(id, opts)
KlaviyoAPI::Flows.get_flow_relationships_tags(id)
KlaviyoAPI::Flows.get_flow_tags(id, opts)
KlaviyoAPI::Flows.get_flows(opts)
KlaviyoAPI::Flows.update_flow(id, body)

Images

KlaviyoAPI::Images.get_image(id, opts)
KlaviyoAPI::Images.get_images(opts)
KlaviyoAPI::Images.update_image(id, body)
KlaviyoAPI::Images.upload_image_from_file(file, opts)
KlaviyoAPI::Images.upload_image_from_url(body)

Lists

KlaviyoAPI::Lists.create_list(body)
KlaviyoAPI::Lists.create_list_relationships(id, body)
KlaviyoAPI::Lists.delete_list(id)
KlaviyoAPI::Lists.delete_list_relationships(id, body)
KlaviyoAPI::Lists.get_list(id, opts)
KlaviyoAPI::Lists.get_list_profiles(id, opts)
KlaviyoAPI::Lists.get_list_relationships_profiles(id, opts)
KlaviyoAPI::Lists.get_list_relationships_tags(id)
KlaviyoAPI::Lists.get_list_tags(id, opts)
KlaviyoAPI::Lists.get_lists(opts)
KlaviyoAPI::Lists.update_list(id, body)

Metrics

KlaviyoAPI::Metrics.get_metric(id, opts)
KlaviyoAPI::Metrics.get_metrics(opts)
KlaviyoAPI::Metrics.query_metric_aggregates(body)

Profiles

KlaviyoAPI::Profiles.create_or_update_profile(body)
KlaviyoAPI::Profiles.create_profile(body)
KlaviyoAPI::Profiles.create_push_token(body)
KlaviyoAPI::Profiles.get_bulk_profile_import_job(job_id, opts)
KlaviyoAPI::Profiles.get_bulk_profile_import_job_import_errors(id, opts)
KlaviyoAPI::Profiles.get_bulk_profile_import_job_lists(id, opts)
KlaviyoAPI::Profiles.get_bulk_profile_import_job_profiles(id, opts)
KlaviyoAPI::Profiles.get_bulk_profile_import_job_relationships_lists(id)
KlaviyoAPI::Profiles.get_bulk_profile_import_job_relationships_profiles(id, opts)
KlaviyoAPI::Profiles.get_bulk_profile_import_jobs(opts)
KlaviyoAPI::Profiles.get_profile(id, opts)
KlaviyoAPI::Profiles.get_profile_lists(id, opts)
KlaviyoAPI::Profiles.get_profile_relationships_lists(id)
KlaviyoAPI::Profiles.get_profile_relationships_segments(id)
KlaviyoAPI::Profiles.get_profile_segments(id, opts)
KlaviyoAPI::Profiles.get_profiles(opts)
KlaviyoAPI::Profiles.merge_profiles(body)
KlaviyoAPI::Profiles.spawn_bulk_profile_import_job(body)
KlaviyoAPI::Profiles.subscribe_profiles(body)
KlaviyoAPI::Profiles.suppress_profiles(body)
KlaviyoAPI::Profiles.unsubscribe_profiles(body)
KlaviyoAPI::Profiles.unsuppress_profiles(body)
KlaviyoAPI::Profiles.update_profile(id, body)

Reporting

KlaviyoAPI::Reporting.query_campaign_values(body, opts)
KlaviyoAPI::Reporting.query_flow_series(body, opts)
KlaviyoAPI::Reporting.query_flow_values(body, opts)

Segments

KlaviyoAPI::Segments.get_segment(id, opts)
KlaviyoAPI::Segments.get_segment_profiles(id, opts)
KlaviyoAPI::Segments.get_segment_relationships_profiles(id, opts)
KlaviyoAPI::Segments.get_segment_relationships_tags(id)
KlaviyoAPI::Segments.get_segment_tags(id, opts)
KlaviyoAPI::Segments.get_segments(opts)
KlaviyoAPI::Segments.update_segment(id, body)

Tags

KlaviyoAPI::Tags.create_tag(body)
KlaviyoAPI::Tags.create_tag_group(body)
KlaviyoAPI::Tags.create_tag_relationships_campaigns(id, body)
KlaviyoAPI::Tags.create_tag_relationships_flows(id, body)
KlaviyoAPI::Tags.create_tag_relationships_lists(id, body)
KlaviyoAPI::Tags.create_tag_relationships_segments(id, body)
KlaviyoAPI::Tags.delete_tag(id)
KlaviyoAPI::Tags.delete_tag_group(id)
KlaviyoAPI::Tags.delete_tag_relationships_campaigns(id, body)
KlaviyoAPI::Tags.delete_tag_relationships_flows(id, body)
KlaviyoAPI::Tags.delete_tag_relationships_lists(id, body)
KlaviyoAPI::Tags.delete_tag_relationships_segments(id, body)
KlaviyoAPI::Tags.get_tag(id, opts)
KlaviyoAPI::Tags.get_tag_group(id, opts)
KlaviyoAPI::Tags.get_tag_group_relationships_tags(id)
KlaviyoAPI::Tags.get_tag_group_tags(id, opts)
KlaviyoAPI::Tags.get_tag_groups(opts)
KlaviyoAPI::Tags.get_tag_relationships_campaigns(id)
KlaviyoAPI::Tags.get_tag_relationships_flows(id)
KlaviyoAPI::Tags.get_tag_relationships_lists(id)
KlaviyoAPI::Tags.get_tag_relationships_segments(id)
KlaviyoAPI::Tags.get_tag_relationships_tag_group(id)
KlaviyoAPI::Tags.get_tag_tag_group(id, opts)
KlaviyoAPI::Tags.get_tags(opts)
KlaviyoAPI::Tags.update_tag(id, body)
KlaviyoAPI::Tags.update_tag_group(id, body)

Templates

KlaviyoAPI::Templates.create_template(body)
KlaviyoAPI::Templates.create_template_clone(body)
KlaviyoAPI::Templates.create_template_render(body)
KlaviyoAPI::Templates.delete_template(id)
KlaviyoAPI::Templates.get_template(id, opts)
KlaviyoAPI::Templates.get_templates(opts)
KlaviyoAPI::Templates.update_template(id, body)

Appendix

Per Request API key

response = KlaviyoAPI::Catalogs.get_catalog_items({
  header_params: {
    'Authorization': 'Klaviyo-API-Key your-api-key',
  },
  debug_auth_names: []
})

klaviyo-api-ruby's People

Contributors

dano-klaviyo avatar ian-montgomery-klaviyo avatar klaviyo-sdk avatar maple-klaviyo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

klaviyo-api-ruby's Issues

[__NSCFConstantString initialize] may have been in progress in another thread when fork() was called

After adding the klaviyo-api-ruby gem to a Ruby on Rails project and making an API request the following error is thrown which is caused by one of the gem's dependencies (Typhoeus).

[a149eed0-66c7-4910-bf27-747435503690] ETHON: Libcurl initialized
objc[56523]: +[__NSCFConstantString initialize] may have been in progress in another thread when fork() was called.
objc[56523]: +[__NSCFConstantString initialize] may have been in progress in another thread when fork() was called. We cannot safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug.

More information can be found in this issue typhoeus/typhoeus#687.

System configuration
Rails version: Rails 6.1.6.1
Ruby version: ruby 3.0.4p208 (2022-04-12 revision 3fa771dded) [arm64-darwin21]

Is the gem working ?

Getting this error for all the requests with valid credentials

{"errors":[{"id":"f2b6a3ee-9d8b-45f1-87a8-e035418cd5c1","status":401,"code":"not_authenticated","title":"Authentication credentials were not provided.","detail":"Missing or invalid authorization scheme. Please use Klaviyo-API-Key.","source":{"pointer":"/data/"}}]}

README outdated

Hey there!
I'm trying to use this gem and I have some issues

KlaviyoAPI::Events.get_events(opts) => uninitialized constant KlaviyoAPI::Events (NameError) Did you mean?
KlaviyoAPI::EventsApi

probably an outdated README?

Another thing I need to do is to do dynamic api_key and api_secret. This is what I came up, but it still gives me 401

config = KlaviyoAPI::Configuration.new
config.api_key = <API_KEY>
config.access_token = <SECRET_KEY>
api_client = KlaviyoAPI::ApiClient.new(config)

KlaviyoAPI::EventsApi.new(api_client).get_events

Can you help me please?

Cannot get filtering to work

I've been trying to apply filtering to the get_profiles method and it just won't work. As per the example in the README I have used:

KlaviyoAPI::Profiles.get_profiles({filter: 'equals(email,[email protected])'})

But it keeps throwing a 400 error "Invalid filter provided".

It also logs:

ETHON: performed EASY effective_url=https://a.klaviyo.com/api/profiles/?filter=equals%28email%2Cme%40test.com%29 response_code=400 return_code=ok total_time=0.174813

I've been able to make other calls successfully, including this same profiles endpoint without the filter opt.

Version: klaviyo-api-sdk-1.1.0
Ruby version 2.4.0

Is it possible to use OAuth access tokens to make API calls with this gem?

As the title says, is this possible?

Is there an equivalent to the code below using an OAuth access token?
# 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

Getting error when passing body object

I'm getting this error:

Response body: {"errors":[{"id":"51c07451-b09a-4e77-a460-13cd0b920a28","status":400,"code":"invalid","title":"Invalid input.","detail":"The payload provided in the request is invalid.","source":{"pointer":"/data"},"meta":{}}]}

When trying to call:

@event = KlaviyoAPI::Events.create_event(body)

My body object looks like this:

body = {
	data: {
		type: 'event',
		attributes: {
			properties: {
				registryID: @registry.id,
				registryKind: @registry.kind
			},
			time: DateTime.now.new_offset(0).iso8601,
			value: 0,
			metric: {
				data: {
					type: 'metric',
					attributes: {
						name: "Created Registry"
					}
				}
			},
			profile: @profile
		}
	}
}

Any idea what the issue is?

get_list api does not support additional_fields

We are trying to use the get_list API to get a count of the number of profiles in a list, but profile_count is not returned.

The get_list API endpoint v2023-06-15 does support query params with additional_fields, but the ruby gem does not support these.

Sample ruby code:

opts = {
      additional_fields_list: ["profile_count"]
}
KlaviyoAPI::Lists.get_list("abcde", opts)

The call is successful, and we do get the list in the response, but without the additional fields requested. Output when debugging has been enabled on the gem:

ETHON: performed EASY effective_url=https://a.klaviyo.com/api/lists/abcde/ response_code=200 return_code=ok total_time=0.257708

Looking in lists_api.rb, neither get_list nor get_list_with_http_info accept the additional_fields options.

klaivyo-api-ruby version: 3.0.0
API endpoint version:v2023-06-15

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.