AI Guides / DevOps
DevOps Intermediate Claude Code General

Meta Ads API from Claude Code: Surviving the UX Maze

Everything the docs don't tell you about creating Facebook ads programmatically

by mobes - January 16, 2026 - 3 views

🚀 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

Meta Developer account with a registered app

Facebook Page connected to the app

Ad Account with payment method

Meta Pixel created

Access to Graph API Explorer for token generation

📖 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:

1.Go to developers.facebook.com → My Apps → Your App

2.Navigate to App settings > Basic

3.Add your Privacy Policy URL (required!)

4.Click Save Changes

5.Find the Publish option in the left sidebar → Click Publish


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:

Generate tokens fresh before each API session

Use Graph API Explorer: developers.facebook.com/tools/explorer

Select your app, add ads_management and pages_read_engagement permissions

Click "Generate Access Token"


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

1.Create Campaign with CBO budget

2.Create Ad Set WITHOUT budget (inherits from campaign), WITH targeting_automation flag

3.Create Ad Creative with page_id and link_data

4.Create Ad linking creative to ad set

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:

Artificial Intelligence: 6002898176962

Software Development: 6003409558536

Programming: 6003139266461

Verification Steps

1.Check your campaign in Ads Manager - all components should show as PAUSED

2.The ad will be in PENDING_REVIEW until Meta approves it

3.Test your conversion tracking by triggering a test event and checking Events Manager
#meta-ads #facebook #marketing-api #conversion-tracking #claude-code
0

Log in to vote

No comments yet. Be the first to share your thoughts!

Log in to participate