All systemsFlownyx — Meta ads command center

API & MCP reference

Meta Marketing API v22.0 registry + our REST routes + MCP tools for external agents.

Meta endpoints
47
Implemented
42
Via Meta MCP
2
Our REST routes
13

Architecture recommendation

Use REST for the UI and deterministic automation. Use MCP when an external agent (Claude Code, Codex) needs strategy context without reimplementing Curt + Hernan.

Layer 1 — Our REST API — sync, bulk ops, entity writes, generation. Typed, testable, same auth as the dashboard.

Layer 2 — Our MCP (POST /api/mcp) — evaluate KPIs, Curt Five Metrics, learning locks, automation plans, image compose. Value-add over raw Meta.

Layer 3 — Official Meta MCP (mcp.metamkt.com) — 29 tools for live reads. OAuth-only, Meta-blessed.

Layer 4 — Pipeboard MCP — deeper writes when official MCP lacks coverage.

MCP tools (our server)

JSON-RPC over POST /api/mcp. Auth: remote agents send Authorization: Bearer <MCP_ACCESS_TOKEN>— this is the owner's personal token and grants full service-role access, so guard it like a root credential. Without a bearer, the browser's Supabase session is used; requests with neither get JSON-RPC error -32001 unauthorized. The GET health check stays open.

Write path: queue_action only queues pause/scale/archive/duplicate proposals into the /actions approval queue — it never touches Meta. There is deliberately no approve/execute tool on this server: approval and execution are human-only, in the app.

list_ad_accounts
list_personas
list_campaigns
evaluate_kpi
evaluate_curt_metrics
evaluate_learning_lock
plan_budget_split
get_automation_plan
list_meta_api_endpoints
list_copy_structures
compose_image
list_canvas_specs
queue_action
trigger_sync
run_landing_scan
list_pending_runs
get_business_brief
list_businesses
get_kpi_summary
list_signals
list_social_connections
get_pinterest_overview
schedule_pins
suggest_pin_slots
trigger_pinterest_analytics_sync

Our REST routes

MethodPathDescription
GET/api/sync/[adAccountId]Pull campaigns, ad sets, ads, insights; recompute KPIs.
POST/api/entities/[id]/statusPause / resume / archive on Meta + mirror.
POST/api/entities/[id]/budgetUpdate budget; optional Hernan +20% scale.
POST/api/bulkBulk pause RED / scale GREEN / archive. dryRun for preview.
POST/api/generateAI copy + image generation pipeline.
POST/api/publishPush generated ad to Meta (PAUSED).
POST/api/agentClaude + Meta MCP analysis chat.
POST/api/mcpOur MCP server (strategy intelligence layer).
GET|PATCH/api/settings/managementManagement mode: manual | hybrid | automated.
POST/api/trackFirst-party pixel event ingestion.
GET/api/cron/sync-allCron: sync all accounts (6h).
GET/api/cron/automateCron: automation runner (12h).
GET/api/cron/refresh-perfCron: refresh AI learning loop (24h).

Meta Marketing API registry

Aligned with official reference docs. Status reflects this codebase.

StatusMethodPathDescriptionLocal route
implementedGET/me/adaccountsList ad accounts for the authenticated user./api/sync (connect flow)
implementedGET/act_{id}/insightsAccount-level insights. Supports async jobs for long ranges./api/sync/[adAccountId]
implementedGET/act_{id}/campaignsList campaigns in an ad account./api/sync/[adAccountId]
implementedGET/act_{id}/adsetsList ad sets in an ad account./api/sync/[adAccountId]
implementedGET/act_{id}/adsList ads in an ad account./api/sync/[adAccountId]
plannedGET/act_{id}/adcreativesList ad creatives.
implementedGET/act_{id}/customaudiencesList custom audiences (Hot 7/28/90 retargeting pools)./strategy/audiences
implementedPOST/act_{id}/customaudiencesCreate customer-list / website-rule / engagement / lookalike audience.
implementedPOST/{audience_id}/usersUpload SHA-256-hashed customer-list users (session batches; DELETE removes).
implementedPOST/{audience_id}/usersreplaceReplace-session upload — swaps the entire customer list.
implementedPOST/{audience_id}/adaccountsShare audience with other ad accounts (targeting / targeting_and_insights).
implementedDELETE/{audience_id}Delete a custom audience.
implementedPOST/act_{id}/adimagesUpload image (multipart or base64 bytes) → image_hash for creatives./api/publish
implementedPOST/act_{id}/advideosUpload video (file or file_url; simple session — chunked TBD for >1GB).
implementedGET/{video_id}Poll video processing status until video_status=ready.
implementedGET/act_{id}/generatepreviewsPreview iframes for a creative spec or creative_id per placement format.
implementedGET/{ad_id}/previewsPreview iframes for an existing ad.
implementedPOST/act_{id}/campaignsCreate campaign (OUTCOME_LEADS, OUTCOME_SALES, etc.).
implementedPOST/{campaign_id}Update campaign status, budget, name./api/entities/[id]/status, /api/entities/[id]/budget
implementedGET/{campaign_id}/insightsCampaign-level performance insights.
implementedPOST/{campaign_id}Archive or delete campaign (status=DELETED)./api/entities/[id]/status
plannedPOST/{campaign_id}/copiesDuplicate campaign (deep_copy, rename_options, status_option). Note: duplication ships via recreate (/api/meta/duplicate — frozen copy from the local mirror), not this endpoint./api/meta/duplicate (recreate)
implementedPOST/act_{id}/adsetsCreate ad set with targeting, budget, optimization goal.
implementedPOST/{adset_id}Update ad set status, budget, targeting./api/entities/[id]/status, /api/entities/[id]/budget
implementedGET/{adset_id}/insightsAd set insights.
implementedPOST/act_{id}/adsCreate ad linked to creative + ad set./api/publish
implementedPOST/{ad_id}Update ad status or name./api/entities/[id]/status
implementedGET/{ad_id}/insightsAd-level insights (CTR, hook rate, CPA).
implementedPOST/act_{id}/adcreativesCreate ad creative (image, video, carousel, post ID)./api/publish
plannedGET/{creative_id}Read creative spec (copy, assets, CTA).
implementedGET/searchTargeting search — interests, geo, locales, schools, employers, categories.
implementedGET/act_{id}/targetingsearchAccount-scoped unified targeting search.
implementedGET/act_{id}/targetingbrowseThe Ads Manager Browse tree for detailed targeting.
implementedGET/act_{id}/targetingsentencelinesHuman-readable summary of a targeting spec.
implementedGET/act_{id}/reachestimateAudience size estimate for targeting spec (-1 = unavailable).
implementedGET/{adset_id|act_id}/delivery_estimateDelivery estimate for an ad set or a candidate targeting spec.
mcpGET/{pixel_id}/statsPixel event stats.
implementedPOST/{pixel_id}/eventsConversions API server events./api/track (first-party) → src/lib/tracking/capi.ts forwarder
implementedPOST/{entity_id}/insightsStart async insights job (report_run_id) for long ranges/breakdowns.
implementedGET/{report_run_id}Poll async insights job status, then fetch /{report_run_id}/insights.
implementedGET/act_{id}/activitiesChange history — budget/status/targeting edits (Ads Manager History parity).
mcpGET/{business_id}/owned_ad_accountsList ad accounts owned by a Business Manager.
implementedGET/me/accountsPages + page tokens + linked IG business account.
implementedGET/{page_id}/published_postsOrganic posts for Golden Ad Process./strategy/golden-ad
implementedGET/{page_post_id}/insightsPost insights (impressions_unique, reactions, clicks, video views).
implementedGET/{ig_user_id}/mediaIG business media list for post-ID ads.
implementedGET/{ig_media_id}/insightsIG media insights (views = unified 2024+ metric).

Settings — configure management mode per account. Dashboard — bulk ops preview + execute.