# Facebook Post Search (`facebook.search_posts`)

Keyword search over public Facebook posts, optionally by date range and place, with post text, author and engagement counts.

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

- Endpoint: `POST https://api.primaryapi.com/v1/run/facebook.search_posts`
- Category: Social · Platform: `facebook` · Kind: search · Status: live
- Price: 3.24 credits per result, at least 4 credits a call; up to 6.25 credits per result if a call is retried elsewhere. A quote’s `maxCredits` is the most a given call can cost.
- Billing unit: per result returned, rounded up to whole credits per call (a call that returns nothing costs nothing)
- 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.search_posts`
- 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 public Facebook posts for (e.g. "product launch"). |
| `limit` | integer | no | 10 | 1–20 | Maximum number of posts to return (1-20, default 10). Billed per post returned. |
| `location` | string | no |  | max 100 chars | Optional place filter: a place name (e.g. "Paris, France") or a numeric Facebook location id. Sources that cannot apply the given form are skipped. |
| `startDate` | string | no |  |  | Only posts published on or after this date, YYYY-MM-DD (e.g. 2026-10-01). |
| `endDate` | string | no |  |  | Only posts published on or before this date, YYYY-MM-DD (e.g. 2026-10-30). |

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 |
|---|---|---|
| `items` | object[] |  |
| `items[].id` | string | Facebook post id |
| `items[].text` | string \| null |  |
| `items[].url` | string \| null |  |
| `items[].createdUtc` | integer \| null | Publish time, Unix seconds |
| `items[].authorName` | string \| null |  |
| `items[].authorUrl` | string \| null |  |
| `items[].authorId` | string \| null | Numeric id of the page or profile that posted |
| `items[].authorImage` | string \| null |  |
| `items[].reactionCount` | integer \| null |  |
| `items[].commentCount` | integer \| null |  |
| `items[].shareCount` | integer \| null |  |
| `items[].image` | string \| null | First image URL |
| `items[].type` | string \| null | Kind of post the source reported (photo, video, status, link, …) |
| `items[].reactions` | object \| null | Reaction counts by type, when available |
| `items[].imagesCount` | integer \| null |  |
| `items[].albumPreview` | object[] \| null | Attached media previews, when available |
| `items[].albumPreview[].id` | string \| null |  |
| `items[].albumPreview[].image` | string \| null |  |
| `items[].albumPreview[].type` | string \| null |  |
| `items[].albumPreview[].url` | string \| null |  |
| `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.

## Example request

```bash
curl -sS -X POST "https://api.primaryapi.com/v1/run/facebook.search_posts" \
  -H "Authorization: Bearer $PRIMARYAPI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"query":"product launch","limit":5}'
```

## 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": {
      "items": [
        {
          "id": "string",
          "text": "string",
          "url": "https://example.com",
          "createdUtc": 0,
          "authorName": "string",
          "authorUrl": "https://example.com",
          "authorId": "string",
          "authorImage": "string",
          "reactionCount": 0,
          "commentCount": 0,
          "shareCount": 0,
          "image": "string",
          "type": "string",
          "reactions": {},
          "imagesCount": 0,
          "albumPreview": [
            {
              "id": "string",
              "image": "string",
              "type": "string",
              "url": "https://example.com"
            }
          ]
        }
      ],
      "nextCursor": null
    }
  },
  "provider": "PrimaryAPI",
  "credits": 4,
  "items": 1,
  "requestId": "req_01JBXK6Y2N9V8T4R3Q2P1M0A7Z",
  "nextCursor": null
}
```

## Pricing and reliability

- Usual price: 3.24 credits per result, at least 4 credits a call
- Price ceiling: up to 6.25 credits per result 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.search_posts`

## 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.

