Facebook Ad Library aggregation
Search Facebook Ad Library by keyword and list company ads — TypeScript SDK, pagination, and credit callouts
Pull public Meta Ad Library creatives for competitive research. Two complementary paths: keyword search across the library, and company/page ad lists when you already know the advertiser.
You'll need an API key and the TypeScript SDK. Platform overview: Facebook.
Credit budget
What this costs
Facebook Ad Library search, company lists, company search, and single-ad get are 1 credit per successful request (per page when paginating). Empty pages still bill when the lookup completes. Trust meta.creditsCharged.
Routes
| Goal | Route | SDK |
|---|---|---|
| Keyword search | GET /v1/facebook/ad-library/ads/search | client.facebook.searchAdLibraryAds({ query, … }) |
| Find advertisers | GET /v1/facebook/ad-library/companies/search | client.facebook.searchAdLibraryCompanies({ query }) |
| List a company's ads | GET /v1/facebook/ad-library/companies/ads | client.facebook.listCompanyAds({ pageId?, companyName?, … }) |
| One ad by URL/id | GET /v1/facebook/ad-library/ads | client.facebook.getAdLibraryAd({ url?, adId?, … }) |
Useful filters on search / company lists: country, status (active / inactive / all), mediaType, sortBy (impressions / most-recent), startDate / endDate, cursor.
Keyword search
import { SocialFetchClient } from "@socialfetch/sdk";
const client = new SocialFetchClient({
apiKey: process.env.SOCIALFETCH_API_KEY!,
});
const page = await client.facebook.searchAdLibraryAds({
query: "running shoes",
country: "US",
status: "active",
mediaType: "video",
sortBy: "most-recent",
});
if (!page.ok) {
console.error(page.error.code, page.error.requestId);
return;
}
for (const ad of page.value.data.ads ?? []) {
console.log(ad);
}
console.log(page.value.meta.creditsCharged, page.value.data.page);Resolve advertiser, then list ads
const companies = await client.facebook.searchAdLibraryCompanies({
query: "Acme Coffee",
});
if (!companies.ok) {
console.error(companies.error.code, companies.error.requestId);
return;
}
const first = companies.value.data.companies?.[0];
if (!first?.pageId) return;
const ads = await client.facebook.listCompanyAds({
pageId: first.pageId,
status: "active",
sortBy: "impressions",
});
if (!ads.ok) {
console.error(ads.error.code, ads.error.requestId);
return;
}
console.log(ads.value.data.lookupStatus, ads.value.data.ads?.length);If you already know the advertiser name, skip company search and call listCompanyAds({ companyName: "Acme Coffee", status: "active" }) directly.
Paginate with data.page.nextCursor while hasMore is true. Keep the same filters on every page.
Optional: other ad libraries
Same product idea, different networks:
- TikTok Ad Library search
- LinkedIn Ad Library search
- Google Ad Library (company ads are priced higher — see that operation page)
Related
- Facebook API · Credits · SDK · MCP