# Facebook Ad Library Search (`facebook.ads_search`)

Search the Meta Ad Library by keyword with country, status, media, date and sort filters; returns matching ads with cursor pagination.

Docs: https://primaryapi.com/docs/api-reference/facebook/ads_search

- Endpoint: `POST https://api.primaryapi.com/v1/run/facebook.ads_search`
- Category: Web Intelligence · Platform: `facebook` · Kind: search · Status: live
- Price: 1 credit per call; up to 4 credits if a call is retried elsewhere. A quote’s `maxCredits` is the most a given call can cost.
- Billing unit: per successful call
- Reliability: routed to a healthy upstream and retried automatically when an attempt fails; live 30-day status: `GET https://api.primaryapi.com/v1/status/apis?sku=facebook.ads_search`
- Execution: synchronous (answers 202 only if it outlives the wait window)

## Input

| Field | Type | Required | Default | Constraints | Description |
|---|---|---|---|---|---|
| `query` | string | yes |  | max 500 chars | Keyword or phrase to search the Meta Ad Library for (e.g. "protein powder"). |
| `searchType` | enum | no |  | one of: keyword_unordered, keyword_exact_phrase | Match mode: keyword_unordered (default, words in any order) or keyword_exact_phrase. |
| `adType` | enum | no |  | one of: all, political_and_issue_ads | All ads (default) or only political and issue ads. |
| `country` | string | no |  | pattern: ^(?:[A-Za-z]{2}\|ALL\|all)$ | Two-letter ISO country code the ads were delivered in (for example "US"), or ALL. Omit for all countries. |
| `status` | enum | no | "ACTIVE" | one of: ALL, ACTIVE, INACTIVE | Delivery status filter (default ACTIVE). |
| `mediaType` | enum | no |  | one of: ALL, IMAGE, VIDEO, MEME, IMAGE_AND_MEME, NONE | Creative media filter (default ALL; MEME = image with text). |
| `sortBy` | enum | no |  | one of: impressions, recent | impressions (highest first, the default) or recent. |
| `startDate` | string | no |  | pattern: ^\d{4}-\d{2}-\d{2}$ | Only ads with impressions on or after this date (YYYY-MM-DD). |
| `endDate` | string | no |  | pattern: ^\d{4}-\d{2}-\d{2}$ | Only ads with impressions on or before this date (YYYY-MM-DD). |
| `limit` | integer | no | 30 | 1–100 | Maximum number of results to return (1-100, default 30). |
| `cursor` | string | no |  |  | Opaque pagination cursor: pass the previous response's nextCursor. |

Unknown fields are rejected with `400 invalid_input`. The routing controls `preferLatencyUnderMs` and `maxCredits` may be sent in the same JSON body.

## Output

When `output.found` is `true`, `output.data` has this shape:

| Field | Type | Description |
|---|---|---|
| `ads` | object[] |  |
| `ads[].id` | string | Ad Library archive id (ad_archive_id) |
| `ads[].adArchiveId` | string | Same value as id (AnyAPI field name) |
| `ads[].active` | boolean \| null | Ad was delivering when scraped |
| `ads[].pageId` | string \| null | Advertiser page id |
| `ads[].pageName` | string \| null |  |
| `ads[].pageUrl` | string \| null |  |
| `ads[].pageProfilePicture` | string \| null |  |
| `ads[].pageLikes` | integer \| null |  |
| `ads[].pageCategories` | string[] |  |
| `ads[].pageDeleted` | boolean \| null |  |
| `ads[].text` | string \| null | Primary ad copy |
| `ads[].body` | string \| null | Same value as text (AnyAPI field name) |
| `ads[].title` | string \| null | Headline |
| `ads[].caption` | string \| null | Display domain / link caption |
| `ads[].linkDescription` | string \| null |  |
| `ads[].linkUrl` | string \| null | Landing page URL |
| `ads[].ctaText` | string \| null |  |
| `ads[].ctaType` | string \| null |  |
| `ads[].displayFormat` | string \| null | IMAGE, VIDEO, CAROUSEL, DCO, … |
| `ads[].type` | enum \| null | video when the creative has a video, else image when it has one |
| `ads[].image` | string \| null | First image (or video preview image) URL |
| `ads[].videoUrl` | string \| null | First video URL |
| `ads[].creatives` | object[] \| null | Per-card / per-version creative of multi-version ads ([] for single-creative ads, null when unknown) |
| `ads[].creatives[].body` | string \| null |  |
| `ads[].creatives[].title` | string \| null |  |
| `ads[].creatives[].caption` | string \| null |  |
| `ads[].creatives[].linkDescription` | string \| null |  |
| `ads[].creatives[].linkUrl` | string \| null |  |
| `ads[].creatives[].ctaText` | string \| null |  |
| `ads[].creatives[].ctaType` | string \| null |  |
| `ads[].creatives[].image` | string \| null | Full-size image URL (expiring CDN link) |
| `ads[].creatives[].imageResized` | string \| null |  |
| `ads[].creatives[].videoUrl` | string \| null | HD video URL when available, else SD |
| `ads[].creatives[].videoPreviewImage` | string \| null |  |
| `ads[].media` | object[] |  |
| `ads[].media[].type` | enum |  |
| `ads[].media[].url` | string \| null | Image URL, or the preview image of a video |
| `ads[].media[].videoUrl` | string \| null |  |
| `ads[].startDate` | integer \| null | Delivery start, Unix seconds |
| `ads[].endDate` | integer \| null | Delivery end, Unix seconds; null while the ad is running |
| `ads[].platforms` | string[] | FACEBOOK, INSTAGRAM, MESSENGER, AUDIENCE_NETWORK, THREADS |
| `ads[].isReshared` | boolean \| null |  |
| `ads[].adCount` | integer \| null | Ads sharing this creative (collation_count) |
| `ads[].currency` | string \| null | Only disclosed for political / social-issue ads |
| `ads[].categories` | string[] \| null | Special ad categories, when the source exposes them |
| `ads[].sourceUrl` | string | Ad Library permalink |
| `ads[].url` | string | Same value as sourceUrl (AnyAPI field name) |
| `totalResults` | integer \| null | Total matches reported by the source (may be capped, e.g. 50001); null when unknown |
| `nextCursor` | string \| null |  |

When the thing you asked about does not exist (or a search matches nothing) the call still succeeds: `output.found` is `false`, `output.data` is `null` and `output.reason` says why (`not_found`, `private`, `no_results`, …). Misses are free unless the notes below say misses are billed.

Pagination: pass the previous response’s `nextCursor` as `cursor` to get the next page; `nextCursor: null` means there are no more results.

## Example request

```bash
curl -sS -X POST "https://api.primaryapi.com/v1/run/facebook.ads_search" \
  -H "Authorization: Bearer $PRIMARYAPI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"query":"running shoes","country":"DE","limit":10}'
```

## Example response

_Values are placeholders that follow the output schema; `credits` is what this call would cost at the usual price._

```json
{
  "output": {
    "found": true,
    "data": {
      "ads": [
        {
          "id": "string",
          "adArchiveId": "string",
          "active": true,
          "pageId": "string",
          "pageName": "string",
          "pageUrl": "https://example.com",
          "pageProfilePicture": "string",
          "pageLikes": 0,
          "pageCategories": [
            "string"
          ],
          "pageDeleted": true,
          "text": "string",
          "body": "string",
          "title": "string",
          "caption": "string",
          "linkDescription": "string",
          "linkUrl": "https://example.com",
          "ctaText": "string",
          "ctaType": "string",
          "displayFormat": "string",
          "type": "image",
          "image": "string",
          "videoUrl": "https://example.com",
          "creatives": [
            {
              "body": "string",
              "title": "string",
              "caption": "string",
              "linkDescription": "string",
              "linkUrl": "https://example.com",
              "ctaText": "string",
              "ctaType": "string",
              "image": "string",
              "imageResized": "string",
              "videoUrl": "https://example.com",
              "videoPreviewImage": "string"
            }
          ],
          "media": [
            {
              "type": "image",
              "url": "https://example.com",
              "videoUrl": "https://example.com"
            }
          ],
          "startDate": 0,
          "endDate": 0,
          "platforms": [
            "string"
          ],
          "isReshared": true,
          "adCount": 0,
          "currency": "string",
          "categories": [
            "string"
          ],
          "sourceUrl": "https://example.com",
          "url": "https://example.com"
        }
      ],
      "totalResults": 0,
      "nextCursor": null
    }
  },
  "provider": "PrimaryAPI",
  "credits": 1,
  "items": 1,
  "requestId": "req_01JBXK6Y2N9V8T4R3Q2P1M0A7Z",
  "nextCursor": null
}
```

## Pricing and reliability

- Usual price: 1 credit per call
- Price ceiling: up to 4 credits if a call is retried elsewhere. A quote’s `maxCredits` is the most a given call can cost; the `maxCredits` routing control caps it per call
- Live 30-day status, success rate, uptime and latency: `GET https://api.primaryapi.com/v1/status/apis?sku=facebook.ads_search`

## Errors to handle

`invalid_input`, `unauthorized`, `insufficient_balance`, `key_limit_reached`, `trial_cap_reached`, `forbidden`, `not_found`, `idempotency_conflict`, `rate_limited`, `all_sources_failed`, `service_unavailable`, `timeout`. See https://primaryapi.com/docs/errors.

