Everything a developer needs to finish connecting Instagram to the ICONIC client platform.
Last updated: 4 April 2026
iconic-contract-signed in GHL (GoHighLevel CRM)
↓
AUTO-SMS (5-min cron in serve_reports.js)
Detects the tag → sends registration SMS with link → tags iconic-reg-link-sent
↓
REGISTER /iconic/register.html?email=X&name=X&tier=entry&icn=ICN-XXXXXX
Client opens link → sets password → POST /api/iconic/register
→ Saves to Supabase + iconic_clients.json
→ Updates GHL (name, custom fields, pipeline opportunity)
→ Auto-login → redirect to dashboard
↓
DASHBOARD /iconic/dashboard.html
Client sees: photos, stats, plan info, upload prompt, Instagram section
↓
CONNECT INSTAGRAM
Client clicks "Connect Instagram Account"
→ Goes to /iconic/instagram_onboarding.html (setup guide)
→ Steps 1-3: Business account + Facebook Page + link them (client does on phone)
→ Steps 4-6: Meta Developer App + credentials + token (admin does once)
→ Step 7: Click "Connect" → auto-setup exchanges token → saves config
↓
AUTO-POSTING (after connected)
System posts AI photos to client's Instagram automatically
Admin monitors via /iconic/instagram_admin.html
| Component | File | Status | Notes |
|---|---|---|---|
| Graph API wrapper | Iconic/instagram_post.js | DONE | Single + carousel posting, container polling, caption gen. 455 lines. |
| OAuth + client management | Iconic/instagram_manager.js | DONE | Token exchange, per-client tokens, queue, health checks. 597 lines. |
| 14 API endpoints | serve_reports.js | DONE | OAuth flow, posting, admin CRUD, config, health. See Section 4. |
| Onboarding guide | Iconic/instagram_onboarding.html | DONE | 7-step click-by-click setup with auto-connect button. |
| Client dashboard IG section | Iconic/dashboard.html | DONE | Connected/not-connected states, disconnect button. |
| Admin dashboard | Iconic/instagram_admin.html | PARTIAL | UI built. JS needs wiring to admin endpoints. |
| Content generation | Iconic/generate_social.js | DONE | 60+ styles (feed/stories/reels), male + female. |
| Client setup guide | Iconic/instagram_client_setup.html | DONE | "I have IG" vs "I need IG" paths. |
| Meta App credentials | ig_app_config.json | EMPTY | BLOCKER. Needs human to create Meta Developer App. |
| Scheduled posting cron | serve_reports.js | TODO | processScheduledPosts() exists but nothing calls it. |
| Admin endpoint auth | serve_reports.js | TODO | All /api/instagram/admin/* endpoints are unprotected. |
| File | Purpose | Lines |
|---|---|---|
Iconic/instagram_post.js | Low-level Graph API v22.0 wrapper. Single image + carousel posting. Container creation → polling → publishing. Exported: graphRequest, createMediaContainer, publishMedia, createCarousel, postWithToken, postCarouselWithToken, verifyAccount, makeConfig, generateCaption | 455 |
Iconic/instagram_manager.js | Per-client OAuth, token storage, posting queue, health checks. Exported: getOAuthUrl, handleCallback, saveClientInstagram, disconnectClient, postToClient, postCarouselToClient, queuePost, processScheduledPosts, checkTokenHealth, checkAllTokenHealth, getAllClientsInstagramStatus, updateClientSettings, getPostingHistory, loadAppConfig, saveAppConfig | 597 |
serve_reports.js | Main server. All 14 Instagram API endpoints live here. Also has the auto-setup endpoint and checkInstagramStatus function. | 7374 |
ig_app_config.json | Meta App ID + Secret storage. Currently EMPTY. Auto-setup endpoint also saves access token and IG account ID here. | 4 |
iconic_clients.json | Client database. Each client gets an .instagram object added after OAuth with: connected, username, igAccountId, pageId, accessToken, status, postCount, autoPost, postsPerWeek | ~53 |
Iconic/instagram_onboarding.html | 7-step setup guide. Steps 1-3 (phone), Steps 4-6 (Meta developer portal), Step 7 (auto-connect button calls /api/instagram/auto-setup). | ~500 |
Iconic/instagram_admin.html | Admin dashboard: client list, config form, posting history, token health check. UI built, JS partially wired. | ~150 |
Iconic/generate_social.js | 60+ Instagram content styles (feed 1:1, stories 9:16, reels 9:16). Male + female variants. Uses OHWX LoRA trigger word. | ~150 |
| Method | Path | Auth | What It Does |
|---|---|---|---|
| GET | /api/instagram/status | None | Check if central @iconicbyai account is configured. Checks process.env → ig_app_config.json → Windows env vars. |
| GET | /api/instagram/connect | Session cookie | Redirects client to Meta OAuth. Encodes email in state param. Requires Meta App ID to be saved. |
| GET | /api/instagram/callback | Public (Meta redirect) | Handles OAuth callback. Exchanges code → short-lived → long-lived token. Finds IG account. Saves to iconic_clients.json. Redirects to dashboard. |
| GET | /api/instagram/client-status | Session cookie | Returns logged-in client's IG status: connected, username, postCount, autoPost, followers. |
| POST | /api/instagram/disconnect | Session cookie | Clears client's IG tokens and sets status to disconnected. |
| POST | /api/instagram/post-now | None | Immediately posts a photo to a client's IG. Body: {email, photoFile, caption}. |
| POST | /api/instagram/auto-setup | None | One-click setup: takes shortLivedToken, exchanges for long-lived, finds IG account, saves everything to ig_app_config.json + process.env. |
| GET | /api/instagram/admin/clients | None | List all clients with their IG connection status. |
| POST | /api/instagram/admin/settings | None | Update client's autoPost and postsPerWeek. Body: {email, autoPost, postsPerWeek}. |
| GET | /api/instagram/admin/history | None | Get last 50 posts across all clients. |
| GET | /api/instagram/admin/config | None | Get Meta App ID (no secret exposed). |
| POST | /api/instagram/admin/config | None | Save Meta App ID + Secret. Body: {appId, appSecret}. |
| POST | /api/instagram/admin/queue | None | Queue a photo for scheduled posting. Body: {email, photoFile, caption, scheduledFor}. |
| POST | /api/instagram/admin/check-health | None | Check token health for all connected clients. |
A human with a Facebook account needs to do these steps. The onboarding guide at /iconic/instagram_onboarding.html walks through this click-by-click:
ig_app_config.json will be populated and all OAuth flows will work. No code changes needed.The function processScheduledPosts() in instagram_manager.js already processes queued posts. It just needs to be called on a schedule.
Add this to serve_reports.js near the existing cron jobs (search for cron.schedule):
// Instagram scheduled posting — every 30 minutes
cron.schedule('*/30 * * * *', async () => {
try {
const igm = getIgManager();
const count = await igm.processScheduledPosts();
if (count > 0) console.log(`[IG Scheduler] Posted ${count} scheduled items`);
} catch (e) {
console.error('[IG Scheduler] Error:', e.message);
}
}, { timezone: 'America/Chicago' });
All /api/instagram/admin/* endpoints currently have no auth. Add a check for an admin session or API key before each one. Pattern:
// Add at the top of each admin endpoint: const adminEmails = ['[email protected]']; // or check a role const sessionToken = parseCookies(req).iconic_session; const email = getEmailFromSession(sessionToken); if (!email || !adminEmails.includes(email)) { res.writeHead(401, { 'Content-Type': 'application/json' }); return res.end(JSON.stringify({ ok: false, error: 'Admin access required' })); }
Iconic/instagram_admin.html has the UI built but needs its JavaScript completed to call the admin API endpoints (fetch clients, save config, check health, view history, queue posts).
Long-lived page tokens don't expire, but user tokens last 60 days. If a client's token dies:
checkTokenHealth() already detects this and sets status: 'token_expired'After a client connects Instagram, their record in iconic_clients.json gets an .instagram field:
{
"[email protected]": {
"name": "Neil Spence",
"tier": "entry",
"plan": "entry",
"password": "...",
"instagram": {
"connected": true,
"username": "iconicbyai",
"igAccountId": "17841400000000",
"pageId": "123456789",
"accessToken": "EAA...long_page_token...",
"connectedAt": "2026-04-04T12:00:00.000Z",
"lastPostAt": null,
"postCount": 0,
"autoPost": false,
"postsPerWeek": 3,
"status": "active",
"followers": 150,
"profilePic": "https://..."
}
}
}
| Page | URL | Who Sees It |
|---|---|---|
| Setup Guide | reports.iconicbyai.com/iconic/instagram_onboarding.html | Admin (one-time setup) |
| Client Dashboard | reports.iconicbyai.com/iconic/dashboard.html | Clients (has IG section) |
| Client Setup | reports.iconicbyai.com/iconic/instagram_client_setup.html | Clients (OAuth guide) |
| Admin Dashboard | reports.iconicbyai.com/iconic/instagram_admin.html | Admin only |
| Admin Hub | reports.iconicbyai.com/iconic/hub | Admin only |
| Instagram Preview | reports.iconicbyai.com/iconic/instagram_preview.html | Clients |