Powered by AppSignal & Oban Pro

BentoSdk Tags API

livebook/tags_api.livemd

BentoSdk Tags API

Mix.install([
  {:bento_sdk, "~> 0.1.0"}
])

Introduction

This notebook demonstrates how to use the BentoSdk to manage tags in the Bento marketing platform. The Tags API allows you to:

  • Get all tags in your account
  • Create new tags

Tags are a simple named data point you can use to tag subscribers.

Configuration

We’ll use Livebook’s secrets feature to securely store and access your Bento credentials:

# Configure BentoSdk with the secrets
BentoSdk.configure(
  site_uuid: System.fetch_env!("LB_BENTO_SITE_UUID"),
  username: System.fetch_env!("LB_BENTO_USERNAME"),
  password: System.fetch_env!("LB_BENTO_PASSWORD")
)

Getting Tags

You can get all tags in your account:

# Example of getting all tags
case BentoSdk.Tags.get() do
  {:ok, tags} ->
    tags
  {:error, reason} ->
    "Error: #{reason}"
end

Creating Tags

You can create a new tag in your account:

# Example of creating a new tag
tag_name = "new_tag"

case BentoSdk.Tags.create(tag_name) do
  {:ok, tag} ->
    tag
  {:error, reason} ->
    "Error: #{reason}"
end

Tag Structure

The tag structure returned by the API includes:

# Example tag structure
%{
  "id" => "1234",
  "type" => "tags",
  "attributes" => %{
    "name" => "example_tag",
    "created_at" => "2024-08-06T05:44:04.444Z",
    "discarded_at" => nil
  }
}