# Facebook Ad Library Search (POST) API

Search Facebook Ad Library with a JSON body to submit keywords and advertising filters together.

`POST https://socialmediascraper.org/v1/facebook/adlibrary_search_ads_post`

$0.002444 USD per request

## Authentication

Send your customer API key in x-api-key. Generate a new Idempotency-Key for each logical request and preserve it with identical input for retries.

## Request parameters

JSON request body

### query

string · Required

Search text used to find matching public content.



### sort_by

string · Optional

Ordering of returned results. Choose one of the allowed sort modes below.

Allowed values: "total_impressions", "relevancy_monthly_grouped"

### search_type

string · Optional

Result category or content format to include. Use an allowed value below.

Allowed values: "keyword_unordered", "keyword_exact_phrase"

### ad_type

string · Optional

Result category or content format to include. Use an allowed value below.

Allowed values: "all", "political_and_issue_ads"

### country

string · Optional

Country or region filter for the selected operation. Use the codes accepted below.



### language

string · Optional

Language code for the transcript or language-specific result.



### status

string · Optional

Status filter for the matching records.

Allowed values: "ALL", "ACTIVE", "INACTIVE"

### media_type

string · Optional

Result category or content format to include. Use an allowed value below.

Allowed values: "ALL", "IMAGE", "VIDEO", "MEME", "IMAGE_AND_MEME", "NONE"

### start_date

string · Optional

Beginning of the time range used to filter results.



### end_date

string · Optional

End of the time range used to filter results.



### trim

boolean · Optional

Request the supplier’s trimmed response representation.



### cursor

string · Optional

Continuation value from the preceding response. Keep the other search or target parameters unchanged when loading the next page.



## Request example

JavaScript examples use Node.js with built-in fetch; Python examples use the standard library. Configure SOCIALSCRAPER_API_KEY in the execution environment.

### cURL

```sh
curl --request POST 'https://socialmediascraper.org/v1/facebook/adlibrary_search_ads_post' \
  --header 'x-api-key: YOUR_API_KEY' \
  --header 'Idempotency-Key: example-request-0001' \
  --header 'x-price-version: 2026-11-23.retail-1' \
  --header 'Content-Type: application/json' \
  --data '{
  "query": "technology"
}'
```

### JavaScript

```javascript
const requestKey = crypto.randomUUID();
const response = await fetch("https://socialmediascraper.org/v1/facebook/adlibrary_search_ads_post", {
  method: "POST",
  headers: {
    "x-api-key": process.env.SOCIALSCRAPER_API_KEY,
    "Idempotency-Key": requestKey,
    "x-price-version": "2026-11-23.retail-1",
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
  "query": "technology"
})
});
const result = await response.json();
if (!response.ok) throw new Error(JSON.stringify(result));
console.log(result);
```

### Python

```python
import json, os, uuid
from urllib.request import Request, urlopen

request_key = str(uuid.uuid4())
request = Request(
    "https://socialmediascraper.org/v1/facebook/adlibrary_search_ads_post",
    method="POST",
    data=json.dumps(json.loads("{\n  \"query\": \"technology\"\n}")).encode(),
    headers={
        "x-api-key": os.environ["SOCIALSCRAPER_API_KEY"],
        "Idempotency-Key": request_key,
        "x-price-version": "2026-11-23.retail-1",
        "Content-Type": "application/json",
    },
)
with urlopen(request, timeout=60) as response:
    print(json.load(response))
```

## Response and fields

The response uses request_id, data and meta. The table below describes the returned data object; keep null values when a source field has no value.

```json
{
  "request_id": "example-request-id",
  "data": {
    "platform": "facebook",
    "resource": "adlibrary_search_ads_post",
    "items": [
      {
        "id": "123456789",
        "position": 0,
        "url": "https://example.com/public-content",
        "title": "Example public content",
        "text": "Example public content",
        "published_at": null,
        "author": {
          "id": "123456789",
          "handle": "example",
          "display_name": "Example creator"
        },
        "metrics": {
          "views": null,
          "likes": 12,
          "comments": null,
          "shares": null
        }
      }
    ],
    "cursor": null
  },
  "meta": {
    "platform": "facebook",
    "fetched_at": "2026-11-28T00:00:00.000Z",
    "cached": false,
    "schema_version": "2026-11-23.2",
    "route_version": 1,
    "billing": {
      "capability": "facebook.adlibrary_search_ads_post",
      "version": "2026-11-23.retail-1",
      "currency": "USD",
      "unit_scale": 1000000000,
      "amount_units": 2444000,
      "amount_usd": "0.002444000",
      "billing_basis": "request"
    }
  }
}
```

- `data.platform` (string): Source platform identifier.

- `data.resource` (string): Operation resource identifier.

- `data.items` (array): Records in the returned page or bounded result set.

- `data.items[].id` (string): Source identity preserved as text.

- `data.items[].position` (number): Zero-based position within this returned set.

- `data.items[].url` (string): Public source URL for this record.

- `data.items[].title` (string): Title or display label associated with the record.

- `data.items[].text` (string): Content text, biography or transcript text associated with this record.

- `data.items[].published_at` (null): Publication value supplied by the source.

- `data.items[].author` (object): Identity fields for the author or account represented by the record.

- `data.items[].author.id` (string): Source identity preserved as text.

- `data.items[].author.handle` (string): Public account username or handle.

- `data.items[].author.display_name` (string): Account or creator display name.

- `data.items[].metrics` (object): Available source metrics grouped by measurement.

- `data.items[].metrics.views` (null): Source-reported views measurement when present.

- `data.items[].metrics.likes` (number): Source-reported likes measurement when present.

- `data.items[].metrics.comments` (null): Source-reported comments measurement when present.

- `data.items[].metrics.shares` (null): Source-reported shares measurement when present.

- `data.cursor` (null): Continuation value for the next request; preserve its returned representation.

## Pagination

Continue with the returned data.cursor and the documented input field: cursor. Keep the original target and filters. Each additional page is a new request with a new Idempotency-Key.

## Errors and recovery

Read the error code and request_id before deciding how to recover. Retain your original input and request identity when retrying the same operation.

400: Review parameter types and identifier-combination rules.

401: Check x-api-key and the key in your workspace.

402: Check the quoted request price and your available USD balance.

429: Wait for Retry-After before retrying with the original request identity.

If a request outcome is uncertain, read GET /v1/requests/:id using the returned request_id before starting a replacement.

## Build a workflow

Choose POST when your automation tool supplies a JSON body containing the search or advertiser filters. The corresponding GET page documents the query-parameter form of the operation.

Price version: 2026-11-23.retail-1. Each additional page is billed as a request. Inspect meta.billing for the amount applied to your request.

[OpenAPI](https://socialmediascraper.org/api-reference/facebook.adlibrary_search_ads_post.openapi.json)

[API playground](https://socialmediascraper.org/playground/?capability=facebook.adlibrary_search_ads_post)
