Developer Guide Updated 2026-11-28

How to Read Meta Ad Library Data with an API

Learn how to read Meta Ad Library data with an API in Python, Node.js, cURL, and MCP. Search commercial Facebook and Instagram ads without Graph ID limits.

Knowing how to read Meta Ad Library data with an API is essential if you are building competitive ad intelligence dashboards, UGC creative research agents, or automated ROAS benchmarking scripts. While anyone can manually browse facebook.com/ads/library in a web tab, extracting structured JSON for active Facebook and Instagram ads programmatically hits surprising roadblocks if you rely solely on Meta's official Graph endpoint.

Want to test live ad queries right away? Open our interactive Meta Ad Library API inspector or claim 100 free credits (no credit card needed) to run 25 free Meta ad searches today.

Why Meta's official Graph ads_archive API blocks most commercial queries

When developers first open Meta's official Ad Library API documentation (graph.facebook.com/v21.0/ads_archive), they expect to query ecommerce, SaaS, gaming, or DTC brand ads worldwide. In practice, Meta's official Graph endpoint enforces two strict limitations:

  1. Geographic & category restrictions: Outside of ads delivered to the European Union or the United Kingdom, Meta's official ads_archive API only returns ads about social issues, elections, or politics. Querying US, Canadian, Australian, or Asian commercial product ads via the official Graph API returns zero results.
  2. Government ID & local residency verification: Obtaining an official ads_archive access token requires uploading government-issued photo ID, waiting for physical mail or identity verification, and maintaining an active Facebook Developer App review status.

By using a dedicated commercial Meta Ad Library API endpoint instead, your Python scripts, Node.js services, and MCP agents can query public commercial ads globally (including US, UK, EU, APAC, and LATAM markets) using a single bearer key—with direct creative media URLs and spoken video transcripts included.

Step 1: Claim your API key (100 free credits, 0 card required)

  1. Sign in with Google or email OTP at https://socialtoai.app/sign-in/ to receive 100 free credits.
  2. Generate a stai_live_... API key in Console → API Keys.
  3. Each Meta Ad Library search or creative lookup costs 4 credits on success, and 0 credits if an upstream request fails or times out.

Step 2: Search active Facebook & Instagram ads via cURL

You can query active or historical ads by keyword, brand name, landing page domain, or Facebook page_id. Filtering for ads that have remained ACTIVE for 30+ days is the fastest way to isolate profitable competitor creatives:

curl -sS -X POST "https://socialtoai.app/v1/call" \
  -H "Authorization: Bearer stai_live_YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "capability": "meta_ads.search",
    "query": "collagen peptides",
    "country": "US",
    "active_status": "ACTIVE",
    "limit": 20,
    "idempotency_key": "meta-ads-collagen-us-p1"
  }'

Normalized Meta Ad JSON structure

Every ad record returned in the items array exposes clean creative, placement, and longevity metadata ready for database ingestion or LLM reasoning:

{
  "request_id": "req_meta_7721904",
  "envelope_status": "ok",
  "capability": "meta_ads.search",
  "billing": {
    "credits": 4,
    "failed_call_charge": 0,
    "balance_credits": 96
  },
  "items": [
    {
      "ad_archive_id": "119482039481029",
      "page_id": "109283746512",
      "page_name": "PureGlow Nutrition",
      "active_status": "ACTIVE",
      "start_date": "2026-09-14",
      "active_days": 75,
      "platforms": ["facebook", "instagram", "audience_network"],
      "body_text": "Tired of chalky morning scoops? Try tasteless marine peptides backed by clinical trials.",
      "cta_text": "Shop Now",
      "link_url": "https://pureglow.example.com/offer-v3",
      "media_type": "video",
      "media_urls": [
        "https://cdn.socialagentapi.com/ads/meta_119482039481029.mp4"
      ]
    }
  ],
  "page": {
    "has_more": true,
    "cursor": "eyJvZmZzZXQiOjIwfQ=="
  }
}

Step 3: Python script — Filter 30+ day winning ads by competitor domain

Media buyers and AI agents rarely care about 2-day test ads that lost money and got shut off. Below is a complete Python workflow that paginates through a competitor's active ads, filters for creatives running 30 days or longer, and extracts their copy, CTA, and video URLs:

import os
import requests

API_KEY = os.environ["SOCIAL_AGENT_API_KEY"]
ENDPOINT = "https://socialtoai.app/v1/call"
HEADERS = {
    "Authorization": f"Bearer {API_KEY}",
    "Content-Type": "application/json",
}

def find_evergreen_meta_ads(query: str, country: str = "US", min_days: int = 30):
    winners = []
    cursor = None

    for page_num in range(1, 4):  # Fetch up to 3 pages
        payload = {
            "capability": "meta_ads.search",
            "query": query,
            "country": country,
            "active_status": "ACTIVE",
            "limit": 20,
        }
        if cursor:
            payload["cursor"] = cursor

        resp = requests.post(ENDPOINT, headers=HEADERS, json=payload, timeout=35)
        resp.raise_for_status()
        data = resp.json()

        for ad in data.get("items", []):
            if (ad.get("active_days") or 0) >= min_days:
                winners.append({
                    "ad_archive_id": ad.get("ad_archive_id"),
                    "advertiser": ad.get("page_name"),
                    "active_days": ad.get("active_days"),
                    "cta": ad.get("cta_text"),
                    "landing_url": ad.get("link_url"),
                    "body": ad.get("body_text"),
                    "media": ad.get("media_urls", []),
                })

        page_info = data.get("page") or {}
        if not page_info.get("has_more"):
            break
        cursor = page_info.get("cursor")

    return winners

if __name__ == "__main__":
    long_running = find_evergreen_meta_ads("AI meeting notes", country="US", min_days=30)
    print(f"Found {len(long_running)} evergreen Meta ads running 30+ days")

Step 4: Query Meta Ad Library directly from Claude, Cursor, or Antigravity via MCP

If you prefer conversational competitive analysis over writing Python scripts, mount our social media MCP server (https://socialtoai.app/mcp) inside Google Antigravity, Claude Desktop, Claude Code, Cursor, or ChatGPT. Once connected, your AI assistant can combine ad library lookups with organic video script analysis in one prompt:

{
  "mcpServers": {
    "social-agent-api": {
      "serverUrl": "https://socialtoai.app/mcp",
      "headers": {
        "Authorization": "Bearer stai_live_YOUR_API_KEY"
      }
    }
  }
}

Example prompt in Antigravity or Claude:

  • "Search Meta Ad Library in the US for active ads mentioning 'AI resume builder', pick the 5 longest-running video ads, summarize their primary landing page offers, and compare their hooks with organic TikTok videos via TikTok Transcript API."

Expanding from Meta Ads to cross-channel creative intelligence

Winning DTC and SaaS creative teams rarely stop at Facebook and Instagram placements:

  • Compare paid vs. organic short-form hooks: Pair Meta video ad copy with organic viral scripts extracted through our TikTok Transcript API.
  • Spot early product trends in Asia: Check emerging consumer angles on RedNote and Douyin via our Xiaohongshu MCP Server weeks before those creatives appear in Western Meta Ad Library feeds.
  • Keep costs strictly predictable: Standard Meta, TikTok Creative Center, and LinkedIn ad calls cost 4 credits each, failed calls cost 0 credits, and prepaid credit packs start at $10 = 3,000 credits on our pricing page.

Open the live Meta Ad Library API page now to inspect sample payloads and connect your agent.

Frequently asked questions about reading Meta Ad Library data via API

Why does Meta's official Ad Library Graph API return empty results for US commercial ads?

Meta's official Graph ads_archive endpoint restricts commercial (non-political) ad searches to ads delivered in the EU/UK and requires government ID verification. Our Meta Ad Library API lets developers query public commercial ecommerce, SaaS, and app ads globally across the US, UK, EU, and APAC with a standard API key.

How much does it cost to query Meta Ad Library data via API?

Each successful Meta Ad Library search or ad detail call costs 4 credits (~$0.008 to $0.013 on prepaid packs). New accounts get 100 free credits on sign-up, and failed calls cost 0 credits.

Does the API return active run duration, landing page URLs, and video files?

Yes. Every ad item includes active_status, start_date, active_days, CTA button text, destination landing page URL, ad body copy, and direct image/MP4 media URLs.