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/emailreturns 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.
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{ "authUrl": "https://www.linkedin.com/oauth/v2/authorization?client_id=..." }{platform} is one of:
| Platform | API Value | Guide |
|---|---|---|
| X | twitter | X Guide |
instagram | Instagram Guide | |
facebook | Facebook Guide | |
linkedin | LinkedIn Guide | |
| TikTok | tiktok | TikTok Guide |
| YouTube | youtube | YouTube Guide |
pinterest | Pinterest Guide | |
reddit | Reddit Guide | |
| Bluesky | bluesky | Bluesky Guide |
| Threads | threads | Threads Guide |
| Google Business Profile | googlebusiness | Google Business Profile Guide |
| SnapchatClosed beta | snapchat | Snapchat Guide |
whatsapp | WhatsApp Guide | |
| Telegram | telegram | Telegram Guide |
| Discord | discord | Discord Guide |
| Slack | slack | Slack Guide |
| Shopify | shopify | Shopify Guide |
| WordPress | wordpress | WordPress Guide |
| Wix | wix | Wix Guide |
| Webflow | webflow | Webflow Guide |
| HubSpot | hubspot | HubSpot Guide |
| Google Analytics | googleanalytics | Google Analytics Guide |
google | Google Guide | |
| Microsoft | microsoft | Microsoft Guide |
| IMAP | imap | IMAP Guide |
- Callback params:
connected,profileId,accountId,username, plusrequest_idandstage(correlation params), added to yourredirect_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 asmyapp://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.
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:
brandNameandlogoUrlon the call, or saved once in the dashboard (Settings, White Labeling) or withPUT /v1/connect/welcome-screen. - Show by default: once saved, every link shows it without
welcome=true.welcome=falseskips it on one link. - Not with
headless=trueorsignup=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.
curl "https://zernio.com/api/v1/connect/instagram?profileId=66a1f0c2a4b9d3e8f1a2b3c4&handoff=true&brandName=Acme" \
-H "Authorization: Bearer $ZERNIO_API_KEY"{
"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"
}
}- Draw
handoff.urlas a QR code (any library). It works for 30 minutes. - The user scans it, sees your welcome screen, logs in on the phone and is told to go back to the computer.
- Poll
GET /v1/connect/handoffs/{handoffId}every few seconds, or wait for theaccount.connectedwebhook.
status | Meaning |
|---|---|
waiting | Not scanned yet. |
opened | The code was scanned. |
connected | Done, with the new accounts. |
failed | With the error code. |
expired | Not 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.
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 throughcanPostandcanFetchAnalytics. - 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 areasemail,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.
| Platform | What to select | Endpoints |
|---|---|---|
| Page | List Pages → Select Page | |
| Organization or personal profile | List orgs → Select org | |
| Board | List boards → Select board | |
| Google Business Profile | Location | List locations → Select location |
| Snapchat | Public profile | List profiles → Select profile |
Instagram (loginMethod=facebook_login only) | Page with a linked Instagram account | List 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. Yourredirect_urlgetstempToken,userProfile(JSON, encoded twice),stepandconnect_tokenfor the list and select endpoints.
step names the selection endpoint to call next. Instagram sends no userProfile: its select-account endpoint takes none.
step | Platform |
|---|---|
select_page | |
select_organization | |
select_board | |
select_location | Google Business Profile |
select_public_profile | Snapchat |
select_phone_number | |
select_account | Instagram via Facebook Login |
Headless example: a Facebook Page
Start it like any OAuth flow, with headless: true:
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{ "authUrl": "https://www.facebook.com/v21.0/dialog/oauth?client_id=..." }After consent, Meta sends the user to your callback:
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:
// 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 },
});{ "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:
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{
"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.
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.{ "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 andredirect_url): themetaadsaccount created alongside, for the/v1/adsendpoints. Absent if it could not be created;account.accountIdstays the Facebook posting account.- Instagram:
POST /v1/connect/instagram/select-accountworks the same on an Instagram ads connect (loginMethod=facebook_login). - First Page is fine for roughly 70% of the
metaadsAPI: anything not sendingobject_story_spec.page_id. - Page-specific 30%: boosting Page posts, Click-to-WhatsApp ads, Lead Gen Forms. Show a picker then and POST the
pageIdto/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.
GET /v1/connect/facebook/ads?profileId=...&loginMode=business- Result: always an
authUrlfor the user's browser. The callback creates or reconnects a standalonemetaadsaccount with a Business Integration System User token; no posting account is needed. - Token:
GET /v1/accountsshowsmetadata.tokenType: "system-user". Without Meta'sexpires_in,tokenExpiresAtis absent and Zernio never re-exchanges it as a personal token. - Pages live on the
metaadsaccount; no Facebook account is created. Connections and billing covers organic accounts and which accounts bill.
The bound Page serves ad creatives and lead forms:
pageIdon the connect picks a granted Page; one outside the grant fails withpage_not_granted.- No
pageId: a reconnect reuses the previous Page, a new connection binds the first granted one. Change it later withPUT /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_valueanderror_reason=reconnect_mismatch. For unrelated ad accounts, disconnect and connect again.
An accepted reconnect rebuilds the ad-account scope:
adAccountIdspassed 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:
?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_completedwebhook. It always carriesaccount.platformAdAccountIds, andaccount.platformAdAccountIdwhen 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.
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}`);{
"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:
- Call
GET /v1/connect/telegramto generate an access code, valid for 15 minutes. - The user makes the Zernio Telegram bot an admin of the channel or group and sends it the code.
- Poll
PATCH /v1/connect/telegramto 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.
- Collect the store domain (
your-store.myshopify.com; the bareyour-storeprefix is accepted). - Call
GET /v1/connect/shopifywithprofileIdandshopto get the authorization URL. - Redirect the merchant to
authUrl. They return to yourredirect_urlwithconnected,profileId,accountIdandusername, like every OAuth platform.
usernameis the realmyshopify.comdomain of the store they approved, which may differ fromshop(merchants often type a brand name). Keep theaccountIdfrom the redirect (oraccount.connectedwebhook), 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 andaccount.connectedfires. 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_productsandwrite_productsscopes and gives you its Admin API access token. Exchange it withPOST /v1/connect/shopify/token;shopis 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/wordpresswithprofileIdandredirect_url, then send the user toauthUrl; 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:
- Update Facebook Page
- Update LinkedIn organization
- Update Pinterest board
- Update Google Business Profile location
- Update Reddit subreddit
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.
?error=oauth_denied&platform=linkedin&request_id=...&stage=authorize| Error | Cause | Fix |
|---|---|---|
oauth_denied | Consent 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_URL | redirect_url is a relative path. | Use an absolute URL or app scheme. |
400 | Malformed profileId. | Pass a valid profile id. |
400 INVALID_FIELD_VALUE | scopes empty, with an unknown area, sent to a platform that rejects it, or missing for Google or Microsoft. | Fix or drop scopes. |
402 PAYMENT_REQUIRED | Billing blocks the connect (billing gates). | Send the user to dashboard_url. |
Known error values: Start OAuth endpoint. Optional params:
| Param | Meaning |
|---|---|
error_message | Human-readable explanation you can show the user. |
is_user_fixable | true when connecting again fixes it (cancelled, declined a permission, ticked no Page). |
error_reason | Finer reason for some error values, listed below. |
platform_error, platform_error_reason, platform_error_description | On 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_reason | Meaning |
|---|---|
pages_permission_declined | The user declined the pages_show_list permission. |
no_pages_granted | Permission granted with no Page ticked, or the user manages no Page (Meta cannot tell them apart). |
granted_pages_not_listed | Pages 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.
error | error_reason | Meaning |
|---|---|---|
invalid_field_value | no_pages_granted | No Page was ticked in Meta's dialog. |
invalid_field_value | page_not_granted | The pageId you passed is not in the grant. |
invalid_field_value | ad_accounts_not_granted | No ad account was granted. |
invalid_field_value | reconnect_mismatch | The grant shares no ad account with the existing connection. |
invalid_state | state_expired | Back after the 30-minute window. Start again. |
connection_failed | Meta 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, withplatform_error*. 400JSON only for an undecryptable state, which names noredirect_url.
Request ids
request_idandstage: on every OAuth callback redirect (success or failure) and on theredirect_urlfrom 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 orrequest_idto 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.
{
"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"
}reason | Cause |
|---|---|
free_tier_exceeded | Over the free connected accounts, no card on file. |
twitter_passthrough | Any X account without a card, on accounts billed monthly. Accounts on the prepaid balance connect X without one. |
enterprise_required | A contract cap. |
Related
- List accounts: accounts and their
isActivestate. - Update an account: default Pages, boards and other settings.
- Account health: tokens and permissions.
- Disconnect an account.
- Instagram: Instagram Login versus Facebook Login.