OverviewProductsPlatformsAPI ReferenceResources

Connecting accounts

Connect an account to a profile with OAuth, a hosted or headless selection step, or credentials for Bluesky, Telegram, Shopify, self-hosted WordPress and IMAP mailboxes.


Connect a social account, ad account or store to a profile and get back its accountId.

Before you start

  • You need an API key, a profile id (create a profile) and a login on the platform.
  • Most platforms use OAuth. Bluesky, Telegram, Shopify and self-hosted WordPress have their own flows.
  • Mailboxes: GET /v1/connect/email returns one hosted link for any address. Gmail and Microsoft addresses go to their sign-in, every other mailbox connects over IMAP. See IMAP connect.
  • Per-platform rules: each platform page.

Start the OAuth flow

Call GET /v1/connect/{platform} with your profileId and send the user's browser to the returned authUrl. Approving connects the account.

TypeScript
import Zernio from '@zernio/node';

const zernio = new Zernio();
const profileId = '66a1f0c2a4b9d3e8f1a2b3c4';

const { data: connect } = await zernio.connect.getConnectUrl({
  path: { platform: 'linkedin' },
  query: { profileId, redirect_url: 'https://myapp.com/callback' }
});
// Send the user's browser to connect.authUrl
JSON
{ "authUrl": "https://www.linkedin.com/oauth/v2/authorization?client_id=..." }

{platform} is one of:

PlatformAPI ValueGuide
XtwitterX Guide
InstagraminstagramInstagram Guide
FacebookfacebookFacebook Guide
LinkedInlinkedinLinkedIn Guide
TikToktiktokTikTok Guide
YouTubeyoutubeYouTube Guide
PinterestpinterestPinterest Guide
RedditredditReddit Guide
BlueskyblueskyBluesky Guide
ThreadsthreadsThreads Guide
Google Business ProfilegooglebusinessGoogle Business Profile Guide
SnapchatClosed betasnapchatSnapchat Guide
WhatsAppwhatsappWhatsApp Guide
TelegramtelegramTelegram Guide
DiscorddiscordDiscord Guide
SlackslackSlack Guide
ShopifyshopifyShopify Guide
WordPresswordpressWordPress Guide
WixwixWix Guide
WebflowwebflowWebflow Guide
HubSpothubspotHubSpot Guide
Google AnalyticsgoogleanalyticsGoogle Analytics Guide
GooglegoogleGoogle Guide
MicrosoftmicrosoftMicrosoft Guide
IMAPimapIMAP Guide
  • Callback params: connected, profileId, accountId, username, plus request_id and stage (correlation params), added to your redirect_url. Your own params are kept unless they share a name with ours.
  • redirect_url: an absolute http(s) URL or an app scheme such as myapp://callback.
  • Every parameter: Start OAuth endpoint.

Show a branded welcome screen

Add welcome=true (recommended) and authUrl opens a Zernio-hosted screen with your name and logo ("Acme wants to connect to your LinkedIn"), which forwards to the platform after a second.

Terminal
curl "https://zernio.com/api/v1/connect/linkedin?profileId=66a1f0c2a4b9d3e8f1a2b3c4&welcome=true&brandName=Acme&logoUrl=https://acme.com/logo.png&redirect_url=https://myapp.com/callback" \
  -H "Authorization: Bearer $ZERNIO_API_KEY"
  • Why: users who see whose app it is finish more often. Later pickers and the closing screen carry the same brand.
  • Brand: brandName and logoUrl on the call, or saved once in the dashboard (Settings, White Labeling) or with PUT /v1/connect/welcome-screen.
  • Show by default: once saved, every link shows it without welcome=true. welcome=false skips it on one link.
  • Not with headless=true or signup=hosted.

Finish on a phone

Add handoff=true to get a short link to show as a QR code. Users on a computer then log in on their phone, where the platform's app already has them signed in.

Terminal
curl "https://zernio.com/api/v1/connect/instagram?profileId=66a1f0c2a4b9d3e8f1a2b3c4&handoff=true&brandName=Acme" \
  -H "Authorization: Bearer $ZERNIO_API_KEY"
JSON
{
  "authUrl": "https://zernio.com/connect/welcome?ticket=...",
  "state": "...",
  "handoff": {
    "id": "79c6dbf2-97ba-4f34-b615-5bf9435526db",
    "url": "https://zernio.com/connect/m/79c6dbf2-97ba-4f34-b615-5bf9435526db",
    "expiresAt": "2026-10-22T18:30:00.000Z"
  }
}
  1. Draw handoff.url as a QR code (any library). It works for 30 minutes.
  2. The user scans it, sees your welcome screen, logs in on the phone and is told to go back to the computer.
  3. Poll GET /v1/connect/handoffs/{handoffId} every few seconds, or wait for the account.connected webhook.
statusMeaning
waitingNot scanned yet.
openedThe code was scanned.
connectedDone, with the new accounts.
failedWith the error code.
expiredNot scanned within 30 minutes.

handoff=true always shows the welcome screen, so it excludes welcome=false, headless=true, signup, redirect=true or redirect_url.

Ask for fewer scopes

The flow asks for every scope Zernio supports unless you pass scopes with the areas you use: posting, analytics, comments, messaging, ads.

TypeScript
const { data: connect } = await zernio.connect.getConnectUrl({
  path: { platform: 'linkedin' },
  query: { profileId, scopes: 'posting,analytics', redirect_url: 'https://myapp.com/callback' }
});

A posting-only account cannot read analytics or the inbox and skips first comments (they need comments). Adding areas means connecting again.

  • Consent screen: only those areas' scopes, plus identity, token refresh, and listing the Pages, organizations or channels to pick from.
  • Scope per area: each platform page; full table on the Start OAuth endpoint.
  • Not asked, not granted: missing from permissions, and reported by Account health through canPost and canFetchAnalytics.
  • Supported: Facebook, Instagram (both login methods), LinkedIn, X, TikTok, YouTube, Threads, Reddit, Pinterest, Google Business Profile and Slack (GET /v1/connect/slack).
  • Rejected by Bluesky, Telegram, Discord, Snapchat and WhatsApp, whose consent screen cannot be reduced.
  • Google and Microsoft require scopes, with their own areas email, calendar, files, contacts. Reconnecting with more areas widens the same account. See Connect a Google account and Connect a Microsoft account.

Pick a Page, organization or board

Six platforms need a pick after OAuth.

PlatformWhat to selectEndpoints
FacebookPageList Pages → Select Page
LinkedInOrganization or personal profileList orgs → Select org
PinterestBoardList boards → Select board
Google Business ProfileLocationList locations → Select location
SnapchatPublic profileList profiles → Select profile
Instagram (loginMethod=facebook_login only)Page with a linked Instagram accountList Pages → Select account

The default Instagram Login has no selection step (login methods).

Standard vs headless mode

  • Standard (default): Zernio hosts the selection screen, then sends the user to your redirect_url.
  • Headless (headless=true): you build the screen. Your redirect_url gets tempToken, userProfile (JSON, encoded twice), step and connect_token for the list and select endpoints.

step names the selection endpoint to call next. Instagram sends no userProfile: its select-account endpoint takes none.

stepPlatform
select_pageFacebook
select_organizationLinkedIn
select_boardPinterest
select_locationGoogle Business Profile
select_public_profileSnapchat
select_phone_numberWhatsApp
select_accountInstagram via Facebook Login

Headless example: a Facebook Page

Start it like any OAuth flow, with headless: true:

TypeScript
const { data: start } = await zernio.connect.getConnectUrl({
  path: { platform: 'facebook' },
  query: { profileId, headless: true, redirect_url: 'https://your-app.com/cb' },
});
// Send the user's browser to start.authUrl
JSON
{ "authUrl": "https://www.facebook.com/v21.0/dialog/oauth?client_id=..." }

After consent, Meta sends the user to your callback:

Text
https://your-app.com/cb?profileId=...&tempToken=...&userProfile=...&platform=facebook&step=select_page&connect_token=...

Read tempToken and userProfile from it. Decode userProfile once more after your framework decodes the query, then parse the JSON (tempToken and connect_token are plain). List the user's Pages:

TypeScript
// requestUrl: the URL your handler received; searchParams decodes the values once
const { tempToken, userProfile: encodedProfile } = Object.fromEntries(new URL(requestUrl).searchParams);
const userProfile = JSON.parse(decodeURIComponent(encodedProfile));

const { data: pages } = await zernio.connect.facebook.listFacebookPages({
  query: { profileId, tempToken },
});
JSON
{ "pages": [{ "id": "123456789", "name": "My Brand Page", "username": "mybrand", "category": "Brand" }] }

Connect the chosen Page with POST /v1/connect/facebook/select-page, passing userProfile as the decoded object:

TypeScript
const { data: result } = await zernio.connect.facebook.selectFacebookPage({
  body: {
    profileId,
    pageId: pages.pages[0].id,
    tempToken,
    userProfile,
    redirect_url: 'https://your-app.com/final-success',
  },
});
// Send the browser to result.redirect_url
JSON
{
  "message": "Facebook page connected successfully",
  "redirect_url": "https://your-app.com/final-success?connected=facebook&profileId=66a1f0c2a4b9d3e8f1a2b3c4&accountId=66b2e19d8c3f5a7e9d0b1c2d&username=My+Brand+Page&request_id=...&stage=select_page",
  "account": {
    "accountId": "66b2e19d8c3f5a7e9d0b1c2d",
    "platform": "facebook",
    "username": "mybrand",
    "isActive": true,
    "selectedPageName": "My Brand Page"
  }
}

account.accountId is the new account's id.

Connect Meta Ads only

For ads only (audience uploads, the Conversions API, analytics, listing ads and campaigns), start at GET /v1/connect/facebook/ads. Your backend picks the first Page, so no picker.

TypeScript
const { data: adsStart } = await zernio.connect.connectAds({
  path: { platform: 'facebook' },
  query: { profileId, headless: true, redirect_url: 'https://your-app.com/cb' },
});
// Send the user's browser to adsStart.authUrl, then list and select
// as above with pages.pages[0].id and no picker.
JSON
{ "authUrl": "https://www.facebook.com/v21.0/dialog/oauth?client_id=..." }
  • Flow: callback, list and select as in the headless flow; the user goes from Meta's consent straight to your "Connected" screen.
  • Login mode: classic login (loginMode=classic, the default). To connect ads without a posting account, use Facebook Login for Business.
  • adsAccountId (select response body and redirect_url): the metaads account created alongside, for the /v1/ads endpoints. Absent if it could not be created; account.accountId stays the Facebook posting account.
  • Instagram: POST /v1/connect/instagram/select-account works the same on an Instagram ads connect (loginMethod=facebook_login).
  • First Page is fine for roughly 70% of the metaads API: anything not sending object_story_spec.page_id.
  • Page-specific 30%: boosting Page posts, Click-to-WhatsApp ads, Lead Gen Forms. Show a picker then and POST the pageId to /v1/connect/facebook/select-page; the Facebook account updates in place, no second OAuth.
  • Hidden Facebook account: if the profile had none for that Page, the new one has enabled: false: hidden, not postable and not billed. See Connections and billing.

Facebook Login for Business

Call GET /v1/connect/{platform}/ads with platform set to facebook or instagram, plus profileId and loginMode=business. Without loginMode, the flow is classic.

Text
GET /v1/connect/facebook/ads?profileId=...&loginMode=business
  • Result: always an authUrl for the user's browser. The callback creates or reconnects a standalone metaads account with a Business Integration System User token; no posting account is needed.
  • Token: GET /v1/accounts shows metadata.tokenType: "system-user". Without Meta's expires_in, tokenExpiresAt is absent and Zernio never re-exchanges it as a personal token.
  • Pages live on the metaads account; no Facebook account is created. Connections and billing covers organic accounts and which accounts bill.

The bound Page serves ad creatives and lead forms:

  • pageId on the connect picks a granted Page; one outside the grant fails with page_not_granted.
  • No pageId: a reconnect reuses the previous Page, a new connection binds the first granted one. Change it later with PUT /v1/accounts/{accountId}/facebook-page.
  • Zero granted Pages: refused with no_pages_granted.

Reconnecting (re-run the dialog to add, drop or swap ad accounts) keeps the connection's id and history.

  • Must overlap: the new grant shares at least one ad account, or it is refused first with error=invalid_field_value and error_reason=reconnect_mismatch. For unrelated ad accounts, disconnect and connect again.

An accepted reconnect rebuilds the ad-account scope:

  • adAccountIds passed on the re-auth become the scope.
  • Otherwise, a narrowed scope keeps its still-granted ad accounts, plus any granted for the first time.
  • An unscoped connection follows the new grant.

Errors: If it fails.

Scoping sync to specific ad accounts

Sync covers every act_* ad account the token sees, which for agencies means every Business Manager the user has a role on. Pass adAccountId (one) or adAccountIds (several) on GET /v1/connect/facebook/ads to sync an allowlist:

Text
?adAccountId=act_1330190928038136
?adAccountIds=act_1330190928038136,act_3686966528111132
  • Checked against the token's /me/adaccounts, then stored. The latest connect replaces the list; omit both to sync everything.
  • Confirm with the account.ads.initial_sync_completed webhook. It always carries account.platformAdAccountIds, and account.platformAdAccountId when the scope is exactly one account.

Connect without OAuth or with a store

Bluesky

Bluesky uses an app password. state is {userId}-{profileId}: userId is currentUserId from GET /v1/users, profileId from GET /v1/profiles.

TypeScript
const { data: bluesky } = await zernio.connect.bluesky.connectBlueskyCredentials({
  body: {
    identifier: 'yourhandle.bsky.social',
    appPassword: 'your-app-password',
    state: '66a0e8b1c2d3e4f5a6b7c8d9-66a1f0c2a4b9d3e8f1a2b3c4',
  },
});
console.log(`Connected ${bluesky.account.username}`);
JSON
{
  "message": "Bluesky connected successfully",
  "account": { "platform": "bluesky", "username": "yourhandle.bsky.social", "displayName": "Your Name", "isActive": true }
}

The Connect Bluesky endpoint lists every field.

Telegram

Telegram connects with an access code:

  1. Call GET /v1/connect/telegram to generate an access code, valid for 15 minutes.
  2. The user makes the Zernio Telegram bot an admin of the channel or group and sends it the code.
  3. Poll PATCH /v1/connect/telegram to check the status until it reports connected.

Bot already an admin? Skip the code and connect directly with POST /v1/connect/telegram and the chat id.

Shopify

Shopify OAuth is per store, with no store picker or shop lookup, so you need the merchant's myshopify.com domain first.

  1. Collect the store domain (your-store.myshopify.com; the bare your-store prefix is accepted).
  2. Call GET /v1/connect/shopify with profileId and shop to get the authorization URL.
  3. Redirect the merchant to authUrl. They return to your redirect_url with connected, profileId, accountId and username, like every OAuth platform.
  • username is the real myshopify.com domain of the store they approved, which may differ from shop (merchants often type a brand name). Keep the accountId from the redirect (or account.connected webhook), not your domain.
  • App Store installs link only for the store in shop, within an hour of your call. They return with the same params and account.connected fires. A store another profile holds is not linked; the merchant stays in their Shopify admin.
  • No browser flow: the merchant creates a custom app with the read_content, write_content, read_products and write_products scopes and gives you its Admin API access token. Exchange it with POST /v1/connect/shopify/token; shop is required, because an Admin token does not identify its store.
  • No social posts: a store powers the Blogs API and the Commerce API; see the Shopify page.

WordPress

  • WordPress.com: GET /v1/connect/wordpress with profileId and redirect_url, then send the user to authUrl; the callback returns the chosen site. See Get WordPress.com authorization URL.
  • Self-hosted: create an Application Password in WordPress admin, then send the site's HTTPS URL, login username and that password to POST /v1/connect/wordpress/token.
  • Checks: Zernio finds the REST API and confirms the user can publish posts and upload media. Never put the username or the Application Password in siteUrl.
  • One site, one blog per account, no social posts: use the Blogs API and the WordPress guide. A self-hosted WooCommerce site is also a store for the Commerce API.

Change a selection without reconnecting

Change an account's Page, organization, board, location or subreddit with no second OAuth:

If it fails

A denied or rejected OAuth adds error and platform to your redirect_url. Check error first; treat unknown values as generic failures, since new ones appear without notice.

Text
?error=oauth_denied&platform=linkedin&request_id=...&stage=authorize
ErrorCauseFix
oauth_deniedConsent denied or refused.Read platform_error*; let the user retry.
no_facebook_pages (is_user_fixable=true, with error_message)No usable Page (error_reason below).Reconnect, click "Edit previous settings" in Meta's dialog and tick the Page, or create a Page first.
400 INVALID_REDIRECT_URLredirect_url is a relative path.Use an absolute URL or app scheme.
400Malformed profileId.Pass a valid profile id.
400 INVALID_FIELD_VALUEscopes empty, with an unknown area, sent to a platform that rejects it, or missing for Google or Microsoft.Fix or drop scopes.
402 PAYMENT_REQUIREDBilling blocks the connect (billing gates).Send the user to dashboard_url.

Known error values: Start OAuth endpoint. Optional params:

ParamMeaning
error_messageHuman-readable explanation you can show the user.
is_user_fixabletrue when connecting again fixes it (cancelled, declined a permission, ticked no Page).
error_reasonFiner reason for some error values, listed below.
platform_error, platform_error_reason, platform_error_descriptionOn oauth_denied and meta_ads_authorization_denied, the platform's own values if sent (access_denied, user_denied). Description truncated to 500 characters.

Error redirects drop the internal headless, adsConnect and adsScope markers.

no_facebook_pages cases (error_reason, when Meta's token debug answered):

error_reasonMeaning
pages_permission_declinedThe user declined the pages_show_list permission.
no_pages_grantedPermission granted with no Page ticked, or the user manages no Page (Meta cannot tell them apart).
granted_pages_not_listedPages ticked, but Meta listed none the user can manage.

Facebook Login for Business errors

Failures after Meta's dialog redirect with error (the API error code), platform=metaads, error_message, request_id, stage, and is_user_fixable and error_reason when known.

errorerror_reasonMeaning
invalid_field_valueno_pages_grantedNo Page was ticked in Meta's dialog.
invalid_field_valuepage_not_grantedThe pageId you passed is not in the grant.
invalid_field_valuead_accounts_not_grantedNo ad account was granted.
invalid_field_valuereconnect_mismatchThe grant shares no ad account with the existing connection.
invalid_statestate_expiredBack after the 30-minute window. Start again.
connection_failedMeta refused the code (for example a replayed callback).
  • Gates of GET /v1/connect/{platform} arrive the same way: reconnect_required, ads_addon_required, payment_required, profile gates.
  • Denial in the dialog: meta_ads_authorization_denied, with platform_error*.
  • 400 JSON only for an undecryptable state, which names no redirect_url.

Request ids

  • request_id and stage: on every OAuth callback redirect (success or failure) and on the redirect_url from select-page, select-account, select-organization, select-board, select-location, select-profile and select-phone-number.
  • X-Request-Id: header on every API response. Quote it or request_id to support; we log the request under it.

stage says where the flow ended:

  • authorize: the consent dialog returned an error or denial, not a code.
  • callback: Zernio processed the code (success, a selection step or a failure).
  • select_page: a selection endpoint finished the flow.

Billing gates

The connect call returns 402 when billing blocks it; send the user to dashboard_url.

JSON
{
  "error": "X (Twitter) requires a payment method due to API pass-through costs. Add a payment method to connect an X account.",
  "code": "PAYMENT_REQUIRED",
  "reason": "twitter_passthrough",
  "dashboard_url": "https://zernio.com/dashboard?tab=billing"
}
reasonCause
free_tier_exceededOver the free connected accounts, no card on file.
twitter_passthroughAny X account without a card, on accounts billed monthly. Accounts on the prepaid balance connect X without one.
enterprise_requiredA contract cap.
Was this page helpful?

On this page