Create, schedule, publish, and inspect posts.
{:ok, post} =
FoPost.Posts.create(client,
workspace_id: workspace.id,
content: "Hello from Elixir",
accounts: [account.id]
)
{:ok, result} = FoPost.Posts.publish(client, post.id):content takes a string for a single block, or a list for a thread. A block may also
be a map of text plus media:
FoPost.Posts.create(client,
workspace_id: workspace.id,
accounts: [account.id],
content: [
"First post in the thread",
%{text: "Second one, with an image", media: [%{type: "image", url: url}]}
]
):accounts takes account ids, FoPost.Account structs, or maps carrying an id.
:status is "draft" or "scheduled"; a scheduled post needs :schedule_at, which
accepts a DateTime, a NaiveDateTime, or an ISO 8601 string. To send something out
now, create it and call publish/3 — publishing answers when delivery is queued, not
when the post is live.
Summary
Functions
A post's performance across the platforms it reached.
Same as analytics/2, but raises FoPost.Error.
Removes a selection of posts in one transaction.
Same as bulk_delete/2, but raises FoPost.Error.
Relabels a selection.
Same as bulk_label/2, but raises FoPost.Error.
Moves a selection's schedule by :offset_minutes, which may be negative but never zero.
Same as bulk_shift/2, but raises FoPost.Error.
Stops the deliveries that have not gone out yet.
Same as cancel/3, but raises FoPost.Error.
Creates the posts a CSV describes. Keep the batch id to roll the import back.
Same as commit_bulk_import/2, but raises FoPost.Error.
Composes a draft or a scheduled post.
Same as create/2, but returns the post or raises FoPost.Error.
Removes a post.
Same as delete/2, but raises FoPost.Error.
The current delivery record for each account the post targets.
Same as deliveries/2, but raises FoPost.Error.
Copies a post into a new draft.
Same as duplicate/2, but raises FoPost.Error.
One post.
Same as get/2, but returns the post or raises FoPost.Error.
One page of posts.
Same as list/2, but returns the page or raises FoPost.Error.
Checks a post against every platform it targets, without publishing.
Same as preflight/2, but raises FoPost.Error.
Queues a post for delivery to its accounts.
Same as publish/3, but raises FoPost.Error.
Every publish attempt made for a post, newest first.
Same as publish_runs/2, but raises FoPost.Error.
Re-sends the deliveries that failed, leaving the successful ones alone.
Same as retry/3, but raises FoPost.Error.
Deletes every post a committed batch created.
Same as rollback_bulk_import/2, but raises FoPost.Error.
Every matching post as a lazy stream, fetching one page at a time.
Edits a post that has not been published.
Same as update/3, but returns the post or raises FoPost.Error.
Dry-runs a CSV import and reports per-row results without creating anything.
Same as validate_bulk_import/2, but raises FoPost.Error.
Functions
@spec analytics(FoPost.Client.t(), String.t()) :: {:ok, FoPost.PostAnalytics.t()} | {:error, FoPost.Error.t()}
A post's performance across the platforms it reached.
Same as analytics/2, but raises FoPost.Error.
@spec bulk_delete( FoPost.Client.t(), keyword() ) :: {:ok, FoPost.BulkResult.t()} | {:error, FoPost.Error.t()}
Removes a selection of posts in one transaction.
Same as bulk_delete/2, but raises FoPost.Error.
@spec bulk_label( FoPost.Client.t(), keyword() ) :: {:ok, FoPost.BulkResult.t()} | {:error, FoPost.Error.t()}
Relabels a selection.
:mode is "replace" (the default, where an empty :label_ids clears them), "add",
or "remove".
Same as bulk_label/2, but raises FoPost.Error.
@spec bulk_shift( FoPost.Client.t(), keyword() ) :: {:ok, FoPost.BulkResult.t()} | {:error, FoPost.Error.t()}
Moves a selection's schedule by :offset_minutes, which may be negative but never zero.
Only drafts and scheduled posts can be shifted, and one ineligible post in the selection changes nothing at all.
Same as bulk_shift/2, but raises FoPost.Error.
@spec cancel(FoPost.Client.t(), String.t(), keyword()) :: {:ok, FoPost.PublishResult.t()} | {:error, FoPost.Error.t()}
Stops the deliveries that have not gone out yet.
Pass :account_ids to cancel only some of them.
Same as cancel/3, but raises FoPost.Error.
@spec commit_bulk_import( FoPost.Client.t(), keyword() ) :: {:ok, FoPost.BulkImportResult.t()} | {:error, FoPost.Error.t()}
Creates the posts a CSV describes. Keep the batch id to roll the import back.
Same as commit_bulk_import/2, but raises FoPost.Error.
@spec create( FoPost.Client.t(), keyword() ) :: {:ok, FoPost.Post.t()} | {:error, FoPost.Error.t()}
Composes a draft or a scheduled post.
Required: :workspace_id, :content, :accounts. Optional: :status,
:schedule_at, :content_type, :artifact_type, :labels, :title,
:internal_title, :summary, :auto_plug, :auto_plug_content, :settings,
:repeatable, :repeatable_times, :repeatable_gap, :repeatable_gap_unit,
:source_ids, :companion_of.
Same as create/2, but returns the post or raises FoPost.Error.
@spec delete(FoPost.Client.t(), String.t()) :: {:ok, FoPost.Message.t()} | {:error, FoPost.Error.t()}
Removes a post.
Same as delete/2, but raises FoPost.Error.
@spec deliveries(FoPost.Client.t(), String.t()) :: {:ok, [FoPost.Delivery.t()]} | {:error, FoPost.Error.t()}
The current delivery record for each account the post targets.
Same as deliveries/2, but raises FoPost.Error.
@spec duplicate(FoPost.Client.t(), String.t()) :: {:ok, FoPost.Post.t()} | {:error, FoPost.Error.t()}
Copies a post into a new draft.
Same as duplicate/2, but raises FoPost.Error.
@spec get(FoPost.Client.t(), String.t()) :: {:ok, FoPost.Post.t()} | {:error, FoPost.Error.t()}
One post.
Same as get/2, but returns the post or raises FoPost.Error.
@spec list( FoPost.Client.t(), keyword() ) :: {:ok, FoPost.Page.t()} | {:error, FoPost.Error.t()}
One page of posts.
Filters: :workspace_id, :status, :search, :platform, :label, :account_id,
:date, :from, :to, :sort. Paging: :page, :per_page. Anything left out keeps
the API's own default.
{:ok, page} = FoPost.Posts.list(client, workspace_id: id, status: "published")
page.meta.total
Same as list/2, but returns the page or raises FoPost.Error.
@spec preflight(FoPost.Client.t(), String.t()) :: {:ok, FoPost.PreflightResult.t()} | {:error, FoPost.Error.t()}
Checks a post against every platform it targets, without publishing.
Same as preflight/2, but raises FoPost.Error.
@spec publish(FoPost.Client.t(), String.t(), keyword()) :: {:ok, FoPost.PublishResult.t()} | {:error, FoPost.Error.t()}
Queues a post for delivery to its accounts.
Nothing reaches a platform without this call or a schedule the user set. Options:
:account_ids— publish to a subset of the post's accounts:dry_run— validate everything without sending anything to a platform
Same as publish/3, but raises FoPost.Error.
@spec publish_runs(FoPost.Client.t(), String.t()) :: {:ok, [FoPost.PublishRun.t()]} | {:error, FoPost.Error.t()}
Every publish attempt made for a post, newest first.
Same as publish_runs/2, but raises FoPost.Error.
@spec retry(FoPost.Client.t(), String.t(), keyword()) :: {:ok, FoPost.PublishResult.t()} | {:error, FoPost.Error.t()}
Re-sends the deliveries that failed, leaving the successful ones alone.
Options: :account_ids, :include_published.
Same as retry/3, but raises FoPost.Error.
@spec rollback_bulk_import(FoPost.Client.t(), String.t()) :: {:ok, FoPost.Message.t()} | {:error, FoPost.Error.t()}
Deletes every post a committed batch created.
Same as rollback_bulk_import/2, but raises FoPost.Error.
@spec stream( FoPost.Client.t(), keyword() ) :: Enumerable.t()
Every matching post as a lazy stream, fetching one page at a time.
Takes the same filters as list/2. Because a stream cannot answer with an error tuple,
a failed page raises FoPost.Error.
client
|> FoPost.Posts.stream(workspace_id: id)
|> Stream.filter(&(&1.status == "published"))
|> Enum.take(10)
@spec update(FoPost.Client.t(), String.t(), keyword()) :: {:ok, FoPost.Post.t()} | {:error, FoPost.Error.t()}
Edits a post that has not been published.
Only the keys you pass are sent, so this stays a partial update. Passing a key as nil
sends null, which is how a field is cleared.
Same as update/3, but returns the post or raises FoPost.Error.
@spec validate_bulk_import( FoPost.Client.t(), keyword() ) :: {:ok, FoPost.BulkImportValidation.t()} | {:error, FoPost.Error.t()}
Dry-runs a CSV import and reports per-row results without creating anything.
:file is a path, a {filename, content} tuple, or a map of :filename and
:content.
Same as validate_bulk_import/2, but raises FoPost.Error.