BentoSdk Broadcasts API
Mix.install([
{:bento_sdk, "~> 0.1.0"}
])
Introduction
This notebook demonstrates how to use the BentoSdk to work with broadcasts in the Bento marketing platform. The Broadcasts API allows you to:
- Get a list of broadcasts
- Create new broadcasts
Broadcasts are a powerful way to send emails to segments of your 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 Broadcasts
Let’s get a list of all broadcasts:
# Example of getting all broadcasts
case BentoSdk.Broadcasts.get() do
{:ok, broadcasts} ->
broadcasts
{:error, reason} ->
"Error: #{reason}"
end
Creating Broadcasts
Let’s create a new broadcast:
# Example of creating a broadcast
broadcast = %{
name: "Summer Sale Announcement",
subject: "Summer Sale - 20% Off Everything!",
content: "Our summer sale is now on! Get 20% off everything until the end of the month.
",
type: "plain",
from: %{
email: "sales@example.com",
name: "Example Store"
},
inclusive_tags: "lead,mql",
exclusive_tags: "customers",
segement_id: "segment_123456789",
batch_size_per_hour: 1500
}
# The create_broadcasts function expects a list of broadcasts
case BentoSdk.Broadcasts.create([broadcast]) do
{:ok, result} ->
result
{:error, reason} ->
"Error: #{reason}"
end