- Connecting platform accounts (Instagram, Facebook, etc.) to your SocialAPI account so you can manage them through the API.
- Authenticating MCP/API clients (Claude, ChatGPT, Cursor) via the built-in OAuth 2.1 authorization server so they can call the API on your behalf.
Connecting platform accounts
SocialAPI manages platform OAuth on your behalf. Your application kicks off the connection, sends the user to the platform’s consent screen, and receives a redirect back to a URL of your choice with the result. You never see or store platform access tokens — SocialAPI persists them encrypted and proxies all subsequent calls. This is a managed connection pattern, not an OAuth flow you implement against SocialAPI. For OAuth 2.1 (used by MCP and third-party API clients calling SocialAPI), see the section below.Step 1: Initiate the connection
CallPOST /v1/accounts/connect with the platform slug, your post-connection redirect_uri, and an optional state value for correlation:
Response (HTTP 202):
state in the response is SocialAPI’s internal CSRF token used between our connect call and our platform callback. Your application does not need to read or store it; just send the user to auth_url.
Step 2: User authorizes on the platform
Redirect your user to theauth_url. They log in to the platform and grant permissions. The platform redirects back to SocialAPI’s callback (not yours). SocialAPI exchanges the code for an access token, persists it encrypted, and then 302-redirects the user to your redirect_uri.
Step 3: Receive the result at your redirect_uri
Success:
account_id. Facebook accounts that manage multiple Pages still resolve to a single account in the connection result; Page details are exposed separately under /v1/accounts/{id}/pages and are not part of this flow.
Error (the user denied consent, the platform returned an error, or the link expired):
status first. On success, persist the account_id against your user record and call /v1/accounts/{id} for full account details. On error, surface a retry path in your UI — the customer can restart from Step 1.
Google: connecting a login with multiple Business Profiles
This only applies to Google logins that manage more than one Business Profile. A Google login with a single Profile connects like any other platform, in a single request, with no extra step. Google accounts can manage several Business Profiles under one login (for example, a chain with multiple locations). When that happens, SocialAPI cannot know which Profile you want to connect, so it does not create an account yet. Instead it stores a pending connection and asks you to choose. Server-callback flow. If the Google login you just authorized manages more than one Profile, yourredirect_uri receives status=selection_required instead of status=success, along with a connection_id:
POST /v1/oauth/exchange, the same fork happens in the response body. A single Profile still returns the usual ConnectAccountResponse (HTTP 201). More than one Profile returns HTTP 200 instead:
connection_id:
GET /v1/accounts/pending/{connection_id}lists the candidate Profiles. This is usually optional since the callback redirect or the exchange response already includes them, but it is useful to re-fetch the list or check whether the pending connection is still valid.
POST /v1/accounts/pending/{connection_id}/selectwith theplatform_account_idof exactly one Profile connects it:
ConnectAccountResponse (HTTP 201) as a normal single-Profile connect.
A pending connection is single-use and expires 30 minutes after it is created. The first successful selection consumes it: a second
select call, or one made after expiry, returns 404. Selecting a platform_account_id that is not in the returned candidate set returns 400.Fallback when redirect_uri is omitted
If your connect call did not include redirect_uri, SocialAPI renders a built-in HTML success or error page in place of the redirect. This is intended for ad-hoc connections (for example, the SocialAPI dashboard itself); production integrations should always supply redirect_uri.
Whitelisting redirect URIs
Redirect URI enforcement is optional until you register your first URI. If your workspace has no redirect URIs registered, any validredirect_uri (https, or http for localhost) is accepted when starting a connect flow. As soon as you register one or more URIs, every redirect_uri must match an entry in your list, and unmatched values are rejected with a 400 error. Deleting all registered URIs returns your workspace to open mode.
Register URIs from the SocialAPI dashboard under Settings → OAuth redirect URIs. The management API exists at /v1/oauth/redirect-uris but is dashboard-only (requires the dashboard JWT, not an API key).
We recommend registering your production redirect URIs to lock down where users can be sent after OAuth.
Correlation state (customer-controlled)
The top-level state field on POST /v1/accounts/connect is your correlation token, not a security primitive enforced by SocialAPI. It is echoed back unchanged in the final redirect. Common uses:
- Tie the redirect to the originating session (set
stateto a server-side session ID). - CSRF defense for your own application — generate a random value, store it in the user’s session, and verify it matches when the redirect lands.
state. If you do not pass one, the final redirect will include state= with an empty value.
Listing connected accounts
Reconnecting an account
If you callPOST /v1/accounts/connect for an account that is already connected, the flow runs again and the stored token is upserted. This is safe to call when tokens expire and is the supported path for token refresh on platforms that lack long-lived tokens.
Disconnecting an account
DELETE /v1/accounts/{id} removes the account and the tokens we hold for it. Where the platform offers a token-revocation endpoint, we also revoke the grant on the platform during disconnect: Facebook, Google, Instagram, Threads, X, TikTok, and YouTube all support this.
LinkedIn, Pinterest, and Zalo do not offer a revocation API, so disconnect removes only the token stored on our side. On those platforms the user still sees the app authorized in their account settings and must remove it manually. If you offboard users under GDPR or similar rules, account for this manual step on those three platforms.
This is separate from POST /oauth/revoke below, which revokes SocialAPI’s own OAuth 2.1 tokens issued to MCP clients, not a platform grant.
OAuth 2.1 for MCP and API clients
SocialAPI includes a built-in OAuth 2.1 authorization server that enables MCP clients (Claude, ChatGPT, Cursor) and other third-party applications to authenticate users and call the API on their behalf. The implementation follows these RFCs:- RFC 8414 for authorization server metadata discovery
- RFC 7591 for dynamic client registration
- RFC 7636 for PKCE (required)
- RFC 7009 for token revocation
Discovery
Clients can discover the authorization server configuration at:Step 1: Register a client
Register your application using dynamic client registration:Step 2: Authorize the user
Redirect the user to the authorization endpoint with PKCE parameters:redirect_uri with ?code=...&state=....
PKCE is required. The only supported challenge method is
S256. Requests without a code_challenge are rejected with 400.social:all, which grants full access to the user’s account. This is the default if no scope is specified.
Step 3: Exchange the code for tokens
/v1 endpoints.
Per RFC 6749 section 2.3.1, the token endpoint also accepts client credentials via HTTP Basic authentication. Send
Authorization: Basic base64(client_id:client_secret) instead of including client_id and client_secret in the request body. Body parameters take precedence if both are present.Step 4: Refresh the access token
When the access token expires, use the refresh token to get a new pair:Revoking tokens
To revoke a refresh token (for example, on user logout):200, even if the token is already invalid.