Facebook Company Ads
The ads one advertiser runs in the Meta Ad Library, by Ad Library page id or company name, with filters and cursor pagination.
- Price per call
- 2 credits
- per successful call
- Price ceiling
- 4 credits
- if a call is retried elsewhere
- Failed calls
- Free
- retried automatically
- Billed
- Per call
- only on success
Endpoint
api.primaryapi.com/ v1/ run/ facebook. company_adsAuth: API key with run or full access, or a dashboard session
Send the input below as a JSON body. The call is routed to a healthy upstream; if an attempt fails, it is retried automatically inside the same request and you pay only for the answer you get. To check an input and see the exact price without running anything, call POST /v1/quote/facebook.company_ads with the same body (free).
Example request
curl -sS -X POST "https://api.primaryapi.com/v1/run/facebook.company_ads" \
-H "Authorization: Bearer $PRIMARYAPI_API_KEY" \
-H "Content-Type: application/json" \
-d '{"pageId":"15087023444","country":"US","limit":10}'const res = await fetch('https://api.primaryapi.com/v1/run/facebook.company_ads', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.PRIMARYAPI_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
pageId: '15087023444',
country: 'US',
limit: 10,
}),
});
const body = await res.json();
if (!res.ok) throw new Error(`${body.code}: ${body.error}`);
// found:false is a successful answer ("does not exist"), not an error
console.log(body.output.found ? body.output.data : body.output.reason, body.credits);import os
import requests
res = requests.post(
"https://api.primaryapi.com/v1/run/facebook.company_ads",
headers={"Authorization": f"Bearer {os.environ['PRIMARYAPI_API_KEY']}"},
json={
"pageId": "15087023444",
"country": "US",
"limit": 10,
},
timeout=60,
)
body = res.json()
if not res.ok:
raise RuntimeError(f"{body['code']}: {body['error']}")
# found=False is a successful answer ("does not exist"), not an error
print(body["output"]["data"] if body["output"]["found"] else body["output"]["reason"], body["credits"]){
"name": "run_api",
"arguments": {
"sku": "facebook.company_ads",
"input": {
"pageId": "15087023444",
"country": "US",
"limit": 10
}
}
}Price this exact input first (free)
curl -sS -X POST "https://api.primaryapi.com/v1/quote/facebook.company_ads" \
-H "Authorization: Bearer $PRIMARYAPI_API_KEY" \
-H "Content-Type: application/json" \
-d '{"pageId":"15087023444","country":"US","limit":10}'Returns credits (what the call is expected to cost) and maxCredits (the most it can cost, which is set aside while it runs). Invalid input fails here the same way it would on run.
Input
JSON body fields. Unknown fields are rejected with 400 invalid_input (never silently ignored). You may add the routing controls preferLatencyUnderMs and maxCredits to the same object.
pageIdstring- Advertiser Ad Library page id (view_all_page_id in an Ad Library URL, e.g. "15087023444"). Provide pageId or companyName.pattern: ^\d{3,25}$
companyNamestring- Advertiser name as the Ad Library shows it (e.g. "Nike"); matched exactly and case-sensitively by the primary source.max 200 chars
countrystring- Two-letter ISO country code the ads were delivered in (for example "US"), or ALL. Omit for all countries.pattern: ^(?:[A-Za-z]{2}|ALL|all)$
statusenumdefault"ACTIVE"- Delivery status filter (default ACTIVE).one of: ALL, ACTIVE, INACTIVE
mediaTypeenum- Creative media filter (default ALL; MEME = image with text).one of: ALL, IMAGE, VIDEO, MEME, IMAGE_AND_MEME, NONE
languagestring- Two-letter language code of the ads (e.g. "EN", "ES").pattern: ^[A-Za-z]{2}$
sortByenum- impressions (highest first, the default) or recent.one of: impressions, recent
startDatestring- Only ads with impressions on or after this date (YYYY-MM-DD).pattern: ^\d{4}-\d{2}-\d{2}$
endDatestring- Only ads with impressions on or before this date (YYYY-MM-DD).pattern: ^\d{4}-\d{2}-\d{2}$
limitintegerdefault30- Maximum number of results to return (1-100, default 30).1–100
cursorstring- Opaque pagination cursor: pass the previous response's nextCursor.
Output
When output.found is true, output.data has these fields (a list under ads, billed per item returned).
adsobject[]ads[].idstring- Ad Library archive id (ad_archive_id)
ads[].adArchiveIdstring- Same value as id (AnyAPI field name)
ads[].activeboolean | null- Ad was delivering when scraped
ads[].pageIdstring | null- Advertiser page id
ads[].pageNamestring | nullads[].pageUrlstring | nullads[].pageProfilePicturestring | nullads[].pageLikesinteger | nullads[].pageCategoriesstring[]ads[].pageDeletedboolean | nullads[].textstring | null- Primary ad copy
ads[].bodystring | null- Same value as text (AnyAPI field name)
ads[].titlestring | null- Headline
ads[].captionstring | null- Display domain / link caption
ads[].linkDescriptionstring | nullads[].linkUrlstring | null- Landing page URL
ads[].ctaTextstring | nullads[].ctaTypestring | nullads[].displayFormatstring | null- IMAGE, VIDEO, CAROUSEL, DCO, …
ads[].typeenum | null- video when the creative has a video, else image when it has oneone of: image, video
ads[].imagestring | null- First image (or video preview image) URL
ads[].videoUrlstring | null- First video URL
ads[].creativesobject[] | null- Per-card / per-version creative of multi-version ads ([] for single-creative ads, null when unknown)
ads[].creatives[].bodystring | nullads[].creatives[].titlestring | nullads[].creatives[].captionstring | nullads[].creatives[].linkDescriptionstring | nullads[].creatives[].linkUrlstring | nullads[].creatives[].ctaTextstring | nullads[].creatives[].ctaTypestring | nullads[].creatives[].imagestring | null- Full-size image URL (expiring CDN link)
ads[].creatives[].imageResizedstring | nullads[].creatives[].videoUrlstring | null- HD video URL when available, else SD
ads[].creatives[].videoPreviewImagestring | nullads[].mediaobject[]ads[].media[].typeenum- one of: image, video
ads[].media[].urlstring | null- Image URL, or the preview image of a video
ads[].media[].videoUrlstring | nullads[].startDateinteger | null- Delivery start, Unix seconds
ads[].endDateinteger | null- Delivery end, Unix seconds; null while the ad is running
ads[].platformsstring[]- FACEBOOK, INSTAGRAM, MESSENGER, AUDIENCE_NETWORK, THREADS
ads[].isResharedboolean | nullads[].adCountinteger | null- Ads sharing this creative (collation_count)
ads[].currencystring | null- Only disclosed for political / social-issue ads
ads[].categoriesstring[] | null- Special ad categories, when the source exposes them
ads[].sourceUrlstring- Ad Library permalink
ads[].urlstring- Same value as sourceUrl (AnyAPI field name)
totalResultsinteger | null- Total matches reported by the source (may be capped, e.g. 50001); null when unknown
nextCursorstring | null
TypeScript type
/** output.data when output.found is true */
type FacebookCompanyAds = {
ads: {
/** Ad Library archive id (ad_archive_id) */
id: string;
/** Same value as id (AnyAPI field name) */
adArchiveId: string;
/** Ad was delivering when scraped */
active: boolean | null;
/** Advertiser page id */
pageId: string | null;
pageName: string | null;
pageUrl: string | null;
pageProfilePicture: string | null;
pageLikes: number | null;
pageCategories: string[];
pageDeleted: boolean | null;
/** Primary ad copy */
text: string | null;
/** Same value as text (AnyAPI field name) */
body: string | null;
/** Headline */
title: string | null;
/** Display domain / link caption */
caption: string | null;
linkDescription: string | null;
/** Landing page URL */
linkUrl: string | null;
ctaText: string | null;
ctaType: string | null;
/** IMAGE, VIDEO, CAROUSEL, DCO, … */
displayFormat: string | null;
/** video when the creative has a video, else image when it has one */
type: "image" | "video" | null;
/** First image (or video preview image) URL */
image: string | null;
/** First video URL */
videoUrl: string | null;
/** Per-card / per-version creative of multi-version ads ([] for single-creative ads, null when unknown) */
creatives: {
body: string | null;
title: string | null;
caption: string | null;
linkDescription: string | null;
linkUrl: string | null;
ctaText: string | null;
ctaType: string | null;
/** Full-size image URL (expiring CDN link) */
image: string | null;
imageResized: string | null;
/** HD video URL when available, else SD */
videoUrl: string | null;
videoPreviewImage: string | null;
}[] | null;
media: {
type: "image" | "video";
/** Image URL, or the preview image of a video */
url: string | null;
videoUrl: string | null;
}[];
/** Delivery start, Unix seconds */
startDate: number | null;
/** Delivery end, Unix seconds; null while the ad is running */
endDate: number | null;
/** FACEBOOK, INSTAGRAM, MESSENGER, AUDIENCE_NETWORK, THREADS */
platforms: string[];
isReshared: boolean | null;
/** Ads sharing this creative (collation_count) */
adCount: number | null;
/** Only disclosed for political / social-issue ads */
currency: string | null;
/** Special ad categories, when the source exposes them */
categories: string[] | null;
/** Ad Library permalink */
sourceUrl: string;
/** Same value as sourceUrl (AnyAPI field name) */
url: string;
}[];
/** Total matches reported by the source (may be capped, e.g. 50001); null when unknown */
totalResults: number | null;
nextCursor: string | null;
};If what you asked about does not exist, is private, or a search matches nothing, the call still succeeds: output.found is false, output.data is null and output.reason says why. Such misses are free unless the notes below say misses are billed, in which case a miss costs the price of one call.
Pagination. Pass the previous response’s nextCursor as cursor to get the next page. nextCursor: null means there is nothing more. See Pagination.
Example response
Values are placeholders that follow the output schema (strings as "string", numbers as 0); credits shows what this call would cost at the usual price.
{
"output": {
"found": true,
"data": {
"ads": [
{
"id": "string",
"adArchiveId": "string",
"active": true,
"pageId": "15087023444",
"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": 2,
"items": 1,
"requestId": "req_01JBXK6Y2N9V8T4R3Q2P1M0A7Z",
"nextCursor": null
}Pricing and reliability
Calls go only to upstreams that are healthy right now. If an attempt fails, the call is retried automatically inside the same request; a failed attempt costs nothing, and a call never costs more than its quote’s maxCredits. Live figures below are measured on real traffic.
Success rate, uptime, latency and call counts are measured live from real traffic over 30 days and show “—” until there is data.
Errors
Errors are JSON { code, error, requestId } and are never charged. The ones to handle for this endpoint:
- invalid_inputThe request failed validation before anything ran.
- unauthorizedNo valid API key or session was presented.
- insufficient_balanceThe balance cannot cover the most this call could cost.
- key_limit_reachedThe key’s own spend limit is used up for the current window.
- trial_cap_reachedAn agent trial key has used its whole trial budget.
- forbiddenThe credential is valid but may not do this.
- not_foundThe thing addressed by the URL does not exist for you.
- idempotency_conflictThe
Idempotency-Keyis already bound to a different request. - rate_limitedToo many requests in the current window.
- all_sources_failedThe call could not be answered, even after automatic retries.
- service_unavailableThis API cannot run in this deployment right now.
- timeoutThe request passed its deadline before it finished.
More Facebook endpoints
- Facebook Ad Creative Details2 credits
- Facebook Ad Details2 credits
- Facebook Ad Library Advertiser Search2 credits
- Facebook Ad Library Search1 credit
- Facebook Event Details2 credits
- Facebook Events by City2 credits
- Facebook Events Search2 credits
- Facebook Group Posts2 credits
- Facebook Marketplace Item2 credits
- Facebook Marketplace Search2 credits
- Facebook Page Contact Info2 credits
- Facebook Page Events2 credits
- Facebook Page Lookup by Name2 credits
- Facebook Page Photos2 credits
- Facebook Page Posts2 credits
- Facebook Page Profile2 credits
- Facebook Page Reels2 credits
- Facebook Page Search6.25 credits per result
- Facebook Post2 credits
- Facebook Post Comments2 credits
- Facebook Post Search3.24 credits per result
- Facebook Post Transcript2 credits
- Facebook Followers / Following ListPlanned
Generated from the PrimaryAPI catalog. Machine-readable contract: GET https://api.primaryapi.com/v1/apis/facebook.company_ads.