# Facebook Ads Library API & Instagram Ads Scraper (`whoareyouanas/facebook-ads-library-api`) Actor

Facebook Ads Library API for developers and AI agents. Search Facebook and Instagram ads by keyword, Page ID or Ad Library URL and get ad copy, images, videos, CTAs, landing pages and dates as JSON in seconds. No Meta token, login or proxy setup. Exact ad limits. MCP-ready.

- **URL**: https://apify.com/whoareyouanas/facebook-ads-library-api.md
- **Developed by:** [Anas Nadeem](https://apify.com/whoareyouanas) (community)
- **Categories:** Social media, Marketing, Agents
- **Features:** Limited permissions
- **Stats:** 2 total users, 2 monthly users, 93.9% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $2.50 / 1,000 ads

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

**Facebook Ads Library API** for developers and AI agents. Search the Meta Ad Library for **Facebook and Instagram ads** by keyword, advertiser Page ID or a pasted Ad Library URL, and get every ad back as clean JSON. Each ad comes with its copy, headline, call to action, landing page, image and video URLs, advertiser and dates.

✅ No Meta access token  ·  ✅ No Facebook login  ·  ✅ No proxy setup  ·  ✅ Exact ad limits  ·  ✅ JSON, CSV or Excel

Send one keyword and get ads back in seconds. Call it from Python, JavaScript or any HTTP client, give it to Claude or another AI agent through MCP, or run it from Apify Console with no code.

### What can this Facebook Ads Library API do?

- ⚡ **Returns ads in seconds.** In our November 2026 cloud tests, searches for 10 to 50 ads finished in 4.5 to 9.5 seconds, and 150 ads took under a minute. It reads Meta's search data directly, with no browser and no page scrolling.
- 🛡️ **Works out of the box.** Residential proxies are built in and included in the price. There is nothing to configure: no proxy, no cookies, no Meta developer app.
- 🔎 **Searches three ways.** Use a keyword, an advertiser's Facebook Page ID, or any Ad Library search URL copied from your browser, with its filters kept.
- 🖼️ **Captures every creative.** You get images, videos with preview images, and every card and version of carousel, dynamic creative and catalog ads.
- 📸 **Covers Instagram too.** Every ad lists where it ran: Facebook, Instagram, Messenger, Threads, WhatsApp or Audience Network. You can also limit a search to Instagram.
- 🤝 **Labels partnership ads.** Branded-content ads name the creator separately from the brand that paid for them, which is useful for influencer research.
- 📅 **Filters by date, country and status.** Search active, inactive or all ads in any country, and choose image or video creatives and a date range.
- 🎯 **Stops exactly at your limit.** `maxAds: 100` returns at most 100 unique ads, one row per ad, so you never pay for more than you asked for.
- 🤖 **Is ready for AI agents.** One required field, flat JSON, a cost you can work out before the call, and a run summary that says what happened.

### Facebook Ads Library API vs Meta's official Ad Library API

This Actor is an independent, unofficial Ad Library API run on Apify. It reads the same public Ad Library that anyone can open in a browser.

| | This Actor | Meta's official Ad Library API |
|---|---|---|
| Setup | An Apify account or API token | A Meta developer account, identity verification and an access token |
| Commercial ads (brands, ecommerce, apps) | All countries in the Ad Library | Only ads delivered in the EU; elsewhere, only political and issue ads |
| Creatives | Direct image and video URLs, with video preview images | A snapshot link for each ad |
| Output | JSON, CSV or Excel, an API, or MCP for AI agents | JSON from the Graph API |

### What data can you extract from the Facebook Ad Library?

| Data | Fields |
|---|---|
| Ad identity | `libraryID`, `adLibraryUrl` |
| Advertiser | `pageId`, `brand`, `brandLogo` |
| Partnership (branded content) | `collaboratorName`, `collaboratorPageId`, `collaboratorLogo` |
| Copy and headline | `body`, `linkTitle`, `linkDescription` |
| Call to action and landing page | `ctaText`, `ctaUrl`, `linkUrl` |
| Creatives | `images`, `videos` (with `poster` preview images and `duration`), `cards`, `format` |
| Status and placements | `active`, `platforms`, `totalPlatforms` |
| Dates | `startDate`, `endDate`, `runningTAT` (days running), `scrapeDate` |
| More context | `similarAdCount`, `multipleVersions`, `sourceUrl` |

### How to scrape Facebook ads in 3 steps

1. Enter a **search keyword**, a **Facebook Page ID**, or an **Ad Library search URL**.
2. Set **Maximum ads**, and optionally choose the country, ad status, media type and dates.
3. Click **Start**, then view the ads or export them as JSON, CSV or Excel.

To follow several brands, save one task per brand and schedule it daily or weekly.

### Input examples

#### Search Facebook ads by keyword

```json
{
  "searchQuery": "protein powder",
  "country": "US",
  "maxAds": 100
}
```

#### Export a competitor's Facebook and Instagram ads

Use the advertiser's Page ID, the number after `view_all_page_id=` in its Ad Library URL. Our [Facebook Page ID Finder](https://apify.com/whoareyouanas/meta-brand-dropdown-search) turns a brand name into a Page ID. This example collects Burger King's active US ads:

```json
{
  "pageId": "134615383218473",
  "country": "US",
  "activeStatus": "active",
  "maxAds": 100
}
```

#### Find ads that ran in a date range

`dateFrom` and `dateTo` use Meta's own Ad Library date filter. It matches every ad that ran at some point in the range:

```json
{
  "pageId": "134615383218473",
  "dateFrom": "2026-11-01",
  "dateTo": "2026-11-10",
  "maxAds": 100
}
```

#### Scrape Instagram ads

Paste an Ad Library URL filtered to Instagram placements. Any filter from the Ad Library website works the same way:

```json
{
  "targetUrl": "https://www.facebook.com/ads/library/?active_status=active&ad_type=all&country=US&media_type=all&publisher_platforms[0]=instagram&q=skincare&search_type=keyword_unordered",
  "maxAds": 50
}
```

#### Download Facebook ad videos

Set `mediaType` to `video` to get direct MP4 links, preview images and durations:

```json
{
  "searchQuery": "running shoes",
  "mediaType": "video",
  "maxAds": 20
}
```

### Output example

One ad from the Burger King search above, as returned on November 20, 2026. Long media links are shortened here.

```json
{
  "libraryID": "2426205064851511",
  "adLibraryUrl": "https://www.facebook.com/ads/library/?id=2426205064851511",
  "pageId": "134615383218473",
  "brand": "Burger King",
  "brandLogo": "https://scontent-lax3-1.xx.fbcdn.net/v/t39.35426-6/…",
  "collaboratorName": null,
  "collaboratorPageId": null,
  "collaboratorLogo": null,
  "active": true,
  "body": "We're giving BK a glow up!",
  "linkTitle": "Meet the new Burger King",
  "linkDescription": "",
  "linkUrl": "https://burgerking.app.link/wtlXQwl6O7b",
  "ctaText": "Order now",
  "ctaUrl": "https://burgerking.app.link/wtlXQwl6O7b",
  "platforms": ["FACEBOOK", "INSTAGRAM"],
  "totalPlatforms": 2,
  "similarAdCount": 2,
  "multipleVersions": false,
  "images": [],
  "videos": [
    {
      "url": "https://video-lax3-2.xx.fbcdn.net/o1/v/t2/f2/m366/…",
      "duration": null,
      "poster": "https://scontent-lax3-2.xx.fbcdn.net/v/t39.35426-6/…"
    }
  ],
  "cards": [],
  "startDate": "2026-11-16T08:00:00.000Z",
  "endDate": null,
  "runningTAT": 3,
  "format": "video",
  "sourceUrl": "https://www.facebook.com/ads/library/?active_status=active&ad_type=all&country=US&media_type=all&search_type=page&view_all_page_id=134615383218473",
  "scrapeDate": "2026-11-20T00:30:42.954Z"
}
```

### How much does the Facebook Ads Library API cost?

You pay only for ads delivered to your dataset, and the price drops on every paid Apify plan. These are the prices at the time of writing; check the **Pricing** tab for the current rates.

| Apify plan | Per 1,000 ads | 100 ads | 10,000 ads |
|---|---:|---:|---:|
| Free | $4.00 | $0.40 | $40 |
| Starter | $3.50 | $0.35 | $35 |
| Scale | $3.00 | $0.30 | $30 |
| Business | $2.50 | $0.25 | $25 |

- **Nothing else to pay:** no start fee, no proxy bill, no extra charge for creatives or advertiser fields.
- **Below Apify's own Facebook Ads Library Scraper** on every standard plan: it charged $5.80, $5.00, $4.20 and $3.40 per 1,000 ads in November 2026.
- **Free to try:** Apify's free plan includes $5 of usage every month, enough for up to 1,250 ads.
- **Enterprise plans** pay the Business price.
- **Budget control:** `maxAds` and the run's maximum charge both stop the run exactly at your limit, and duplicate ads are never charged.

### Facebook Ads Library API for AI agents (MCP)

Give Claude, Cursor, Codex or any other MCP client access to the Ad Library through the hosted [Apify MCP server](https://docs.apify.com/mcp):

```text
https://mcp.apify.com?tools=whoareyouanas/facebook-ads-library-api
```

For a client that accepts an `mcpServers` configuration:

```json
{
  "mcpServers": {
    "apify-facebook-ads-library": {
      "url": "https://mcp.apify.com?tools=whoareyouanas/facebook-ads-library-api"
    }
  }
}
```

Sign in with Apify OAuth when prompted. For a token-based client, add `"headers": {"Authorization": "Bearer YOUR_APIFY_TOKEN"}` to the server entry. The [Apify MCP configurator](https://mcp.apify.com/) has the setup for each client. An agent with no Apify account can [buy a prepaid, spend-capped token](https://docs.apify.com/agents/payments) and pay per run.

Example prompts:

> Find 20 active Nike ads in the US with whoareyouanas/facebook-ads-library-api and summarize their hooks, offers and calls to action, with links to each ad.

> Pull the last 30 days of ads from Facebook Page 134615383218473 and group them by format and landing page.

#### Notes for AI agents

- **Minimum input:** one of `searchQuery`, `pageId` or `targetUrl`, plus `maxAds`. For example, `{"searchQuery": "nike", "maxAds": 20}`. Everything else has a default.
- **No setup:** don't send proxy, cookie or token settings. Residential proxies are built in.
- **Cost before the call:** at most `maxAds` × $0.004 on Apify's free plan, and $0.0025-0.0035 per ad on paid plans (see [pricing](#how-much-does-the-facebook-ads-library-api-cost)). 20 ads cost at most $0.08, with no start fee.
- **Clear errors:** an invalid input fails at once, before any charge. The message names the field and lists the supported ones.
- **Reading the result:** the dataset holds the ads. `RUN_SUMMARY` says how many were delivered and why the run stopped (see [Run summary](#run-summary)), and the run's status message says the same in one sentence.
- **Synchronous calls:** searches of up to 150 ads finish well within the 300-second limit of [synchronous API runs](#use-the-facebook-ads-library-api-from-python-javascript-or-curl).

### Use the Facebook Ads Library API from Python, JavaScript or cURL

You need an [Apify API token](https://console.apify.com/settings/integrations), not a Meta token. One synchronous request starts the run and returns the ads:

```bash
curl --request POST \
  'https://api.apify.com/v2/acts/whoareyouanas~facebook-ads-library-api/run-sync-get-dataset-items' \
  --header "Authorization: Bearer ${APIFY_TOKEN}" \
  --header 'Content-Type: application/json' \
  --data '{"searchQuery":"protein powder","country":"US","maxAds":20}'
```

Python, with the `apify-client` package:

```python
import os
from apify_client import ApifyClient

client = ApifyClient(os.environ["APIFY_TOKEN"])
run = client.actor("whoareyouanas/facebook-ads-library-api").call(
    run_input={"pageId": "134615383218473", "country": "US", "maxAds": 500}
)
items = client.dataset(run["defaultDatasetId"]).list_items().items
```

JavaScript, with the `apify-client` package:

```js
import { ApifyClient } from 'apify-client';

const client = new ApifyClient({ token: process.env.APIFY_TOKEN });
const run = await client.actor('whoareyouanas/facebook-ads-library-api').call({
  pageId: '134615383218473',
  country: 'US',
  maxAds: 500,
});
const { items } = await client.dataset(run.defaultDatasetId).listItems();
```

To send ads to Google Sheets, Slack, n8n, Make or Zapier, use Apify's [integrations](https://docs.apify.com/integrations) or a webhook. The **API** tab has examples in more languages.

### Use cases

- **Competitor research:** see every ad a competitor runs, with its offers, hooks and landing pages.
- **Winning ads and products:** long-running active ads (a high `runningTAT`) are the ones advertisers keep paying for. This is useful for ecommerce and dropshipping research.
- **Creative swipe files:** collect videos, images and carousel cards by keyword, industry or brand.
- **Influencer and partnership research:** find which creators run branded-content ads for a brand.
- **Agency reporting and monitoring:** schedule a task per client or competitor and compare Library IDs between runs to spot new ads.
- **AI research agents:** let an agent pull live ads and summarize angles, offers and calls to action.

### Example tasks

Open an example, select **Try for free** to copy it into your account, and swap in your own keyword or Page ID.

**Competitor and brand research**

- [View a competitor's Facebook ads by Page ID](https://apify.com/whoareyouanas/facebook-ads-library-api/examples/competitor-facebook-page-ads): Burger King's active US ads, 50 ads.
- [Find active Nike ads on Facebook and Instagram](https://apify.com/whoareyouanas/facebook-ads-library-api/examples/nike-facebook-instagram-ads): keyword search for a brand, 10 ads.
- [Facebook Ads Library product research](https://apify.com/whoareyouanas/facebook-ads-library-api/examples/facebook-ads-product-research): ecommerce ads that mention "50% off free shipping", 50 ads.

**Ad examples by type and industry**

- [Facebook lead ad examples](https://apify.com/whoareyouanas/facebook-ads-library-api/examples/facebook-lead-ad-examples): "get a free quote" ads with their Get Quote and Sign Up buttons, 30 ads.
- [Real estate Facebook ad examples](https://apify.com/whoareyouanas/facebook-ads-library-api/examples/real-estate-facebook-ads): exact phrase "homes for sale", 30 ads.
- [Photography Facebook ad examples](https://apify.com/whoareyouanas/facebook-ads-library-api/examples/photography-facebook-ad-examples): exact phrase "photography session", 30 ads.

**Filters and exports**

- [Download Facebook Ad Library videos](https://apify.com/whoareyouanas/facebook-ads-library-api/examples/facebook-ad-library-video-downloader): video ads with direct MP4 links, preview images and durations, 20 ads.
- [Export Facebook Ads Library search results from a URL](https://apify.com/whoareyouanas/facebook-ads-library-api/examples/facebook-ads-library-search-export): a pasted UK image-ad search, 25 ads.
- [Scrape Instagram ads for a keyword](https://apify.com/whoareyouanas/facebook-ads-library-api/examples/instagram-ads-by-keyword): an Ad Library URL limited to Instagram placements, 25 ads.
- [Find Facebook ads that ran in a date range](https://apify.com/whoareyouanas/facebook-ads-library-api/examples/facebook-ads-date-range): keyword search with `dateFrom` and `dateTo`, 30 ads.

### Speed and quality

Every release passes a suite of cloud checks before it goes live: exact 1-, 2-, 5-, 31- and 150-ad limits, Page, keyword and URL searches, date ranges, pasted URLs with tracking parameters, empty searches, and budget and runtime stops.

| Measured in November 2026 | Ads | Time |
|---|---:|---:|
| Ten public example tasks | 10-50 each | 4.5-9.5 seconds |
| Page, keyword or URL searches, 12 runs | 31 each | about 11 seconds typically |
| Keyword "dinosaur", United States, 2 runs | 150 | 26 and 51 seconds |

Larger runs in September 2026 delivered all 719 of Burger King's US ads and 1,000 "dinosaur" ads, with no duplicate Library IDs. Independent browser checks matched every one of 281 sampled IDs.

### Input reference

Provide `searchQuery`, `pageId` or `targetUrl`. If several are filled in, `targetUrl` wins, then `pageId`, then `searchQuery`.

| Input | Default | Description |
|---|---|---|
| `searchQuery` | - | Keyword search, up to 500 characters. |
| `pageId` | - | Numeric Facebook Page ID, as a string. |
| `targetUrl` | - | Any Ad Library search URL. Its filters take precedence over the form's country, status, media and date settings. |
| `maxAds` | `100` via API; `1` in a fresh form | Maximum unique ads to deliver, from 1 to 10,000. |
| `country` | `US` | Two-letter country code, such as `US` or `IN`, or `ALL`. |
| `activeStatus` | `active` | `active`, `inactive` or `all`. |
| `mediaType` | `all` | `all`, `image`, `video`, `meme` or `none`. |
| `dateFrom` | - | Start of Meta's date range, `YYYY-MM-DD`. |
| `dateTo` | - | End of the date range, `YYYY-MM-DD`. |

URLs from `facebook.com`, `m.facebook.com` and `web.facebook.com` all work. The URL filters are:

- `country`, `q`, `view_all_page_id`;
- `active_status`, `media_type`, `ad_type`, `search_type`, `is_targeted_country`;
- `content_languages[n]` and `publisher_platforms[n]`;
- `sort_data[mode]` and `sort_data[direction]`;
- `start_date[min]` and `start_date[max]`.

Tracking parameters such as `fbclid` or `utm_source` are removed automatically and listed in the run summary. Older tasks that send `proxyConfiguration` keep working: proxies are built in, so the field is ignored.

### Output fields

Each dataset row is one ad, identified by `libraryID`, and every row has the same fields. Missing copy is an empty string; other missing values are `null`.

- `images` holds objects with a `url`. `videos` holds `url`, `duration` and `poster`, the preview image shown before the video plays.
- `cards` holds every card or version of the ad, each with its own copy, link, call to action and media.
- `format` is `image`, `video`, `carousel`, `dynamic` or `unknown`. `dynamic` covers dynamic creative and catalog (product) ads; their versions are in `cards`, and `multipleVersions` is `true`.
- `endDate` is set when an ad has stopped; running ads have `endDate: null`. `runningTAT` is how many days an active ad has been running.
- On partnership ads, `brand` and `pageId` are the advertiser, and the `collaborator` fields are the creator the ad runs under.

Meta's media links are temporary, so download any images or videos you want to keep soon after the run.

#### Run summary

Each run saves `RUN_SUMMARY` to its key-value store, and its status line says the outcome in one sentence.

| Field | Meaning |
|---|---|
| `delivered` | Unique ads in the dataset. |
| `stopReason` | Why the run stopped: `max_ads` (your limit), `exhausted` (no more results), `budget`, `time_limit`, `interrupted` or `error`. |
| `complete` | `true` when Meta had no more results and every ad was delivered. |
| `metaResultCount` | Meta's approximate number of results for the search. |
| `skipped`, `duplicates`, `ignoredParameters` | Records left out, duplicates removed, and URL parameters ignored. |

### More ad library scrapers

| Actor | Use it for |
|---|---|
| [Meta (Facebook) Ad Library Scraper](https://apify.com/whoareyouanas/meta-ad-scraper) | Our flagship Facebook ad scraper, including single-ad lookups by ID |
| [Facebook Ad Library Video Downloader & Ad Lookup](https://apify.com/whoareyouanas/meta-ad-library-single-ad-lookup) | One ad's video, images and details from its Library ID or link |
| [Facebook Page ID Finder](https://apify.com/whoareyouanas/meta-brand-dropdown-search) | Turn a brand name into a Facebook Page ID |
| [Google Ads Transparency Scraper](https://apify.com/whoareyouanas/google-ads-transparency-scraper) | Competitor ads from Google's Ads Transparency Center |
| [TikTok Ad Library & Creative Scraper](https://apify.com/whoareyouanas/tiktok-ad-scraper) | Competitor ads on TikTok |
| [LinkedIn Ad Library Scraper](https://apify.com/whoareyouanas/linkedin-ad-library-scraper) | Competitor ads on LinkedIn |

### Turn competitor ads into your next creative test with Seercraft

We also build **[Seercraft](https://www.seercraft.io/)** for ongoing Meta ad research. It tracks competitors daily, saves Facebook and Instagram ads to boards, answers questions with links to the source ads, and turns your findings into creative briefs.

### Switching from another Facebook ads scraper

Moving from Curious Coder's Facebook Ad Library Scraper or a similar Actor takes a few minutes. Your Ad Library search URLs work as `targetUrl`.

| Your current setup | In this Actor |
|---|---|
| A list of Ad Library search URLs | One `targetUrl` per run, or one saved task per URL |
| A result limit per source | `maxAds`, an exact limit |
| A Facebook Page URL | The numeric Page ID as `pageId` |
| Country and status options | `country` and `activeStatus` |
| A date range | `dateFrom` and `dateTo`, or `start_date[min]` and `start_date[max]` in the URL |
| A proxy configuration or subscription | Not needed: proxies are built in |
| Scripts that read the output | Map to the field names above, especially `libraryID`, `brand`, `images` and `videos` |

### FAQ

#### Is this the official Facebook Ads Library API?

No. It is an independent, unofficial API for the public Ad Library website, run on Apify and not affiliated with Meta. You call it like any API with your Apify token. You don't need a Meta developer account, identity verification or an access token.

#### Do I need a Meta access token, a Facebook account or a proxy?

No. Public Ad Library data needs no Facebook login, cookies or Meta token, and residential proxies are built in. You only need an Apify account.

#### How do I find winning Facebook ads?

Search a keyword or a competitor's Page, then sort by `runningTAT` or `startDate`. Ads that have been running for weeks are the ones advertisers keep paying for. Check `similarAdCount` and `multipleVersions` to see which ones they are scaling and testing.

#### Can I scrape Instagram ads?

Yes. Every ad lists its placements in `platforms`. To get only Instagram ads, paste an Ad Library URL with `publisher_platforms[0]=instagram`, as in the [Instagram example](#scrape-instagram-ads).

#### Can I download Facebook ad videos and images?

Yes. Each ad includes direct video (MP4) and image URLs, plus video preview images. Set `mediaType` to `video` to get only video ads.

#### Can I track a competitor's new ads every day?

Yes. Save a task with the competitor's Page ID and schedule it. Each run creates a new dataset, so comparing `libraryID`s between runs shows new and stopped ads.

#### Can I use it with n8n, Make, Zapier or Google Sheets?

Yes, through Apify's integrations, webhooks and API. The same input works everywhere.

#### How many ads can I get in one run?

Up to 10,000 per run. For bigger research, run one search per Page or keyword and schedule them.

#### Why did I get fewer ads than `maxAds`?

`maxAds` is an upper limit. When Meta has fewer matching ads, you get all of them, and the run's status line and `RUN_SUMMARY` show the count.

#### Is it legal to scrape the Facebook Ad Library?

Meta publishes the Ad Library so that anyone can see the ads running on its platforms. This Actor collects only that public ad data, without logging in. If you are unsure how your use case is regulated where you work, check with a lawyer.

#### Can I export Facebook ads to CSV or Excel?

Yes. Export the dataset as JSON, CSV or Excel. JSON keeps the nested `cards`, `images` and `videos`; CSV suits flat fields such as brand, copy, Library ID and dates.

### Support

Open an issue in the Actor's **Issues** tab with your run URL and what you expected. Feature requests for new fields or filters are welcome.

# Changelog

This Actor's version history is a separate document: https://apify.com/whoareyouanas/facebook-ads-library-api/changelog.md

# Actor input Schema

## `targetUrl` (type: `string`):

Paste any Meta Ad Library search URL from your browser. It takes precedence over Page ID and keyword, and its filters (country, status, platforms, sort, date range) take precedence over the form. Tracking parameters such as fbclid are removed automatically. To look up one ad by its ID, use our Facebook Ad Library Single Ad Lookup.

## `searchQuery` (type: `string`):

Find ads that mention a keyword, brand or product, for example nike or protein powder. The example searches nike. A URL or Page ID takes precedence when provided.

## `pageId` (type: `string`):

Numeric Facebook Page ID of one advertiser, the number after view_all_page_id= in its Ad Library URL. Takes precedence over the keyword example. A search URL takes precedence over this field.

## `maxAds` (type: `integer`):

Maximum unique ads to deliver in this run, from 1 to 10,000. You pay only for ads delivered, and the run stops exactly at this limit.

## `country` (type: `string`):

Two-letter country code where the ads were shown, such as US, GB, IN or DE, or ALL for every country. Used for keyword and Page ID searches.

## `activeStatus` (type: `string`):

Which ads to return by status. Used for keyword and Page ID searches.

## `mediaType` (type: `string`):

Return only ads with this kind of creative. Used for keyword and Page ID searches.

## `dateFrom` (type: `string`):

First day of the range, YYYY-MM-DD. Leave empty for no start limit.

## `dateTo` (type: `string`):

Last day of the range, YYYY-MM-DD. Leave empty for no end limit.

## Actor input object example

```json
{
  "searchQuery": "nike",
  "maxAds": 1,
  "country": "US",
  "activeStatus": "active",
  "mediaType": "all"
}
```

# Actor output Schema

## `ads` (type: `string`):

No description

## `summary` (type: `string`):

No description

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "searchQuery": "nike",
    "maxAds": 1
};

// Run the Actor and wait for it to finish
const run = await client.actor("whoareyouanas/facebook-ads-library-api").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "searchQuery": "nike",
    "maxAds": 1,
}

# Run the Actor and wait for it to finish
run = client.actor("whoareyouanas/facebook-ads-library-api").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "searchQuery": "nike",
  "maxAds": 1
}' |
apify call whoareyouanas/facebook-ads-library-api --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,whoareyouanas/facebook-ads-library-api"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/qWCMu9IA87yv3nB3e/builds/FFMlvMyys8CNRdhyp/openapi.json
