# Upscrape Facebook LLM Integration Prompt

Give this to an LLM or coding agent. It must fetch the OpenAPI spec first and use this brief only for orientation.

## First Step

Fetch and read this OpenAPI spec before writing code:

https://data.upscrape.com/catalog/platforms/facebook/openapi.json?token=SFMyNTY.g2gDdAAAAAFtAAAAC3BsYXRmb3JtX2lkbQAAAAhmYWNlYm9va24GAGq5C0qfAWIAAVGA.zsvRdplyJMcyV7sznW3_PYVIfhcmo6WVP8-vJLJIaOA
This signed OpenAPI URL is valid for approximately 7 days.

## Hard Rules

- Use the OpenAPI spec as the source of truth for endpoints, request bodies, response bodies, errors, and JSON schemas.
- Do not infer fields from capability descriptions; fetch the spec and use its component schemas.
- Authenticate every request with `Authorization: Bearer YOUR_API_KEY`.
- Start runs with `POST /execute`; do not invent platform-specific execute endpoints.
- Poll `GET /jobs/{id}` or `GET /jobs/{id}/result` until `state` is `completed` or `failed`.
- Optionally send `Prefer: wait=N` on `POST /execute` to wait up to N seconds for inline results.
- If the response is `200`, the job completed — read `results[0].data`. If `202`, poll `GET /jobs/{id}`.
- `stream` is public-facing but must remain `false` today.

## API Base

- Base URL: `https://data.upscrape.com`
- OpenAPI spec: `https://data.upscrape.com/catalog/platforms/facebook/openapi.json?token=SFMyNTY.g2gDdAAAAAFtAAAAC3BsYXRmb3JtX2lkbQAAAAhmYWNlYm9va24GAGq5C0qfAWIAAVGA.zsvRdplyJMcyV7sznW3_PYVIfhcmo6WVP8-vJLJIaOA`
- Execute endpoint: `POST /execute`
- Job poll endpoint: `GET /jobs/{id}`
- Result alias: `GET /jobs/{id}/result`
- Content-Type: `application/json`
- Optional header: `Idempotency-Key`
- Optional header: `Prefer: wait=N` (hold connection up to N seconds for synchronous result)

## Execution Flow

1. Send `POST /execute` with a platform capability ID and its `input` object.
2. The API responds with a queued `job_id`.
3. Poll the job endpoint until `state` becomes `completed` or `failed`.
4. If completed, read `results[0].data`; its exact shape is defined by the OpenAPI component schema for the selected capability.

## Example Execute Request

```json
{
  "capability": "facebook.ads-library.search",
  "input": {
    "query": "Meta AI"
  }
}
```

## Optional Request Fields

- `network.session_id`: explicit reusable session identifier
- `network.session_key`: stable key used to derive a reusable session
- `network.sticky`: reuse the resolved session when `true`
- `timeout_ms`: per-capability timeout override up to the capability maximum listed below
- `stream`: must be `false`

## Supported Capabilities

- `facebook.ads-library.search` - Search Ads Library. Searches the Facebook Ads Library for active and inactive ads by advertiser or keyword. Max `timeout_ms`: 120000. Streaming: supported.
- `facebook.page-posts.list` - List Page Posts. Lists recent posts from a Facebook page including text, media, and engagement metrics. Max `timeout_ms`: 120000. Streaming: supported.
- `facebook.page-reels.list` - List Page Reels. Lists reels from a Facebook page with view counts and video metadata. Max `timeout_ms`: 60000. Streaming: supported.
- `facebook.page-videos.list` - List Page Videos. Lists videos posted by a Facebook page with titles, view counts, and engagement metrics. Max `timeout_ms`: 120000. Streaming: supported.
- `facebook.page.get` - Get Page. Fetches a Facebook page's public profile including name, category, follower count, and page metadata. Max `timeout_ms`: 30000. Streaming: disabled.
- `facebook.photo.get` - Get Photo. Fetches details about a public Facebook photo including image URL and engagement metadata. Max `timeout_ms`: 30000. Streaming: disabled.
- `facebook.post-comments.list` - List Post Comments. Lists comments on a Facebook post including comment text, author, and reaction counts. Max `timeout_ms`: 120000. Streaming: supported.
- `facebook.post.get` - Get Post. Fetches a Facebook post's details including text, reactions, shares, and comment count. Max `timeout_ms`: 30000. Streaming: disabled.
- `facebook.reel.get` - Get Reel. Fetches details about a public Facebook Reel including video URL, view count, and engagement. Max `timeout_ms`: 30000. Streaming: disabled.
- `facebook.video.get` - Get Video. Fetches details about a public Facebook video including title, view count, and engagement metrics. Max `timeout_ms`: 30000. Streaming: disabled.