How to scrape the Meta Ad Library

Adrian Horning
Adrian Horning @adrian_horning_
How to scrape the Meta Ad Library

The Meta Ad Library is a goldmine for marketers, researchers, and growth, but it wasn’t built with automation in mind.

That’s why I built the Scrape Creators API to pull real-time Meta Ad Library data using simple HTTP requests.

In this post, I’ll show you exactly how to do that using **JavaScript with Axios**.

But, you can use any no-code platform also like Clay, Make or Zapier.

Anything where you can make API calls from.

You’ll also find:

- A video walkthrough on YouTube
- A working code example on GitHub
- Live demos for searching ads, finding companies, and more

🎥 Watch the Video

👉 Click here to watch on YouTube

🧠 What You'll Learn


- How to search for ads by keyword
- How to look up a company page
- How to get all ads from a specific advertiser
- How to retrieve a single ad by ID
- Copy/paste-ready Axios code examples

🛠 Setup


Before you start:

- Sign up at [Scrape Creators](https://scrapecreators.com) and grab your API key
- If you are using JavaScript (Node.js), install Axios in your project:

 npm install axios

🔍 Search Ads by Keyword

You know how you can search for ads by a keyword in the Meta Ad Library?

Well, you can do the same thing programmatically!

All you have to do is call the Search Ads endpoint with a `query` parameter, like so:

 
    const response = await axios.get(`https://api.scrapecreators.com/v1/facebook/adLibrary/search/ads?query=running`,
      {
        headers: {
          "x-api-key": process.env.SCRAPE_CREATORS_API_KEY,
        },
      }
    );
    return response.data;
 

And you can even search by Ad Type, Country, Status, and Start and End Date!

The response will look something like this.

 {
  "searchResults": [
    {
      "ad_archive_id": "615470338018648",
      "start_date": 1740729600,
      "state_media_run_label": null,
      "targeted_or_reached_countries": [],
      "total_active_time": 5519
    }
  ],
  "searchResultsCount": 50001,
  "cursor": "AQHRYLVDkoMkvGv7yK1rcce-vJmKiKv330R4v3j9KHSOaYvmF1bq1QkotG0rgW8Fkrj-"
}

Here are some of the valuable fields that will be returned:

  • `ad_archive_id` -> this is the ad id
  • `start_date_string`
  • `end_date_string`
  • `publisher_platform` -> to know if the ad is running on Instagram, Facebook, etc
  • `snapshot` -> This is where all the ad copy and variations will be
  • `body` -> body of the ad
  • `cta_text`
  • `link_url` -> where the user goes after they click on the ad
  • `page_id` -> The company's ad library page id
  • `videos`
  • `images`

And if you want more pages of results, just pass the `cursor` that is returned.

Get Individual Ad Details

Lets say we want to get the ad detail of a single ad.

For that we just need the Library ID, in this case 1755312555404167.

 const response = await axios.get(`https://api.scrapecreators.com/v1/facebook/adLibrary/ad?id=1755312555404167`, {
  headers: {
    "x-api-key": process.env.SCRAPE_CREATORS_API_KEY
  }
})

You will get the same details as above, including start_date_string, end_date_string, publisher_platform, snapshot, cta_text, link, etc.

Search for a company's ads

Now lets say we wanted to just get the ads from lululemon.

First we need the lululemon page id.

If you already know it, great, hold onto it.

If you don't, you can find it by using this endpoint:

 const response = await axios.get(`https://api.scrapecreators.com/v1/facebook/adLibrary/search/companies?query=lululemon`, {
  headers: {
    'x-api-key': process.env.SCRAPE_CREATORS_API_KEY
  }
})
console.log(response.data)

That will return a `searchResults` array.

You want to key into the first search result and return the page_id, like so:

 const lululemonPageId = response?.data?.searchResults?.[0]?.page_id

Then you can use that to fetch their ads using this endpoint:

 const response = await axios.get(`https://api.scrapecreators.com/v1/facebook/adLibrary/company/ads?pageId=${lululemonPageId}`, {
  headers: {
    'x-api-key': process.env.SCRAPE_CREATORS_API_KEY
  }
})
console.log(response.data)

And the response will almost be identical to the Search endpoint.

If you want additional pages, a `cursor` will be returned, and you need to pass that to subsequent requests like so:

 const response = await axios.get(`https://api.scrapecreators.com/v1/facebook/adLibrary/company/ads?pageId=${lululemonPageId}&cursor=AQHRBUAxNmFlxBVMFL6uTb1ICFsV65O4SqmPbcVZJhiveBpPS1hFHAmL6yCJcF760cXP`, {
  headers: {
    'x-api-key': process.env.SCRAPE_CREATORS_API_KEY
  }
})
console.log(response.data)

And that's it!

📦 Get the Full Code

Want to see all this code in one file?

👉 View on GitHub

✅ Ready to Start?

Create your free API key at Scrape Creators and start pulling Meta Ad Library data into your app.

Questions or feedback? Hit me up at adrian@thewebscrapingguy.com

Other APIs

If you're looking to scrape other Ad Libraries like the LinkedIn Ad Library, or Google Ad Transparency Center, check out Scrape Creators.

Also, if you want to scrape Instagram, YouTube, TikTok, Twitter, and more, you can also use scrape creators for that too!