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
:client- HTTP client to make requests with. Defaults toKlaviyo.Client.Hackney.:client_opts- options to pass to the HTTP client when making a request.:host- host to make requests to. Defaults toa.klaviyo.com.:json_codec- JSON encoder and decoder. Defaults toJason.:port- HTTP port to send requests over. Defaults tonil.:private_api_key- API key provided by Klaviyo for making requests to the Metrics, Profiles, Lists, Campaigns and Templates API's.:protocol- HTTP protocol used when making requests. Defaults tohttps.:public_api_key- API key provided by Klaviyo for making requests to the Identify and Track API's.
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.