BentoSdk Fields API
Mix.install([
{:bento_sdk, "~> 0.1.0"}
])
Introduction
This notebook demonstrates how to use the BentoSdk to manage fields in the Bento marketing platform. The Fields API allows you to:
- Get all fields in your account
- Create new fields
Fields are simple named key-value pairs, think of them as form fields.
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 Fields
You can get all fields in your account:
# Example of getting all fields
case BentoSdk.Fields.get() do
{:ok, fields} ->
fields
{:error, reason} ->
"Error: #{reason}"
end
Creating Fields
You can create a new field in your account:
# Example of creating a new field
field_key = "company"
case BentoSdk.Fields.create(field_key) do
{:ok, field} ->
field
{:error, reason} ->
"Error: #{reason}"
end
Field Structure
The field structure returned by the API includes:
# Example field structure
%{
"id" => "1234",
"type" => "fields",
"attributes" => %{
"key" => "company",
"created_at" => "2024-08-06T05:44:04.444Z",
"discarded_at" => nil
}
}