Klaviyo

An Elixir library for working with the Klaviyo REST API.

Documentation

Installation

def deps do
[
{:klaviyo, "~> 1.0"}
]
end

Out of the box, this library provides support for hackney as the HTTP client and jason and poison as the JSON codecs. If you plan to utilize these you will need to add them as dependencies to your project.

Making Requests

Klaviyo.Campaign.send("dqQnNW") |> Klaviyo.request()

When making requests to the Track and Identify API's you can expect to receive a response of :success or :failure.

When making requests to all other API's you can expect to receive a response of {:ok, response} or {:error, reason}.

Configuration

This library can be configured globally via Mix or by passing configuration in on a per-request basis.

Mix

This approach is suitable for configuration that is static. If you need to obtain values at runtime (i.e. you need access to environment variables) you will need to provide configuration on a per-request basis.

config :klaviyo, private_api_key: "...",
public_api_key: "..."

Per-request

This approach is suitable if you need to provide different configuration per request or you need to obtain configuration at runtime.

Klaviyo.Campaign.send("dqQnNW") |> Klaviyo.request(private_api_key: "...")

Configuration Options

Authentication

Klaviyo provides different authentication requirements depending on whether you are making a request to a public API (Track and Identify) or a private API (Metrics, Profiles, Lists, Campaigns and Templates).

This library will handle this for you automatically. The only thing you need to do is provide the appropriate API key to the :private_api_key and :public_api_key configuration options.

HTTP Client

This library allows you to use the HTTP client of your choice. We provide support for hackney out-of-the-box. If you would like to use a different client you may implement the Klaviyo.Client behaviour and use your client with the :client configuration option.

As an example, please see Klaviyo.Client.Hackney.

JSON Codec

This library also allows you to use the JSON coded of your choice. We support any library that provides encode!/1 and decode!\1 as the interface for encoding and decoding JSON. As a result, Jason and Poison are supported out-of-the-box. If you would like to use a different JSON codec that does not adhere to this required interface you can wrap it in your own implementation.