# Connect a social account

Source: https://ampost.io/docs/api/accounts-connect · Full reference: https://ampost.io/llms-full.txt

`POST /api/accounts/connect` · MCP tool `accounts_connect` · scope `accounts:write` · rate limit `connectPlatform` · success `201`

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.

| Field | In | Type | Required | Description |
|---|---|---|---|---|
| `platform` | body | instagram \| facebook \| linkedin \| tiktok \| threads \| twitter \| discord \| telegram \| bluesky \| youtube \| pinterest | no | The platform to connect. Required unless `accountId` is given. |
| `platformSetId` | body | string | no | Target platform set. Default: your default set, or for a reconnect the account's own set. An active account cannot change sets. |
| `accountId` | body | string | no | 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. |
| `expectedUsername` | body | string | no | 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. |
| `expectedPlatformAccountId` | body | string | no | 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. |
| `redirectUrl` | body | string | no | 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). |
| `state` | body | string | no | Returned unchanged as `state` on `redirectUrl`. |
| `Idempotency-Key` (MCP `idempotencyKey`) | header | string | no | Idempotency key (1-255 visible ASCII characters, for example a UUID). A retry with the same key and arguments within 24 hours returns the first result instead of running again. Send a new key for each new action. See Idempotency. |

Example request:

```json
{
  "platform": "instagram",
  "platformSetId": "0b6e4d2a-9c3f-4e1b-8a7d-5f2c1e9b3d40"
}
```

Example response:

```json
{
  "id": "11111111-1111-4111-8111-111111111111",
  "platform": "instagram",
  "platformSetId": "0b6e4d2a-9c3f-4e1b-8a7d-5f2c1e9b3d40",
  "status": "pending",
  "reconnectAccountId": null,
  "expectedPlatformAccountId": null,
  "expectedUsername": null,
  "redirectUrl": null,
  "connectUrl": "https://ampost.io/connect/11111111-1111-4111-8111-111111111111#token=one-time-token",
  "createdAt": "2026-10-06T12:00:00.000Z",
  "expiresAt": "2026-10-06T12:10:00.000Z"
}
```
