Excontentstack
Elixir wrapper for Contentstack's Management API. A simple and idiomatic way to interact with Contentstack from Elixir applications.
Installation
Add excontentstack to your list of dependencies in mix.exs:
def deps do
[
{:excontentstack, "~> 0.6.0"}
]
endThen run:
mix deps.get
Configuration
You can configure Contentstack credentials in your config files:
# config.exs
config :excontentstack,
management_token: System.get_env("CONTENTSTACK_MANAGEMENT_TOKEN"),
api_key: System.get_env("CONTENTSTACK_API_KEY"),
master_locale: "en"For Delivery API access, also add:
config :excontentstack,
delivery_token: System.get_env("CONTENTSTACK_DELIVERY_TOKEN"),
environment: System.get_env("CONTENTSTACK_ENVIRONMENT") || "live"Usage
Management API
The Management API provides full CRUD operations for entries.
client = Excontentstack.Management.new(
management_token: "your_management_token",
api_key: "your_api_key",
master_locale: "en-us"
)
# List entries (single page)
{:ok, entries} = Excontentstack.Management.Entries.list(client, "blog_post")
# Get a specific entry
{:ok, entry} = Excontentstack.Management.Entries.get(client, "blog_post", "entry_uid")
# Create an entry
{:ok, new_entry} = Excontentstack.Management.Entries.create(client, "blog_post", %{
title: "My Blog Post",
content: "This is the content"
})
# Update an entry
{:ok, updated_entry} = Excontentstack.Management.Entries.update(
client,
"blog_post",
"entry_uid",
%{title: "Updated Title"}
)
# Delete an entry
{:ok, _} = Excontentstack.Management.Entries.delete(client, "blog_post", "entry_uid")Delivery API
The Delivery API provides read-only access to published content. It supports the same list, list_all, and get operations as the Management API, plus a stream operation for memory-efficient processing of large result sets.
client = Excontentstack.Delivery.new(
delivery_token: "your_delivery_token",
api_key: "your_api_key",
environment: "live",
master_locale: "en-us"
)
# List entries (single page)
{:ok, entries} = Excontentstack.Delivery.Entries.list(client, "blog_post")
# List all entries across all pages (automatic pagination)
{:ok, all_entries} = Excontentstack.Delivery.Entries.list_all(client, "blog_post")
# Get a specific entry
{:ok, entry} = Excontentstack.Delivery.Entries.get(client, "blog_post", "entry_uid")
# Stream entries lazily — pages are fetched on demand
client
|> Excontentstack.Delivery.Entries.stream("blog_post")
|> Stream.filter(fn entry -> entry["published"] == true end)
|> Stream.map(fn entry -> entry["title"] end)
|> Enum.take(10)
# Stream with options, processing in batches
client
|> Excontentstack.Delivery.Entries.stream("blog_post", params: [locale: "en-us"])
|> Stream.chunk_every(50)
|> Enum.each(fn batch -> process_batch(batch) end)