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

GoalRouteSDK
Keyword searchGET /v1/facebook/ad-library/ads/searchclient.facebook.searchAdLibraryAds({ query, … })
Find advertisersGET /v1/facebook/ad-library/companies/searchclient.facebook.searchAdLibraryCompanies({ query })
List a company's adsGET /v1/facebook/ad-library/companies/adsclient.facebook.listCompanyAds({ pageId?, companyName?, … })
One ad by URL/idGET /v1/facebook/ad-library/adsclient.facebook.getAdLibraryAd({ url?, adId?, … })

Useful filters on search / company lists: country, status (active / inactive / all), mediaType, sortBy (impressions / most-recent), startDate / endDate, cursor.

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:

On this page