Excontentstack.Management.Entries (Excontentstack v0.5.1)

Operations on entries.

Summary

Functions

Creates a new entry for a given content type.

Retrieves a single entry by content type and entry UID.

Lists entries for a given content type.

Lists all entries for a given content type, handling pagination automatically.

Publishes an entry to one or more environments.

Streams all entries for a given content type with lazy, memory-efficient pagination.

Unpublishes an entry from one or more environments.

Functions

create(client, content_type_uid, data, opts \\ [])

Creates a new entry for a given content type.

delete(client, content_type_uid, entry_uid, opts \\ [])

Deletes an entry by UID.

Returns the API response payload as-is. For successful deletes, Contentstack may return only a notice message

Options

  • :params - additional query params

Examples

iex> Excontentstack.Management.Entries.delete(client, "content_type_index", "entry_uid")
{:ok, %{"notice" => "Entry deleted successfully."}}

get(client, content_type_uid, entry_uid, opts \\ [])

Retrieves a single entry by content type and entry UID.

list(client, content_type_uid, opts \\ [])

Lists entries for a given content type.

Returns a single page of entries. Use list_all/3 to automatically fetch all entries across multiple pages.

Options:

  • :params – query params like :limit, :skip, :include, etc.
  • :raw – if true, returns full response metadata

Returns {:ok, %{entries: [...]}} or {:error, reason}.

list_all(client, content_type_uid, opts \\ [])

Lists all entries for a given content type, handling pagination automatically.

Fetches all pages and returns the complete dataset. For large content types, consider using list/3 with manual pagination instead.

Options:

  • :params – query params like :include, :locale, etc. Note: If :limit is provided and less than 100, only one request is made.

Returns {:ok, entries} or {:error, reason}.

Examples

# Fetch all entries
{:ok, all_entries} = Entries.list_all(client, "blog_post")

publish(client, content_type_uid, entry_uid, publish_opts, opts \\ [])

Publishes an entry to one or more environments.

publish_opts

  • :environments (required) – list of environment names to publish to
  • :locales – list of locale codes to publish
  • :locale – locale code; defaults to the client's master locale
  • :version – entry version to publish
  • :scheduled_at – ISO 8601 datetime to schedule the publish

Options

  • :params – additional query params (e.g. publish_all_localized: true)

Examples

Entries.publish(client, "blog_post", "entry_uid", %{
  environments: ["production"],
  locales: ["en-us"]
})

# Scheduled publish
Entries.publish(client, "blog_post", "entry_uid", %{
  environments: ["staging"],
  version: 2,
  scheduled_at: "2030-12-31T23:59:59.000Z"
})

stream(client, content_type_uid, opts \\ [])

Streams all entries for a given content type with lazy, memory-efficient pagination.

Returns a Stream that fetches entries on-demand page-by-page (100 entries per page). This is ideal for processing large content types without loading everything into memory.

Unlike list_all/3 which loads all entries upfront, stream/3 only fetches pages as they are consumed, enabling early termination and memory-efficient pipelines.

Options

  • :params – query params like :include, :locale, etc. Note: :limit and :skip are managed internally for pagination and will be overridden.

Returns

Returns an Enumerable.t() (Stream) that yields individual entries.

Errors during stream consumption will raise a RuntimeError. Validate inputs before consuming the stream to catch configuration errors early.

Examples

# Batch processing with chunking
client
|> Entries.stream("blog_post", params: [locale: "en-us"])
|> Stream.chunk_every(50)
|> Enum.each(fn batch -> process_batch(batch) end)

# Early termination - only fetches first page
client
|> Entries.stream("blog_post")
|> Enum.take(10)

# Filter and transform pipeline
client
|> Entries.stream("blog_post")
|> Stream.filter(fn entry -> entry["published"] == true end)
|> Stream.map(fn entry -> entry["title"] end)
|> Enum.to_list()

# Process and discard
stream(client, "blog")
|> Stream.each(&send_to_analytics/1)
|> Stream.run() # Nothing kept in memory

# Filter before materializing
stream(client, "blog")
|> Stream.filter(&published?/1)
|> Enum.to_list()

# Avoid this - it defeats the purpose of streaming
client
|> Entries.stream("blog_post")
|> Enum.to_list()

unpublish(client, content_type_uid, entry_uid, unpublish_opts, opts \\ [])

Unpublishes an entry from one or more environments.

Accepts the same options map as publish/5.

Options

  • :params – additional query params (e.g. publish_all_localized: true)

Examples

Entries.unpublish(client, "blog_post", "entry_uid", %{
  environments: ["production"],
  locales: ["en-us"]
})

update(client, content_type_uid, entry_uid, data, opts \\ [])

Updates an existing entry.