Skip to content

Feeding competitor ads from the Meta Ad Library to an AI agent on a schedule

By Hayden Barnett · · 5 min read

A creative-strategy agent is only as good as what you feed it. “Write five hooks for our spring campaign” gets generic output. “Here are the 40 ads our three closest competitors are running right now, with copy, format and how long each has been live. Find the angles they keep paying for” gets something you can use.

The data is public. Anyone can open the Meta Ad Library in a browser and scroll. Getting it into an agent every morning is where it breaks:

  • The official Ad Library API skips most commercial ads. Ads that didn’t reach the EU only come back if they’re about social issues, elections or politics, so a competitor’s US-only campaign isn’t there. It also needs a Meta developer app and an access token you have to keep alive. (More on that in what the official APIs won’t give you.)
  • Browser automation against the Ad Library page works until it doesn’t. The page is a heavy client app. Selectors move, a login wall can show up mid-scroll, and a headless browser on a cloud IP gets challenged. Then you’re maintaining a Facebook login and a proxy pool for a side feature.
  • Agents don’t do well with half-loaded pages. If your scraper returns 12 ads one day and 31 the next because of a lazy-load race, the agent will report a strategy shift that never happened.

What the agent needs is boring: the same JSON shape every day, with stable ids, so it can tell what’s new, what stopped, and what’s been running for months.

Find the advertiser’s page id once

Ads belong to a Facebook page, and the stable key is the page id. Look it up once and store it:

export FETCHPROOF_API_KEY=fp_your_key

curl -s 'https://api.fetchproof.com/v1/facebook/adLibrary/search/companies?query=COMPETITOR_NAME' \
  --header "x-api-key: $FETCHPROOF_API_KEY"

Each item in searchResults has page_id, name, category, likes, verification, page_alias and, when linked, ig_username and ig_followers. Brands often run several pages (a main page, a regional page, a sub-brand), so check which one actually runs the ads before you save the id. An empty result costs 0 credits.

Pull the ads

With the page id, one call returns that advertiser’s ads:

curl -s 'https://api.fetchproof.com/v1/facebook/adLibrary/company/ads?pageId=PAGE_ID&country=US&status=ACTIVE&sort_by=relevancy_monthly_grouped' \
  --header "x-api-key: $FETCHPROOF_API_KEY"

You can pass companyName instead of pageId and it resolves to the best-matching page, but for a scheduled job the page id is safer: names collide, ids don’t. The filters match the Ad Library’s own: country (a two-letter code or ALL), status (ACTIVE, INACTIVE or ALL, default ACTIVE), media_type (IMAGE, VIDEO and so on), language, start_date and end_date. sort_by=relevancy_monthly_grouped is the Library’s “most recent” order; the default sorts by impressions.

One item in results, trimmed (field names and types are from a real response; identifying values replaced):

{
  "ad_archive_id": "<ad library id>",
  "page_id": "<page id>",
  "page_name": "<advertiser>",
  "is_active": true,
  "start_date": 1744009200,
  "start_date_string": "2025-04-07T07:00:00.000Z",
  "end_date": 1794902400,
  "end_date_string": "2026-11-17T08:00:00.000Z",
  "publisher_platform": ["FACEBOOK", "INSTAGRAM", "AUDIENCE_NETWORK"],
  "collation_count": null,
  "spend": null,
  "reach_estimate": null,
  "url": "https://www.facebook.com/ads/library/?id=<ad library id>",
  "snapshot": {
    "body": { "text": "<primary ad copy>" },
    "title": "<headline>",
    "cta_text": "Install now",
    "cta_type": "INSTALL_MOBILE_APP",
    "display_format": "DPA",
    "link_url": "<landing page url>",
    "images": [],
    "videos": [],
    "cards": [
      {
        "title": "<card headline>",
        "body": "<card copy>",
        "cta_text": "Install Now",
        "link_url": "<product url>",
        "original_image_url": "https://scontent-iad6-1.xx.fbcdn.net/v/...",
        "resized_image_url": "https://scontent-iad6-1.xx.fbcdn.net/v/...",
        "video_hd_url": null,
        "video_sd_url": null
      }
    ],
    "page_like_count": 39489061
  }
}

The response also carries a cursor. Send it back with the same filters for the next page.

What an agent actually needs from that:

  • Copy: snapshot.body.text, snapshot.title, and for carousels and catalog ads, each card’s title and body.
  • Creative: snapshot.display_format (IMAGE, VIDEO, DCO, DPA and others), image URLs in snapshot.images[].original_image_url or the cards, video files in snapshot.videos[].video_hd_url / video_sd_url with a video_preview_image_url poster.
  • Timing: start_date_string is when the ad started delivering. Days live is the best public proxy for “this ad works”, because nobody keeps paying for a loser for four months.
  • Status: trust is_active. On active ads, end_date is the most recent delivery day the Library shows, so it moves forward every day; it isn’t a scheduled stop date.

The same call as an agent tool

If the agent runs in Claude Code, Cursor or Claude Desktop, give it the API as MCP tools instead of writing glue. In Claude Code:

claude mcp add --transport stdio --env FETCHPROOF_API_KEY=fp_your_key fetchproof -- npx -y @fetchproof/mcp

The Ad Library tools are facebook_adLibrary_search_companies, facebook_adLibrary_company_ads, facebook_adLibrary_search_ads (keyword search across all advertisers) and facebook_adLibrary_ad (one ad by id). A prompt that uses them:

For each page id in competitors.txt, call facebook_adLibrary_company_ads with
country=US and status=ACTIVE. For every ad, record ad_archive_id, page_name,
start_date_string, display_format, snapshot.body.text and cta_text.
Group the ads by the offer or angle in the copy. For each group, list how many
ads use it and the oldest start date. Flag any angle that appears for only one
competitor. Write the result to ads-brief.md.

Setup for other clients is in the MCP docs.

Put it on a schedule

The pattern that holds up is: snapshot daily, diff against yesterday, and only hand the agent the diff plus the long-runners. That keeps the context small and the brief about what changed.

A cron job that snapshots each competitor to a dated NDJSON file:

#!/usr/bin/env bash
# ads-snapshot.sh: one line per ad, one file per day
set -euo pipefail
API=https://api.fetchproof.com
day=$(date +%F)
mkdir -p snapshots
: > "snapshots/$day.ndjson"

while read -r page_id; do
  curl -s -G "$API/v1/facebook/adLibrary/company/ads" \
    -H "x-api-key: $FETCHPROOF_API_KEY" \
    --data-urlencode "pageId=$page_id" \
    --data-urlencode "country=US" \
    --data-urlencode "status=ACTIVE" |
  jq -c '.results[]? | {id: .ad_archive_id, page: .page_name, active: .is_active,
    started: .start_date_string, format: .snapshot.display_format,
    copy: .snapshot.body.text, cta: .snapshot.cta_text, link: .snapshot.link_url}' \
    >> "snapshots/$day.ndjson"
done < competitors.txt
# crontab: weekdays at 06:30, before the agent's 07:00 run
30 6 * * 1-5  cd /srv/ads && ./ads-snapshot.sh

The diff is a set comparison on id: ids in today’s file and not yesterday’s are new launches, ids in yesterday’s and not today’s have stopped. Feed the agent the new and stopped ads plus anything active for more than 60 days. If the agent runs headless, claude -p with the brief prompt and --allowedTools limited to the Fetchproof tools works as the 07:00 step.

This script reads the first page per competitor. A brand with a big catalog can have many pages of active ads; follow cursor until you have what you need, or narrow with media_type or start_date so the daily job stays small.

Limits worth knowing before you build on it

  • Spend and reach are mostly null. The Ad Library only discloses spend and reach for political and issue ads and, for reach, ads shown in the EU. For an EU-delivered ad, facebook_adLibrary_ad returns aaa_info audience data. For everything else, days live and the number of variants are what you have.
  • Creative URLs expire. Image and video links are signed CDN URLs. If the agent or a human reviewer needs the file next month, download it when you take the snapshot.
  • Keyword search pages expire. On search/ads, a cursor from page 2 onward is tied to a short-lived upstream session. If it has expired, the response says so and you start again without a cursor. The company ads job above doesn’t hit this in practice because it reads one page per run.
  • No video transcripts. get_transcript=true on the ad endpoint returns a 400. Download the video from snapshot.videos and transcribe it yourself if you need the voiceover.
  • Upstream refusals happen. A blocked or timed-out request returns an error and costs nothing; retry it on the next run rather than in a tight loop.

What it costs

Each call costs 1 credit by default. Errors, blocked or timed-out requests, invalid requests and cache hits cost nothing. A not-found or empty result is charged only where that operation’s published cost says so. For company ads, an empty page costs 0 credits and an unknown companyName is a 404 at 0 credits. So a daily job across 10 competitors, one page each, is 10 calls a day, or about 220 calls a month on weekdays.

New accounts start with 100 free credits, enough to build and test the whole pipeline. Pack sizes and prices are on the pricing page.

Try it without code

The free Meta Ad Library search tool runs a keyword search in the browser and exports page 1 as JSON or CSV, which is a quick way to see the data before you wire it into an agent. If you’d rather run it on Apify, the Facebook Ad Library Actor takes a company name or page id and calls the same endpoints.

Try it with 100 free credits

Sign up with an email address, no card. Credits never expire. Errors, invalid requests and cache hits cost 0 credits, and each endpoint page lists exactly what it charges.