Connect a social account
/api/accounts/connectCreate a short-lived Ampost-hosted link that connects one social account to a platform set.
- The user opens
connectUrlin 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.needsReconnectis true), pass its id asaccountId;platformmay then be omitted. - For a new connection,
expectedUsernameorexpectedPlatformAccountIdmakes 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_soonin 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
AuthorizationstringrequiredBearer <API key>. Create a key in the dashboard under API keys.Idempotency-KeystringA 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 | pinterestThe platform to connect. Required unless
accountIdis given.platformSetIdstringTarget platform set. Default: your default set, or for a reconnect the account's own set. An active account cannot change sets.
accountIdstringReconnect 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.
expectedUsernamestringNew connections: the username the user must sign in to, as
usernamein accounts_get (Facebook: the Page name). Case and a leading @ are ignored. Otherwise the request fails with ACCOUNT_MISMATCH.expectedPlatformAccountIdstringNew connections: the platform's id of the account the user must sign in to, as
platformAccountIdin accounts_get. Otherwise the request fails with ACCOUNT_MISMATCH.redirectUrlstringWhen 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).
statestringReturned unchanged as
stateonredirectUrl.
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.