Apify example task · whoareyouanas/facebook-ads-library-api

Scrape Instagram ads for a keyword

Find active ads that ran on Instagram for the keyword skincare in the United States, using a Meta Ad Library search URL filtered to Instagram placements.

Actor
Facebook Ads Library API & Instagram Ads Scraper
Result limit
25 (maxAds)
Estimated cost
Up to $0.10
Run options
0.5 GB memory · 300 s timeout

Example updated 2026-11-23 · actor build 0.2.10 · runs in your own Apify account

01 / About the actor

Facebook Ads Library API & Instagram Ads Scraper

Facebook Ads Library API for developers and AI agents. Search Facebook and Instagram ads by keyword, Page ID or Ad Library URL and get ad copy, images, videos, CTAs, landing pages and dates as JSON in seconds. No Meta token, login or proxy setup. Exact ad limits. MCP-ready.

One focused search

Use one keyword, Page ID, or direct search URL per run.

Bound the ad sample

Set maxAds rather than relying on Meta's approximate displayed result count.

Keep creative structure

Review image, video, carousel, and dynamic creative fields in JSON or dataset exports.

02 / Input

The exact input this example runs.

Provide targetUrl, searchQuery, or pageId and set maxAds for the unique-ad cap. Use the documented country, status, media, and date filters where applicable. The current Actor uses built-in proxies and ignores the legacy proxyConfiguration field.

input.json · instagram-ads-by-keyword
{
  "targetUrl": "https://www.facebook.com/ads/library/?active_status=active&ad_type=all&country=US&media_type=all&publisher_platforms[0]=instagram&q=skincare&search_type=keyword_unordered",
  "maxAds": 25
}
Input fields used by this example, their values and what they control
FieldValue in this exampleWhat it controls
targetUrlChange this"https://www.facebook.com/ads/library/?active_status=active&ad_type=all&country=US&media_type=all&publisher_platforms[0]=instagram&q=skincare&search_type=keyword_unordered"Paste any Meta Ad Library search URL from your browser. It takes precedence over Page ID and keyword, and its filters (country, status, platforms, sort, date range) take precedence over the form. Tracking parameters such as fbclid are removed automatically. To look up one ad by its ID, use our Facebook Ad Library Single Ad Lookup.
maxAdsChange this25Maximum unique ads to deliver in this run, from 1 to 10,000. You pay only for ads delivered, and the run stops exactly at this limit.
Other inputs you can add (7)
Deployed actor input fields, types, defaults, and descriptions
FieldType / requiredDefaultPurpose
searchQuerystringNot specifiedFind ads that mention a keyword, brand or product, for example nike or protein powder. The example searches nike. A URL or Page ID takes precedence when provided.
pageIdstringNot specifiedNumeric Facebook Page ID of one advertiser, the number after view_all_page_id= in its Ad Library URL. Takes precedence over the keyword example. A search URL takes precedence over this field.
countrystring"US"Two-letter country code where the ads were shown, such as US, GB, IN or DE, or ALL for every country. Used for keyword and Page ID searches.
activeStatusstring"active"Which ads to return by status. Used for keyword and Page ID searches.

Options: active, inactive, all

mediaTypestring"all"Return only ads with this kind of creative. Used for keyword and Page ID searches.

Options: all, image, video, meme, none

dateFromstringNot specifiedFirst day of the range, YYYY-MM-DD. Leave empty for no start limit.
dateTostringNot specifiedLast day of the range, YYYY-MM-DD. Leave empty for no end limit.

03 / Make it yours

Change these fields for your own research.

  1. 01 · targetUrl

    Ad Library search URL

    Paste any Meta Ad Library search URL from your browser. It takes precedence over Page ID and keyword, and its filters (country, status, platforms, sort, date range) take precedence over the form. Tracking parameters such as fbclid are removed automatically. To look up one ad by its ID, use our Facebook Ad Library Single Ad Lookup.

    Example: "https://www.facebook.com/ads/library/?active_status=active&ad_type=all&country=US&media_type=all&publisher_platforms[0]=instagram&q=skincare&search_type=keyword_unordered"

  2. 02 · maxAds

    Maximum ads

    Maximum unique ads to deliver in this run, from 1 to 10,000. You pay only for ads delivered, and the run stops exactly at this limit.

    Example: 25

Run it in three steps

  1. Open the example on Apify and select Try for free to copy it into your Apify account.
  2. Replace the sample values above with your own target and keep the limit small.
  3. Start the run, then export the dataset as JSON, CSV or Excel.

04 / Output

What the results table shows.

Columns in the “Ads” view

libraryID

Ad ID

brand

Advertiser

pageId

Page ID

active

Active

body

Ad copy

linkTitle

Headline

ctaText

Call to action

linkUrl

Landing page

format

Format

platforms

Platforms

startDate

Started

endDate

Ended

collaboratorName

Partnership creator

images

Images

videos

Videos

adLibraryUrl

View ad

A view selects columns for the table. The full JSON export keeps every field, including nested arrays and objects.

05 / Cost

What this example costs to run.

At most about $0.10: up to 25 results at $0.004 each (Ad). Fewer results cost less. The live Pricing tab on Apify is authoritative.

Prices checked 2026-11-24. Set a run spending limit in Apify when you widen the input.

06 / API

Run the same input from your code.

This call starts a billable run of Facebook Ads Library API & Instagram Ads Scraper with this example's input and returns the dataset items when it finishes. Synchronous calls wait up to five minutes; for longer runs, POST to /runs instead and read the run's default dataset when it succeeds. Keep the token in an environment variable.

cURL · run and return the results
curl --request POST \
  'https://api.apify.com/v2/acts/whoareyouanas~facebook-ads-library-api/run-sync-get-dataset-items?format=json' \
  --header "Authorization: Bearer $APIFY_TOKEN" \
  --header 'Content-Type: application/json' \
  --data '{"targetUrl":"https://www.facebook.com/ads/library/?active_status=active&ad_type=all&country=US&media_type=all&publisher_platforms[0]=instagram&q=skincare&search_type=keyword_unordered","maxAds":25}'

Coverage & interpretation

Check the result before relying on it.

Questions

About this example.

What does the "Scrape Instagram ads for a keyword" example collect?

Find active ads that ran on Instagram for the keyword skincare in the United States, using a Meta Ad Library search URL filtered to Instagram placements. It runs Facebook Ads Library API & Instagram Ads Scraper, published by whoareyouanas on Apify.

Which input does this example use?

Ad Library search URL (targetUrl) set to "https://www.facebook.com/ads/library/?active_status=active&ad_type=all&country=US&media_type=all&publisher_platforms[0]=instagram&q=skincare&search_type=keyword_unordered"; Maximum ads (maxAds) set to 25. The full JSON input is shown on this page.

How much does it cost to run this example?

At most about $0.10: up to 25 results at $0.004 each (Ad). Fewer results cost less. The live Pricing tab on Apify is authoritative.

How do I change it for my own research?

Open the example on Apify and select Try for free to copy it into your account, then edit Ad Library search URL, Maximum ads. Keep the result limit small for the first run and check the output before scaling up.

Can I run it from the API or on a schedule?

Yes. Send the same JSON input to the Facebook Ads Library API & Instagram Ads Scraper run endpoint with your Apify API token, or save the copied task in your Apify account and add a schedule. Results land in the run's default dataset as JSON, CSV or Excel.

How is the search limited to Instagram?

The Ad Library URL includes publisher_platforms[0]=instagram, the same filter the Ad Library applies when you choose Instagram as the platform. Each ad's platforms field lists every platform it ran on.

Can I paste my own Ad Library URL?

Yes. Set up a search in the Meta Ad Library in your browser, copy the address, and paste it as the search URL. Its country, status, platform, language, sort and date filters are kept; tracking parameters such as fbclid are ignored.

Does it scrape Instagram posts or profiles?

No. It returns ads from the Meta Ad Library that ran on Instagram, not organic posts or profile data.

More examples

Related tasks you can copy.

Guides

Read more about this workflow.