# Meta Ad Library

> **Beta:** the parser for this endpoint has not yet been checked against a live response. Field shapes may change.

`POST /v1/ads/meta`

Ads from the Meta ad library by keyword, page or URL: page, dates, platforms, creative, and spend and impressions where disclosed, as Apify-style dataset items.

Family: Ads API · Mode: Live

## Price

Unit: ad

| Mode | Price (USD) |
|---|---|
| Live | $0.00018 |

Per ad returned.

## Description

POST the input as one JSON object. Each URL and each search term is a source; ads are collected source by source until `resultsLimit` is reached. Only the first page of library results is read for each source.

The response body is a JSON array of items, with no wrapper. Every item carries `receipt_id`, and the same id is in the `X-Receipt-Id` response header.

**Billing.** Per ad returned, whatever fetch level was needed. An input that finds no ads costs $0. Results are cached for 6 h.

**Beta.** The parser behind this route was written from public documentation and hasn't been checked against live pages yet. Item field names are fixed; some values may be null more often than they should be until that check is done.

## Authentication

HTTP Basic auth: any login, with your `dg_` API key as the password. A `Bearer` token header with the key also works.

## Request

Send a JSON object.

| Field | Type | Required | Description |
|---|---|---|---|
| `startUrls` | array<object\|string> | no | Ad library URLs (a keyword search with `q`, `country`, `ad_type` and `active_status`, a page's ads with `view_all_page_id`, or one ad with `id`), or a Facebook page URL, which is searched by the page's name. Each entry is `{"url": ...}` or a plain string. `urls` is accepted too. Send this, `searchTerms`, or both. |
| `startUrls.url` | string | yes | The URL. |
| `urls` | array<object\|string> | no | Same as `startUrls`. |
| `searchTerms` | array<string>\|string | no | Keyword searches, one source each. `searchTerm` and `search_terms` are accepted too. |
| `searchTerm` | string | no | Same as `searchTerms`, for a single keyword. |
| `search_terms` | array<string>\|string | no | Same as `searchTerms`. |
| `country` | string | no | Two-letter country the ads were shown in, or `ALL`. `countryCode` is accepted too. A country in an ad library URL wins for that URL. default `ALL` |
| `countryCode` | string | no | Same as `country`. |
| `adType` | string | no | `ALL`, or `POLITICAL_AND_ISSUE_ADS` for ads about social issues, elections or politics. `ad_type` is accepted too. default `ALL`; one of `ALL`, `POLITICAL_AND_ISSUE_ADS` |
| `activeStatus` | string | no | Which ads: running now, stopped, or both. Unknown values fall back to `all`. default `all`; one of `active`, `inactive`, `all` |
| `resultsLimit` | integer | no | Most ads to return across all sources. `count` and `maxItems` are accepted too. default `100`; min 1; max 5000 |
| `count` | integer | no | Same as `resultsLimit`. |
| `maxItems` | integer | no | Same as `resultsLimit`. |
| `limitPerSource` | integer | no | Most ads from any one URL or search term. min 1; max 5000 |
| `auto_upgrade` | boolean | no | Lets the request move to a higher fetch level when the included level can't get the data, billed at the level that delivered it. `false` stops at the Standard level and returns the failure at $0. Also accepts `"true"`, `"false"`, `1` and `0`. default `true` |
| `max_level` | string | no | The highest fetch level Auto-upgrade may use. `rendered` never uses the Protected level. default `protected`; one of `standard`, `rendered`, `protected` |
| `max_cost` | number | no | The most this task may cost, in USD. The wallet check reserves this amount instead of the worst-case price, the request never upgrades past it, and the charge never exceeds it. Ads stop at the number this amount pays for. min 0 |
| `max_age` | integer | no | Accept a cached result up to this many seconds old, 0 to 86,400. `0` always fetches fresh. Default window: 6 h. min 0; max 86400 |

### Example request

```bash
curl -X POST "https://api.dataforgaio.com/v1/ads/meta" \
  -u "api:$DATAFORGAIO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "searchTerms": [
    "trail running shoes"
  ],
  "country": "US",
  "activeStatus": "active",
  "resultsLimit": 2
}'
```

## Response

| Field | Type | Description |
|---|---|---|
| `inputUrl` | string\|null | The URL or search this ad came from. |
| `adArchiveID` | string | The ad's library id. |
| `adArchiveId` | string | Same as `adArchiveID`, for clients that use this spelling. |
| `adId` | string\|null | The ad id, when shown. |
| `pageID` | string | Id of the page that ran the ad. |
| `pageId` | string | Same as `pageID`. |
| `pageName` | string\|null | Name of the page that ran the ad. |
| `isActive` | boolean | True while the ad is running. |
| `startDate` | integer\|null | When the ad started, Unix seconds. |
| `endDate` | integer\|null | When the ad stopped, Unix seconds. Null while running. |
| `startDateFormatted` | string\|null | `startDate` as ISO 8601. |
| `endDateFormatted` | string\|null | `endDate` as ISO 8601. |
| `publisherPlatform` | array<string> | Where it ran, for example `FACEBOOK`, `INSTAGRAM`. |
| `collationCount` | integer\|null | Number of near-identical ads grouped with this one. |
| `collationId` | string\|null | Id of that group. |
| `categories` | array<string> | Ad categories, for example `POLITICAL`. |
| `currency` | string | Currency of `spend`. Empty when not disclosed. |
| `spend` | object\|string\|null | Amount spent, disclosed for political and issue ads. |
| `impressionsWithIndex` | object | Impressions, disclosed for political and issue ads. |
| `impressionsWithIndex.impressionsText` | string\|null | Impression range as shown. |
| `impressionsWithIndex.impressionsIndex` | integer | Impression bucket, `-1` when not disclosed. |
| `impressionsWithIndex.range` | object\|null | Impression range `{lower_bound, upper_bound}`. Present for ads read from the library's data interface. |
| `reachEstimate` | integer\|object\|null | Estimated reach, when disclosed. |
| `targetedOrReachedCountries` | array<string> | Countries the ad targeted or reached. |
| `snapshot` | object | The ad's creative: page name, body text, title, link, call to action, images, videos and cards. Keys are camelCase; which keys are present depends on where the ad was read. |
| `url` | string\|null | Link to the ad in the ad library. |
| `receipt_id` | string\|null | Id of the ledger receipt for this request. Same on every item. |

### Item types

#### ad

| Field | Type | Description |
|---|---|---|
| `inputUrl` | string\|null | The URL or search this ad came from. |
| `adArchiveID` | string | The ad's library id. |
| `adArchiveId` | string | Same as `adArchiveID`, for clients that use this spelling. |
| `adId` | string\|null | The ad id, when shown. |
| `pageID` | string | Id of the page that ran the ad. |
| `pageId` | string | Same as `pageID`. |
| `pageName` | string\|null | Name of the page that ran the ad. |
| `isActive` | boolean | True while the ad is running. |
| `startDate` | integer\|null | When the ad started, Unix seconds. |
| `endDate` | integer\|null | When the ad stopped, Unix seconds. Null while running. |
| `startDateFormatted` | string\|null | `startDate` as ISO 8601. |
| `endDateFormatted` | string\|null | `endDate` as ISO 8601. |
| `publisherPlatform` | array<string> | Where it ran, for example `FACEBOOK`, `INSTAGRAM`. |
| `collationCount` | integer\|null | Number of near-identical ads grouped with this one. |
| `collationId` | string\|null | Id of that group. |
| `categories` | array<string> | Ad categories, for example `POLITICAL`. |
| `currency` | string | Currency of `spend`. Empty when not disclosed. |
| `spend` | object\|string\|null | Amount spent, disclosed for political and issue ads. |
| `impressionsWithIndex` | object | Impressions, disclosed for political and issue ads. |
| `impressionsWithIndex.impressionsText` | string\|null | Impression range as shown. |
| `impressionsWithIndex.impressionsIndex` | integer | Impression bucket, `-1` when not disclosed. |
| `impressionsWithIndex.range` | object\|null | Impression range `{lower_bound, upper_bound}`. Present for ads read from the library's data interface. |
| `reachEstimate` | integer\|object\|null | Estimated reach, when disclosed. |
| `targetedOrReachedCountries` | array<string> | Countries the ad targeted or reached. |
| `snapshot` | object | The ad's creative: page name, body text, title, link, call to action, images, videos and cards. Keys are camelCase; which keys are present depends on where the ad was read. |
| `url` | string\|null | Link to the ad in the ad library. |
| `receipt_id` | string\|null | Id of the ledger receipt for this request. Same on every item. |

### Example response

```json
[
  {
    "inputUrl": "https://www.facebook.com/ads/library/?active_status=active&ad_type=all&country=US&media_type=all&q=trail+running+shoes&search_type=keyword_unordered",
    "adArchiveID": "1229350099285014",
    "adArchiveId": "1229350099285014",
    "adId": null,
    "pageID": "100200300400",
    "pageId": "100200300400",
    "pageName": "Summit Running Co.",
    "isActive": true,
    "startDate": 1764547200,
    "endDate": null,
    "startDateFormatted": "2025-12-01T00:00:00.000Z",
    "endDateFormatted": null,
    "publisherPlatform": [
      "FACEBOOK",
      "INSTAGRAM"
    ],
    "collationCount": 2,
    "collationId": "889900112233",
    "categories": [
      "UNKNOWN"
    ],
    "currency": "",
    "spend": null,
    "impressionsWithIndex": {
      "impressionsText": null,
      "impressionsIndex": -1
    },
    "reachEstimate": null,
    "targetedOrReachedCountries": [],
    "snapshot": {
      "pageName": "Summit Running Co.",
      "body": {
        "text": "New trail shoes for winter. Free gait analysis."
      },
      "title": "Shop trail shoes",
      "linkUrl": "https://summitrunning.example/trail-shoes",
      "ctaText": "Shop now",
      "ctaType": "SHOP_NOW",
      "displayFormat": "IMAGE",
      "images": [
        {
          "originalImageUrl": "https://images.example/ad-1.jpg"
        }
      ],
      "videos": [],
      "cards": []
    },
    "url": "https://www.facebook.com/ads/library/?id=1229350099285014",
    "receipt_id": "8cbb5b5c-8e15-5c82-9959-45f93cdad009"
  },
  {
    "inputUrl": "https://www.facebook.com/ads/library/?active_status=active&ad_type=all&country=US&media_type=all&q=trail+running+shoes&search_type=keyword_unordered",
    "adArchiveID": "1229350099285015",
    "adArchiveId": "1229350099285015",
    "adId": null,
    "pageID": "100200300400",
    "pageId": "100200300400",
    "pageName": "Summit Running Co.",
    "isActive": true,
    "startDate": 1764547200,
    "endDate": null,
    "startDateFormatted": "2025-12-01T00:00:00.000Z",
    "endDateFormatted": null,
    "publisherPlatform": [
      "FACEBOOK",
      "INSTAGRAM"
    ],
    "collationCount": 1,
    "collationId": "889900112234",
    "categories": [
      "UNKNOWN"
    ],
    "currency": "",
    "spend": null,
    "impressionsWithIndex": {
      "impressionsText": null,
      "impressionsIndex": -1
    },
    "reachEstimate": null,
    "targetedOrReachedCountries": [],
    "snapshot": {
      "pageName": "Summit Running Co.",
      "body": {
        "text": "New trail shoes for winter. Free gait analysis."
      },
      "title": "Shop trail shoes",
      "linkUrl": "https://summitrunning.example/trail-shoes",
      "ctaText": "Shop now",
      "ctaType": "SHOP_NOW",
      "displayFormat": "IMAGE",
      "images": [
        {
          "originalImageUrl": "https://images.example/ad-1.jpg"
        }
      ],
      "videos": [],
      "cards": []
    },
    "url": "https://www.facebook.com/ads/library/?id=1229350099285015",
    "receipt_id": "8cbb5b5c-8e15-5c82-9959-45f93cdad009"
  }
]
```

## Errors

| Code | When |
|---|---|
| 400 | Invalid input (no URL or search term, a non-Facebook URL, or an unknown `adType`), or `max_cost` below the price of one item. Body: `{"error": {"type": "invalid-input", "message": ..., "receipt_id": null}}`. |
| 400 | Nothing found for the input (`type: invalid-input`). $0. |
| 401 | No valid API key (`type: user-or-token-not-found`). |
| 402 | Wallet balance below the worst case for this request (`type: not-enough-usage-to-run-paid-actor`). |
| 429 | Too many requests (`type: rate-limit-exceeded`). |
| 500 | No allowed fetch level got the page (`type: internal-error`). $0. |

## Migrating

Replaces Apify `Facebook Ads Library actor input and dataset items`. Same request body and response envelope; change the base URL and the key.
