Skip to content

About

Official Rust client for the FoPost API — schedule and publish social posts, manage accounts, media, and analytics. https://fopost.com

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

fopost

crates.io docs.rs license ci

Official Rust SDK for the FoPost API. Schedule and publish to +30 social platforms from your code.

[dependencies]
fopost = "0.3"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }

Async, built on reqwest. Requires Rust 1.88 or newer.

0.x release. The public API is still settling and minor versions may contain breaking changes. Pin an exact version if that matters to you.

Quick start

use fopost::{models::CreatePost, Client};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::from_env()?; // reads FOPOST_API_KEY

    // Everything is scoped to a workspace.
    let workspaces = client.workspaces().list().await?;
    let workspace = &workspaces[0];

    let accounts = client.accounts().list(Some(&workspace.id)).await?;
    let ids: Vec<_> = accounts.iter().map(|a| a.id.clone()).collect();

    // Create a post, then publish it immediately.
    let post = client
        .posts()
        .create(&CreatePost::text(&workspace.id, "Hello from Rust").accounts(ids.clone()))
        .await?;
    client.posts().publish(&post.id, &Default::default()).await?;

    // Or schedule it for later.
    client
        .posts()
        .create(
            &CreatePost::text(&workspace.id, "Scheduled with the SDK")
                .accounts(ids)
                .schedule_at("2026-09-01T10:00:00Z"),
        )
        .await?;

    Ok(())
}

Configuration

use std::time::Duration;

let client = fopost::Client::builder()
    .api_key(std::env::var("FOPOST_API_KEY")?)
    .base_url("https://api.fopost.com/v1") // override for another deployment
    .timeout(Duration::from_secs(30))
    .max_retries(3)                        // 1 disables retrying
    .build()?;
# Ok::<(), Box<dyn std::error::Error>>(())
Env var Used for
FOPOST_API_KEY The API key Client::from_env() reads

Keys are created in the dashboard under Settings → API Keys. A key carries only the scopes granted at creation and may be bound to a single workspace, in which case naming any other workspace answers 403.

Resources

Namespace Methods
posts() list, list_all, get, create, create_with_files, update, update_with_files, delete, duplicate, publish, unpublish, retry, cancel, preflight, deliveries, publish_runs, analytics, bulk, validate_import, commit_import, rollback_import
accounts() list, list_with, get, create, rename, move_to, delete, toggle_primary, validate, health, health_summary, refresh_token, analytics, communities, sync_communities, search_communities, add_community, remove_community, create_telegram_connect_code, telegram_connect_status, telegram_bot_commands, set_telegram_bot_commands, delete_telegram_bot_commands, slack_channels, slack_members, slack_identity, update_slack_identity, reddit_subreddits, reddit_subreddit_rules, reddit_flairs, set_reddit_default_subreddit, follow_x_user, unfollow_x_user, ice_breakers, set_ice_breakers, delete_ice_breakers, persistent_menu, set_persistent_menu, delete_persistent_menu, greeting, set_greeting, delete_greeting, webhook_subscription, resubscribe_webhook, discord_channels, switch_discord_channel, discord_identity, update_discord_identity, discord_pins, delete_discord_message, pin_discord_message, unpin_discord_message, crosspost_discord_message, create_discord_thread, send_discord_dm, discord_events, discord_event, create_discord_event, update_discord_event, delete_discord_event, discord_members, discord_member, discord_roles, create_discord_role, update_discord_role, delete_discord_role, add_discord_member_role, remove_discord_member_role, platform_metrics
account_groups() list, get, create, update, delete, set_members
workspaces() list, get, create, update, delete, analytics
labels() list, get, create, update, delete
webhooks() list, create, update, delete, test, deliveries, delivery, redeliver
automations() list, get, create, update, delete, toggle, runs, get_run, stats, trigger, versions, version, restore_version
analytics() overview, time_series, top_posts, labels, posts_table, posting_streak, demographics, collect, decay, frequency, timeline, changes, collect_post, native_posts, inbox
media() list, limits, upload, presign, complete, upload_direct, upload_direct_with, generate_alt_text, delete
designs() list, create, get, update, delete, versions, restore_version, duplicate, export, bulk, posts, text_to_slides, from_post
fonts() list, upload, delete
video_edits() ops, list, create, get
contacts() list, get, create, update, delete, conversations, import, list_fields, create_field, update_field, delete_field, conversation_analytics
broadcasts() list, get, create, update, delete, send, cancel, recipients
sequences() list, get, create, update, delete, enroll, unenroll, enrollments
inbox() list, threads, conversations, unread_count, accounts, platforms, mark_thread_read, resolve, refresh, update, edit_comment, reply, reply_with, hide, unhide, delete, like, unlike, repost, unrepost, bookmark, unbookmark, vote, pin, unpin, react, start_conversation, set_typing, handover, approvals, approve_reply, reject_reply, get_x_post, search_x_posts
ads() list, external, boostable, connections, sources, authorize_meta, delete_connection, boost, create, refresh, set_status, delete, audiences, create_audience, search_targeting, lead_forms, create_lead_form, leads, set_statuses, audience, update_audience, delete_audience, add_audience_users, estimate_reach, insights, ad_insights, lead_form, archive_lead_form, leads_feed, lead_pages, subscribe_lead_page, unsubscribe_lead_page, goals, reach_frequency, create_reach_frequency, reach_frequency_prediction, reserve_reach_frequency, cancel_reach_frequency, partnership_creators, request_partnership, revoke_partnership, account_activity, labels, create_label, update_label, delete_label, apply_label, studies, create_study, study, delete_study, ios_campaign_limits, high_demand_periods, create_high_demand_period, delete_high_demand_period, value_rule_sets, create_value_rule_set, delete_value_rule_set
knowledge() list, create, update, delete, sync, search
inbox() list, threads, conversations, unread_count, accounts, platforms, mark_thread_read, resolve, refresh, update, edit_comment, reply, reply_with, hide, unhide, delete, like, unlike, repost, unrepost, bookmark, unbookmark, vote, pin, unpin, react, start_conversation, set_typing, approvals, approve_reply, reject_reply, get_x_post, search_x_posts
ads() list, external, boostable, connections, sources, providers, authorize, delete_connection, boost, create, refresh, set_status, delete, audiences, create_audience, search_targeting, lead_forms, create_lead_form, leads, set_statuses, audience, update_audience, delete_audience, add_audience_users, add_audience_companies, estimate_reach, insights, ad_insights, lead_form, archive_lead_form, leads_feed, lead_pages, subscribe_lead_page, unsubscribe_lead_page, bid_pricing, supply_forecast, conversion_rules, create_conversion_rule, conversion_rule, update_conversion_rule, delete_conversion_rule, attach_conversion_rule, detach_conversion_rule, conversion_metrics, send_conversion_events, upload_conversions, send_conversions, conversion_batches, pixels, create_pixel, pixel, update_pixel, share_pixel, pixel_stats, event_match_quality, custom_conversions, create_custom_conversion, custom_conversion, update_custom_conversion, delete_custom_conversion
google_business() get_location, update_location, get_attributes, update_attributes, get_menus, replace_menus, get_services, replace_services, list_media, add_media, delete_media, list_place_actions, create_place_action, update_place_action, delete_place_action, get_verification_options, start_verification, complete_verification, get_performance, get_search_keywords, assign
validate() post, length, media, subreddit
whatsapp() profile, update_profile, request_display_name, set_username, templates, template_library, template, create_template, import_template, update_template, delete_template, groups, create_group, group, update_group, delete_group, group_invite_link, reset_group_invite_link, remove_group_participants, blocked, block_users, unblock_users, commerce_settings, update_commerce_settings, link_catalog, flows, flow, create_flow, update_flow, delete_flow, upload_flow_json, publish_flow, deprecate_flow, flow_responses, encryption_key_status, set_encryption_key, account_events, sandbox_sessions, create_sandbox_session
blogs() list_blogs, list_articles, get_article, create_article, update_article, delete_article, list_products, update_product
activity() list
queue() slots, create_slot, update_slot, delete_slot, next, preview
connect_sessions() create, get
logs() list

account_groups() needs the accounts scope. inbox(), knowledge(), contacts(), broadcasts() and sequences() need the inbox scope (and publish on broadcasts().send/cancel and sequences().enroll/unenroll, which reach a platform), except contacts().conversation_analytics, which needs analytics and ads() the ads scope; boost, create, set_status, delete and set_statuses on ads() spend money and also need publish. On inbox(), edit_comment, like, unlike, repost, unrepost, bookmark, unbookmark, vote, pin, unpin, react, start_conversation, set_typing, handover, a reply_with carrying media or quick replies, and deleting our own reply also need publish, as do accounts().follow_x_user and unfollow_x_user. inbox().get_x_post and search_x_posts read X live with the named account's token and need only inbox; every X repost, bookmark, follow, lookup and search is an X API call metered to the workspace, and an X account connected before these shipped answers 409 reconnect_required until it is reconnected. A boost or ad starts paused unless you pass .paused(false). validate() needs the posts scope and stores nothing. designs(), fonts(), video_edits() and media().generate_alt_text need the posts scope; text_to_slides, generate_alt_text and the AI video operations use AI credits, and a video edit runs in the background, so read it back with video_edits().get until status is succeeded or failed. On google_business() the reads need accounts and every write needs publish as well; every call fails with a 503 configuration_error until Google grants the deployment Business Profile API access, and responses relay Google's own shape as serde_json::Value.

That is every endpoint the API documents. Anything not yet wrapped is reachable through client.request(method, path, query, body), which gets the same auth, retries, and error handling.

Analytics

use fopost::models::{AnalyticsQuery, MetricChangesQuery, NativePostsQuery};

# async fn run(client: fopost::Client, post: fopost::models::Post, accounts: Vec<fopost::models::Account>) -> Result<(), fopost::Error> {
# fn save(_changes: &[fopost::models::MetricChange]) {}
// How long a post keeps earning, from the repeated readings of each post
let decay = client.analytics().decay(&AnalyticsQuery::new().days(30)).await?;
println!("{:?}", decay.half_life_bucket); // Some("1h_3h")

// Whether posting more earned more
let cadence = client.analytics().frequency(&AnalyticsQuery::new().days(90)).await?;
if let Some(best) = &cadence.best {
    println!("{}", best.label); // "3-5 a week"
}

// Every reading held for one post, with what moved between them
let timeline = client.analytics().timeline(&post.id).await?;

// Mirror the metrics into your own store, without refetching everything
let mut query = MetricChangesQuery::new();
loop {
    let page = client.analytics().changes(&query).await?;
    save(&page.changes);
    match (page.has_more, page.cursor) {
        (true, Some(cursor)) => query = MetricChangesQuery::new().since(cursor),
        _ => break,
    }
}

// Refresh one post now instead of waiting for the next collection run
client.analytics().collect_post(&post.id).await?;

// Posts on the account that never went out through FoPost
let native = client
    .analytics()
    .native_posts(&accounts[0].id, &NativePostsQuery::new())
    .await?;
# let _ = (timeline, native);
# Ok(())
# }

A post is addressed by its FoPost id or by its permalink, so a post made by hand on the network works the same way:

# async fn run(client: fopost::Client) -> Result<(), fopost::Error> {
client.analytics().timeline("https://x.com/acme/status/1").await?;
# Ok(())
# }

Error handling

Every call returns Result<T, fopost::Error>. A non-2xx response becomes Error::Api, carrying the status, the API's machine-readable code, and the whole body.

use fopost::Error;

# async fn run(client: fopost::Client) {
match client.posts().publish("9b2f6c1e-…", &Default::default()).await {
    Ok(outcome) => println!("{} deliveries queued", outcome.deliveries().len()),
    Err(Error::Api(err)) if err.is_payment_required() => {
        println!("Out of room on this plan — upgrade at {:?}", err.upgrade_url());
    }
    Err(Error::Api(err)) if err.is_rate_limited() => {
        println!("Rate limited, retry in {:?}s", err.retry_after);
    }
    Err(err) => eprintln!("{err}"),
}
# }

Requests are rate limited per key, per minute. A 429 is retried automatically, waiting for the interval the API asks for in Retry-After, up to max_retries attempts.

Publishing safely

publish in dry-run mode, and preflight, both report what would happen without sending anything:

use fopost::models::{PublishOptions, PublishOutcome};

# async fn run(client: fopost::Client, post_id: &str) -> Result<(), fopost::Error> {
// Hard blockers per account, plus advisory content signals.
let check = client.posts().preflight(post_id).await?;
if !check.ready {
    for account in &check.accounts {
        for issue in &account.issues {
            println!("{}: {issue}", account.platform.as_deref().unwrap_or("?"));
        }
    }
}

// Or run the publish path itself without anything leaving the building.
let outcome = client.posts().publish(post_id, &PublishOptions::new().dry_run()).await?;
assert!(matches!(outcome, PublishOutcome::DryRun(_)));
# Ok(()) }

Media

Media upload and bulk CSV import post multipart bodies, which the multipart feature covers. It is on by default.

use fopost::models::{ContentBlock, CreatePost, MediaItem, MediaType, MediaUpload};

# async fn run(client: fopost::Client, workspace_id: &str) -> Result<(), fopost::Error> {
let bytes = std::fs::read("card.png").unwrap();
let uploaded = client
    .media()
    .upload(workspace_id, [MediaUpload::new("card.png", "image/png", bytes)])
    .await?;

let block = ContentBlock::text("Ship it").with_media([MediaItem::new(
    MediaType::Image,
    &uploaded[0].name,
    &uploaded[0].url,
)
.alt("A product screenshot")]);

client.posts().create(&CreatePost::new(workspace_id, [block])).await?;
# Ok(()) }

Larger files can skip the API and go straight to storage. upload_direct reserves a slot with presign, PUTs the bytes to the returned url with the returned headers and no API key, then calls complete to land the file in the library. It needs no Cargo feature. upload_direct_with takes the full PresignUpload (folder, origin, brand role, brand voice, person consent) and a FileSource; a path is streamed from disk, so a 5 GB video never sits in memory.

use fopost::models::{BrandRole, FileSource, PresignUpload};

# async fn run(client: fopost::Client, workspace_id: &str) -> Result<(), fopost::Error> {
let bytes = std::fs::read("clip.mp4").unwrap();
let uploaded = client
    .media()
    .upload_direct(workspace_id, "clip.mp4", "video/mp4", bytes)
    .await?;
println!("{}", uploaded.url);

let input = PresignUpload::new(workspace_id, "logo.png", "image/png", 0).brand_role(BrandRole::Logo);
let logo = client
    .media()
    .upload_direct_with(input, FileSource::Path("logo.png".into()))
    .await?;
println!("{}", logo.url);
# Ok(()) }

Files on posts

create_with_files and update_with_files take up to five MediaFiles and attach them to the post's first content block. Files at or under the account's multipart ceiling travel in the same request; bigger ones are uploaded directly and attached by url. The post that comes back is the same either way. Both need the multipart feature.

use fopost::models::{CreatePost, MediaFile};

# async fn run(client: fopost::Client, workspace_id: &str) -> Result<(), fopost::Error> {
let post = client
    .posts()
    .create_with_files(
        &CreatePost::text(workspace_id, "Ship it").accounts(["acc_1"]),
        vec![MediaFile::from_path("clip.mp4", "video/mp4")],
    )
    .await?;
println!("{}", post.id);
# Ok(()) }

Upload limits

limits says what the account may upload: max_file_bytes is the ceiling by any route (it grows with connected accounts, or with the Large Uploads add-on), multipart_max_file_bytes is what a single multipart request carries per file, and next_tier is what more accounts would unlock. A file over the ceiling is a 413 file_too_large; ApiError::max_file_bytes() reads the limit it broke.

# async fn run(client: fopost::Client, workspace_id: &str) -> Result<(), fopost::Error> {
let limits = client.media().limits(Some(workspace_id)).await?;
println!("{} bytes per file", limits.max_file_bytes);

match client.media().upload_direct(workspace_id, "huge.mp4", "video/mp4", vec![]).await {
    Err(fopost::Error::Api(api)) if api.is_file_too_large() => {
        println!("too big, the ceiling is {:?}", api.max_file_bytes());
    }
    other => {
        other?;
    }
}
# Ok(()) }

Cargo features

Feature Default What it does
rustls-tls yes TLS through rustls, needing no system OpenSSL
native-tls no TLS through the platform's own stack
multipart yes Media upload and bulk CSV import

To use native-tls instead, turn the defaults off and name what you want back:

fopost = { version = "0.3", default-features = false, features = ["native-tls", "multipart"] }

Forward compatibility

Response types ignore fields they do not know, and every enum keeps an Other(String) variant, so a platform or status added server-side parses on an older SDK instead of failing the whole response.

use fopost::models::Platform;

assert_eq!(Platform::InstagramBusiness.as_str(), "instagram-business");
assert_eq!(Platform::from("brand-new"), Platform::Other("brand-new".into()));

Examples

export FOPOST_API_KEY=fp_...
cargo run --example create_post -- "Hello from the Rust SDK"
cargo run --example preflight -- <post-id>

Chatbots and the inbox

The chat adapter turns the FoPost inbox into one send/receive channel for a chatbot framework. It ships in the TypeScript and Python SDKs. There is no dedicated adapter here and no API change behind it, so the same loop is three pieces with this client:

  1. Verify the inbox.message_received webhook. The payload is ids only, on purpose, so nothing a customer wrote sits in your logs. The signing scheme is HMAC-SHA256 over {timestamp}.{body}, refused past a five minute tolerance.
  2. Read the item back with client.inbox().list(…), filtered to the payload's accountId and matched on its itemId.
  3. Answer with client.inbox().reply(&item.id, text), or open a thread with client.inbox().start_conversation(…).

Reading needs the inbox scope; answering needs publish as well.

Verifying webhooks

Every FoPost webhook is signed the same way. Hand the verifier the request bytes exactly as received:

use fopost::{verify_webhook, WebhookSignature};

# fn handle(raw_body: &[u8], headers: &reqwest::header::HeaderMap, secret: &str) -> Result<(), Box<dyn std::error::Error>> {
let envelope = verify_webhook(raw_body, &WebhookSignature::from_headers(headers), secret)?;
if envelope.event.as_str() == "post.published" {
    println!("{} published", envelope.data["id"]);
}
# Ok(())
# }

verify_webhook prefers the timestamped X-FoPost-Signature-256 and refuses a delivery more than five minutes from the clock; it falls back to the body-only X-FoPost-Signature only when no timestamp header is present. The comparison is constant-time.

Contributing

Issues and pull requests are welcome at fopost/fopost-rust.

cargo fmt --check
cargo clippy --all-features --all-targets -- -D warnings
cargo test --all-features

Other SDKs

TypeScript (@fopost/sdk), Python (fopost), PHP, Laravel, and WordPress, plus ready-to-run API collections for Postman and Bruno.

License

MIT. See LICENSE.

Google Ads

Ads, audiences and insights are on client.ads() and dispatch by connection. What only Google has is on client.google_ads():

use fopost::models::{GoogleQuery, GoogleScope};

# async fn run(client: fopost::Client) -> fopost::Result<()> {
let scope = GoogleScope::new("c4d5e6f7-…", "1234567890");
let strategies = client.google_ads().bid_strategies(&scope).await?;

let result = client
    .google_ads()
    .query(&GoogleQuery {
        scope: scope.clone(),
        query: "SELECT campaign.id, metrics.clicks FROM campaign".into(),
    })
    .await?;
# Ok(())
# }

Also create_bid_strategy, ad_schedule and set_ad_schedule, local_services_leads, and the conversion methods. Changes need the publish scope as well as ads; customer_id has to name an account the connection's grant reaches.

About

Official Rust client for the FoPost API — schedule and publish social posts, manage accounts, media, and analytics. https://fopost.com

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages