> Documentation index: https://docs.scrapier.io/llms.txt
> Auth: header `X-API-Key: <key>` · Base: https://api.scrapier.io/api/v2 · Synchronous; paginate with `cursor` ← `data.next_cursor`.

# Facebook Ad Library

Structured Facebook data: send `urls`. Cursor-paginated, 1 credit per successful call.

`GET|POST https://api.scrapier.io/api/v2/facebook-ad-library/` · 1 credit per successful call · Cursor-paginated

## Overview

Call `GET /api/v2/facebook-ad-library/` with `urls`. The results are in `data.ads`; send `data.next_cursor` back as `cursor` to get the next page. 8 optional parameters refine the call (see Parameters).

## Request

```bash
curl -G "https://api.scrapier.io/api/v2/facebook-ad-library/" \
  -H "X-API-Key: YOUR_API_KEY" \
  --data-urlencode "urls=https://www.facebook.com/ZapierApp" \
  --max-time 210
```

```python
import requests

resp = requests.get(
    "https://api.scrapier.io/api/v2/facebook-ad-library/",
    headers={"X-API-Key": "YOUR_API_KEY"},
    params={"urls": "https://www.facebook.com/ZapierApp"},
    timeout=210,
)
body = resp.json()
if not resp.ok:
    raise RuntimeError(body.get("error") or body.get("detail"))

print(body["data"]["ads"])
```

POST with a JSON body works too (same parameters; the body is merged over the query string).

## Parameters

| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| `X-API-Key` (header) | string | yes | — | Your API key. |
| `urls` | string | yes | e.g. `https://www.facebook.com/ZapierApp` | Facebook Ad Library URL (search or page) |
| `cursor` | string | no | — | Pagination cursor returned in the previous response's `next_cursor`. Pass it back unchanged to fetch the next page. When `next_cursor` is null, you have reached the last page. |
| `ad_country` | string | no | `ALL` | Country filter. Locked in cursor. |
| `ad_type` | string | no | `all` | Ad type filter, lowercase (e.g. 'all', 'political_and_issue_ads') -- Facebook's URL route is case-sensitive; 'ALL' uppercase silently narrows results. Locked in cursor. |
| `ad_status` | string | no | `ALL` | Active / Inactive / ALL. Locked in cursor. |
| `scrape_details` | boolean | no | `false` | Fetch full ad details per item (slower). Locked in cursor. |
| `use_proxy` | boolean | no | `true` | Route the request through Scrapier's residential proxy pool. Default: `true`. Leave as is unless support tells you otherwise. |
| `country` | string | no | `ALL` | Default country code (e.g., ALL, US, IN) |
| `period` | string | no | — | Facebook date_preset filter (e.g., ALL, LAST_30_DAYS) — leave empty to use URL default |
| `active_status` | string | no | `all` | Ad activity filter: all, active, or inactive |
| `raw_data` | boolean | no | `false` | When true, the response carries the full raw upstream payload(s) the scraper received (GraphQL / JSON API bodies, HTML, embedded JSON-LD -- exactly as the platform returned them) under `raw_responses`, in place of the formatted items. When false (default) you get the formatted output. Pagination (`cursor` / `next_cursor`) works the same in both modes. |

## Response

HTTP 200. Results are in `data.ads`. Sample from the live catalog, arrays trimmed to 3 items.

```json
{
  "success": true,
  "data": {
    "urls": "https://www.facebook.com/ads/library/?q=covid",
    "page": 1,
    "page_size": 10,
    "ads": [
      {
        "id": "ad-1",
        "ad_archive_id": "1234567890",
        "page_name": "Example",
        "ad_text": "..."
      }
    ],
    "next_cursor": "eyJpIjoidXJsIiwicCI6Mn0"
  }
}
```

## Response fields

| Field | Type | Example | Description |
|---|---|---|---|
| `urls` | string | `https://www.facebook.com/ads/library/?q=covid` |  |
| `page` | integer | `1` |  |
| `page_size` | integer | `10` |  |
| `ads` | array | `[1 item]` | The results. |
| `next_cursor` | string | `eyJpIjoidXJsIiwicCI6Mn0` | Pass back as `cursor` for the next page. `null` on the last page. |
| `ads[].id` | string | `ad-1` |  |
| `ads[].ad_archive_id` | string | `1234567890` |  |
| `ads[].page_name` | string | `Example` |  |
| `ads[].ad_text` | string | `...` |  |

## Pagination

Pass `data.next_cursor` back as `cursor` until it is `null`. Required inputs are ignored once a cursor is sent. Each page is one billed call.

```python
import requests

URL = "https://api.scrapier.io/api/v2/facebook-ad-library/"
HEADERS = {"X-API-Key": "YOUR_API_KEY"}
params = {"urls": "https://www.facebook.com/ZapierApp"}
items = []

for _ in range(10):  # each page is one billed call
    resp = requests.get(URL, headers=HEADERS, params=params, timeout=210)
    resp.raise_for_status()
    data = resp.json()["data"]
    items.extend(data.get("ads") or [])
    if not data.get("next_cursor"):  # None = last page
        break
    params = {"cursor": data["next_cursor"]}
```

## Errors

Failed calls are free. Branch on HTTP status; the message is in `error` (or `detail`). See https://docs.scrapier.io/errors.md

- **400** Bad input. The exact message varies by endpoint. `{"success":false,"error":"…"}`
- **402** Balance below the endpoint's price. `{"error":"Insufficient credits. Buy more to scrape more.","balance":1,"required":2}`
- **403** Invalid or unknown API key. `{"detail":"Authentication service unavailable or invalid API key."}`
- **429** Throttled — wait for Retry-After. `{"detail":"Request was throttled. Expected available in N seconds."}`
- **404** unknown slug · **503** busy (retry after `Retry-After`) · **5xx** upstream failure or timeout (retry with backoff).

## Notes

- Locked into the cursor: `ad_country`, `ad_type`, `ad_status`, `scrape_details`. Set them on the first call; later pages reuse them.

## Related

- [Facebook Ad Library Leads](https://docs.scrapier.io/api-reference/facebook/facebook-ad-library-leads.md): Structured Facebook data: send `urls`. Cursor-paginated, 2 credits per successful call.
- [Facebook Ad Library Ad Transcript](https://docs.scrapier.io/api-reference/facebook/facebook-ad-library-transcript.md): Structured Facebook data: send `urls`. Single lookup, 3 credits per successful call.
- [Facebook Comment Replies](https://docs.scrapier.io/api-reference/facebook/facebook-comment-replies.md): Structured Facebook data: send `feedback_id`. Cursor-paginated, 1 credit per successful call.
- [Facebook Comments](https://docs.scrapier.io/api-reference/facebook/facebook-comments.md): Structured Facebook data: send `urls`. Cursor-paginated, 1 credit per successful call.
