Facebook Ad Library search API
Search the Meta Ad Library (ads on Facebook, Instagram, Messenger, WhatsApp, Threads and Audience Network) by keyword: 30 ads a page with the creative (text, title, link, call to action, images, videos, carousel cards), the advertiser, delivery dates and placements, in the library’s own JSON. Filters: country, active or inactive, media type, special ad category, language, placement and a delivery date window.
GET /v1/facebook/ads/searchBeta2 credits per callRefunded on failureimport os, requests
res = requests.get(
"https://api.groundsocial.dev/v1/facebook/ads/search?q=running%20shoes&country=US",
headers={"Authorization": f"Bearer {os.environ['GROUNDSOCIAL_API_KEY']}"},
)
res.raise_for_status()
data = res.json(){ "ads": [ { "ad_archive_id": "1339489931715040", "page_id": "71740214065", "page_name": "KURU Footwear", "is_active": true, "start_date": 1783321200, "end_date": 1795507200, "publisher_platform": [ "FACEBOOK", "INSTAGRAM", "… 1 more" ], "collation_count": 1, "collation_id": "1962576714495079", "categories": [ "UNKNOWN" ], "currency": "", "spend": null, "impressions_with_index": { "impressions_text": null, "impressions_index": -1 }, "reach_estimate": null, "…": "16 more fields" }, { "ad_archive_id": "2087216342231765", "page_id": "380039845369159", "page_name": "SHEIN", "is_active": true, "start_date": 1784271600, "end_date": 1795507200, "publisher_platform": [ "FACEBOOK", "INSTAGRAM" ], "collation_count": null, "collation_id": null, "categories": [ "UNKNOWN" ], "currency": "", "spend": null, "impressions_with_index": { "impressions_text": null, "impressions_index": -1 }, "reach_estimate": null, "…": "16 more fields" }, "… 2 more" ], "count": 50001, "page_info": { "has_next_page": true, "end_cursor": "AQHTENf1iSXzN3Of5tndjGUMLkaZgZ136jt8lT5WV_l52Al2qA9KQ9L1c5a9PV0OHq9G" }}Parameters
| Name | Type | Description |
|---|---|---|
qquery · required | string | Keyword or phrase. Example: running shoes. |
search_typequery | "keyword_unordered" | "keyword_exact_phrase" | keyword_unordered (default: all the words, any order) or keyword_exact_phrase. One of keyword_unordered, keyword_exact_phrase. |
countryquery | string | ISO 3166-1 alpha-2 country the ads reached (US, GB, DE…), or ALL (default). |
statusquery | "active" | "inactive" | "all" | active (default), inactive, or all. One of active, inactive, all. |
media_typequery | "all" | "image" | "video" | "meme" | "image_and_meme" | "none" | all (default), image, video, meme (image with text), image_and_meme, none (text only). One of all, image, video, meme, image_and_meme, none. |
ad_typequery | "all" | "political_and_issue_ads" | "housing" | "employment" | "credit" | "financial" | all (default), or one of Meta’s special ad categories: political_and_issue_ads, housing, employment, credit, financial. One of all, political_and_issue_ads, housing, employment, credit, financial. |
sort_byquery | "total_impressions" | "relevancy_monthly_grouped" | "total_active_time" | total_impressions (default, high to low), relevancy_monthly_grouped (most recent), or total_active_time (longest-running first, within each page of 30). One of total_impressions, relevancy_monthly_grouped, total_active_time. |
languagequery | string | Comma-separated ISO 639-1 languages of the ad text (en,es). |
publisher_platformsquery | string | Comma-separated placements: facebook, instagram, audience_network, messenger, whatsapp, threads, oculus. |
start_datequery | string | YYYY-MM-DD: only ads delivered on or after this day. |
end_datequery | string | YYYY-MM-DD: only ads delivered on or before this day. |
afterquery | string | The previous page’s page_info.end_cursor; keep the other filters the same. |
Response fields
200 with a FacebookAdsPage, in Facebook’s own JSON.
| Field | Type | Description |
|---|---|---|
ads | FacebookAd[] | |
count | integer | null | Meta’s estimate of how many ads match, on the first page (null on later pages). Meta caps it at 50,001. |
page_info | object |
Status codes
| Status | Meaning |
|---|---|
200 | A page of ads, with the next cursor. |
400 | Invalid input. Nothing was charged. |
401 | Missing or invalid API key. |
402 | Not enough credits, a spend cap was reached, or payment is required. |
403 | The target is private, or the account is suspended. |
404 | The ad, Page or advertiser is not in the Meta Ad Library. |
429 | Too many requests. Wait for Retry-After seconds. |
503 | Facebook is temporarily unavailable. Retryable; nothing was charged. |
Every error has code, message, hint and retryable. All error codes
Questions
How do I get the next page?
Pass page_info.end_cursor as after with the same filters. The first page also carries count, Meta’s estimate of all matches (capped at 50,001).
Is this the official Ad Library API?
No. It reads what the public Ad Library website shows anyone, logged out, for every country and every ad type, not only political ads. Not affiliated with Meta Platforms, Inc.
Facebook is a trademark of Meta Platforms, Inc. We are not affiliated with or endorsed by Meta.