Meta Ads API from Claude Code: Surviving the UX Maze
Everything the docs don't tell you about creating Facebook ads programmatically
🚀 Kickoff Prompt
Copy this prompt and paste it into your AI assistant to get started:
I want to create a Meta/Facebook ad campaign using the Marketing API. Help me set up: 1. A campaign with daily budget 2. An ad set with interest targeting 3. Ad creative with copy 4. Server-side conversion tracking Before we start, I need to make sure: - My Meta app is in LIVE mode (not development) - I have a fresh access token (they expire in ~1 hour) - I have my Ad Account ID, Page ID, and Pixel ID ready Walk me through each step and warn me about common blockers.
📋 Prerequisites
📖 Guide Content
The Reality Check
Meta's API documentation is comprehensive but assumes you already know where everything lives in their constantly-changing UI. This guide covers the real blockers we hit.
Step 1: Get Your App to LIVE Mode
The Blocker: You cannot create ads via API if your app is in "Development Mode."
Error you'll see:
{"error": {"message": "Application does not have permission for this action"}}
The Fix:
Without a privacy policy URL, Meta won't let you go live.
Step 2: Access Tokens Expire Fast
The Blocker: Default tokens from Graph API Explorer expire in ~1-2 hours.
Error you'll see:
{"error": {"message": "Error validating access token: Session has expired"}}
The Fix:
ads_management and pages_read_engagement permissions
For production, implement token refresh flow or use System User tokens.
Step 3: Campaign Budget Optimization (CBO) Conflicts
The Blocker: If you set budget at campaign level (CBO), you can't also set it at ad set level.
Error you'll see:
{"error": {"message": "Daily budget and lifetime budget are unavailable for this ad set"}}
The Fix:
When using CBO (campaign-level budget), do NOT set budget on the ad set - it inherits from the campaign.
Step 4: Advantage+ Audience Flag
The Blocker: When using flexible/interest targeting, Meta now requires declaring whether you're using Advantage+ audience.
Error you'll see:
{"error": {"message": "targeting_automation is required"}}
The Fix:
Add this to your ad set targeting:
"targeting_automation": {"advantage_audience": 0}
Set to 0 for manual targeting control, 1 for Meta's AI-expanded audience.
Step 5: The Complete Working Flow
Step 6: Server-Side Conversion Tracking
Use the Conversions API for CompleteRegistration events. Hash email with SHA256, include client IP and user agent. Pair with browser-side pixel using matching event_id for deduplication.
Finding Interest Targeting IDs
Use the Targeting Search API:
GET /search?type=adinterest&q=artificial%20intelligence
Common useful IDs:
✅ Verification Steps
Log in to vote