Pages in API reference

Accounts

Connect a social account

POST/api/accounts/connect

Create a short-lived Ampost-hosted link that connects one social account to a platform set.

  • The user opens connectUrl in a browser and authorizes there; consent cannot happen in chat.
  • In MCP, a client that supports URL elicitation asks the user to open the page itself, and the result then has no connectUrl.
  • Then poll the connection request until it is connected, failed or expired.
  • To reconnect an existing account (a revoked one, or an active one whose health.needsReconnect is true), pass its id as accountId; platform may then be omitted.
  • For a new connection, expectedUsername or expectedPlatformAccountId makes sure the user signs in to the right account.
  • If the user signs in to another account, the request fails with ACCOUNT_MISMATCH and nothing changes.
  • A new request replaces the pending one for the same platform and set, also one the user opened but did not finish (it fails with SUPERSEDED), so call this again when the user lost or closed the page.
  • A coming-soon platform (availability: coming_soon in platforms_list) returns 403 PLATFORM_COMING_SOON for accounts it is not open to yet, reconnects included.
Key scope
accounts:write
MCP tool
accounts_connect
Retries
Safe with an Idempotency-Key

Headers

  • Authorizationstringrequired

    Bearer <API key>. Create a key in the dashboard under API keys.

  • Idempotency-Keystring

    A unique value per logical request, so a retry never creates a second post. See Idempotency.

Body

  • platforminstagram | facebook | linkedin | tiktok | threads | twitter | discord | telegram | bluesky | youtube | pinterest

    The platform to connect. Required unless accountId is given.

  • platformSetIdstring

    Target platform set. Default: your default set, or for a reconnect the account's own set. An active account cannot change sets.

  • accountIdstring

    Reconnect this existing account (active: refreshes its token and permissions; revoked: reactivates it). The user must sign in to the same platform account, otherwise the request fails with ACCOUNT_MISMATCH and nothing changes.

  • expectedUsernamestring

    New connections: the username the user must sign in to, as username in accounts_get (Facebook: the Page name). Case and a leading @ are ignored. Otherwise the request fails with ACCOUNT_MISMATCH.

  • expectedPlatformAccountIdstring

    New connections: the platform's id of the account the user must sign in to, as platformAccountId in accounts_get. Otherwise the request fails with ACCOUNT_MISMATCH.

  • redirectUrlstring

    When done, the result page links the browser here (the user clicks to leave Ampost), with the outcome in the query (https; http only for localhost).

  • statestring

    Returned unchanged as state on redirectUrl.

Over MCP

Show connectUrl to the user and ask them to open it in a browser to authorize the account. Then call accounts_connect_status with the id every 2-5 seconds until the status is connected, failed or expired. Never ask the user for a password, access token or authorization code.

Errors return { error: { code, message } }; every code is in Error codes.