How to Connect Social Media Accounts to Your SaaS with Zernio

Your customer clicks Connect Facebook, approves access, and returns to your app. You show a green Connected badge. Then they try to schedule their first post and discover your app has no idea which Facebook Page they meant to use.

That’s where a social integration gets complicated. The person who grants access, the account or page you publish to, and the workspace that owns the connection are three different things. Once you add LinkedIn, Instagram, and X, you also have to handle different permissions, media requirements, and publishing errors. docs.zernio.com

This guide walks through the flow in Laravel. You’ll create a Zernio profile for a customer workspace, let the customer connect LinkedIn from your app, verify the destination, and publish a post. Then you’ll see what changes when you add scheduling and more platforms.

Affiliate disclosure: I may earn a commission if you sign up through my link.

Create a Zernio account and follow along

The real problem starts after OAuth

Imagine you’re building a marketing tool for agencies. One agency manages three brands. Its account manager has access to several LinkedIn company pages and Facebook Pages. They use the same browser and the same social logins for all three clients.

When they click Connect LinkedIn from the Acme workspace, your app needs to know whether they selected their personal profile or the Acme company page. It also needs to keep that connection out of the other clients’ workspaces. A mistake here can put the wrong company name in the post composer or send a post to the wrong audience. docs.zernio.com

The next problem appears after onboarding. A customer can revoke access after scheduling a post, or a connection can lack the permission your app needs. A multi-platform post can also succeed on LinkedIn and fail on Instagram. If the UI shows one generic Failed status and offers a single retry button, the customer risks sending the LinkedIn post twice. docs.zernio.com

Zernio gives you a shared API for connecting accounts and publishing, plus hosted selection screens where needed. Your Laravel app still manages workspace permissions, stores the verified destinations, and tells customers which posts went live. docs.zernio.com

Step 1. Set up the API client in Laravel

Start with one workspace and one LinkedIn account you control. LinkedIn accepts a text-only post, so you can verify the full connection and publishing flow before adding media uploads. Instagram requires media on every post. docs.zernio.com

Sign up for Zernio and create your API key. Zernio’s REST API uses Bearer authentication. Keep the key in your backend environment. zernio.com

ZERNIO_API_KEY=your_api_key 

Add this entry to config/services.php:

'zernio' => [ 'key' => env('ZERNIO_API_KEY'), ], 

Use Laravel’s HTTP client for the requests below:

use Illuminate\Support\Facades\Http; $zernio = Http::baseUrl('https://zernio.com/api/v1') ->withToken(config('services.zernio.key')) ->acceptJson() ->timeout(30); 

The snippets assume your Laravel app already has authenticated users, a Workspace model, and policies for managing integrations and publishing posts.

Step 2. Give each workspace its own Zernio profile

If your app has one workspace per client or brand, create one Zernio profile per workspace. For example, Acme’s Laravel workspace might have ID 42. Its Zernio profile uses workspace_42 as its externalId. Under that profile, Acme’s LinkedIn and Instagram connections each have their own account ID. When someone publishes to LinkedIn, you send the LinkedIn account ID with the post. docs.zernio.com

Add a nullable zernio_profile_id column to workspaces. Create the profile during workspace setup or when the customer connects their first account:

$profileId = $zernio->post('profiles', [ 'name' => $workspace->name, 'externalId' => "workspace_{$workspace->id}", ])->throw()->json('profile._id'); $workspace->update([ 'zernio_profile_id' => $profileId, ]); 

Reuse the saved ID on subsequent connection attempts. If Zernio creates the profile but the request times out before Laravel saves it, look it up with GET /profiles?externalId=workspace_42. Zernio documents externalId as unique among the profiles you own, so a stable value gives you a way to recover the original profile. docs.zernio.com

Step 3. Add a “Connect LinkedIn” button

Put the button on the workspace’s Social accounts page. Have it submit to an authenticated Laravel action. Check whether the user can manage that workspace’s integrations, then ask Zernio for the authorization URL using the profile ID you stored. docs.zernio.com

use Illuminate\Support\Facades\Gate; Gate::authorize('manageIntegrations', $workspace); $authUrl = $zernio->get('connect/linkedin', [ 'profileId' => $workspace->zernio_profile_id, 'redirect_url' => route('social.callback', [ 'workspace' => $workspace->id, ]), ])->throw()->json('authUrl'); return redirect()->away($authUrl); 

LinkedIn users can select their personal profile or an organization they administer. Zernio can host that selection screen. Once the customer returns, show the selected profile or page on your Social accounts screen so they can check where their posts will go. docs.zernio.com

Step 4. Verify the account on your backend

Zernio can append profileId, accountId, and username to the callback URL. Use the returned accountId to identify the connection, then verify it against the account list Zernio returns for the workspace’s stored profile. Show success after that lookup succeeds. docs.zernio.com

Gate::authorize('manageIntegrations', $workspace); $accountId = $request->query('accountId'); if (! is_string($accountId) || $accountId === '') { return redirect()->route('social.index', $workspace) ->with('error', 'LinkedIn connection was not completed.'); } $accounts = $zernio->get('accounts', [ 'profileId' => $workspace->zernio_profile_id, ])->throw()->json('accounts', []); $account = collect($accounts)->first( fn (array $account) => $account['_id'] === $accountId && $account['platform'] === 'linkedin' && $account['isActive'] ); if ($account === null) { return redirect()->route('social.index', $workspace) ->with('error', 'Could not verify the LinkedIn connection.'); } $workspace->socialAccounts()->updateOrCreate( ['zernio_account_id' => $account['_id']], [ 'platform' => $account['platform'], 'username' => $account['username'] ?? null, ] ); return redirect()->route('social.index', $workspace) ->with('success', 'LinkedIn connected.'); 

Add a unique index on workspace_id and zernio_account_id so repeated callbacks can’t create duplicate rows. If an account appears active but publishing fails, use GET /accounts/{accountId}/health to check for token or permission issues. That gives you something specific to tell the customer when they open the integrations page. docs.zernio.com

Step 5. Publish a text post to the connected account

Have the frontend send the ID of a local social_accounts row. Resolve it through the current workspace before sending the underlying Zernio account ID. Zernio’s publishing endpoint accepts account IDs owned by your Zernio team across profiles, so the workspace lookup is what prevents one customer from publishing through another customer’s connection. docs.zernio.com

Gate::authorize('publishPosts', $workspace); $data = $request->validate([ 'social_account_id' => ['required', 'integer'], 'content' => ['required', 'string', 'max:3000'], ]); $account = $workspace->socialAccounts() ->where('platform', 'linkedin') ->findOrFail($data['social_account_id']); $post = $zernio->post('posts', [ 'content' => $data['content'], 'platforms' => [[ 'platform' => $account->platform, 'accountId' => $account->zernio_account_id, ]], 'publishNow' => true, ])->throw()->json('post'); 

Save post._id with your local post record and use the returned status to update the UI. For your first test, open the selected LinkedIn profile or company page and confirm the post appeared where you expected. docs.zernio.com

To schedule the post, replace publishNow with scheduledFor and timezone. If the customer picks 10:00 in Sofia, send the intended local date and time with Europe/Sofia. Store the scheduled time alongside the Zernio post ID so the customer can see what’s queued after refreshing the page. zernio.com

Step 6. Handle the failures customers actually see

Suppose a customer schedules one announcement for LinkedIn and Instagram. LinkedIn publishes it, but Instagram fails. Show both outcomes beside the respective accounts and give the customer a way to retry just Instagram. Zernio exposes platform-level publishing events and a post.partial event for partial success. docs.zernio.com

If the customer closes the OAuth screen, leave the connection unconfirmed and let them reopen it. If an existing connection loses access, mark that account as needing attention and show a Reconnect button. If a publish request times out, treat the result as unknown and reconcile it before retrying. The original request may already have reached Zernio. docs.zernio.com

Start with account.connected, account.disconnected, post.platform.published, and post.platform.failed. Verify webhook signatures against the raw request body and deduplicate deliveries before updating records or notifying the customer. Map each event back to the workspace or destination that owns it. docs.zernio.com

Step 7. Add Instagram using the same connection flow

Once LinkedIn works, reuse your workspace profiles, connection records, and callback verification for Instagram. Request the authorization URL from GET /connect/instagram. Zernio’s default Instagram Login flow supports direct authorization with a professional Instagram account. docs.zernio.com

The platform rules belong in your composer. If a customer selects LinkedIn and Instagram for a text-only announcement, let them know Instagram needs an image or video before they schedule it. The workspace setup, authorization redirect, and POST /posts structure stay familiar as you add each platform. docs.zernio.com

Before you ship, walk through the flow as a customer. Connect a LinkedIn account, confirm the selected destination, publish a text post, and check that it appears on the intended page. Then disconnect the account and verify that your app gives the customer a way to reconnect.

Try Zernio and connect your first social account