1. Find the advertiser
Search the Meta Ad Library by the name the user supplies. The SDK setstype=accounts; the REST request states it explicitly.
id. The row carries name, meta_ad_library.category, stats.followers (the Meta page like count), and meta_ad_library.instagramHandle.
2. Confirm the social accounts
Look up Instagram, TikTok, and YouTube separately. Usemeta_ad_library.instagramHandle for Instagram. TikTok and YouTube need a handle the user already has; the Ad Library result does not carry those handles.
accounts.lookup works by a known handle, URL, or id, so the handle must come from the advertiser row or the user; never guess one. The account response includes the platform’s public profile data, such as name, description, url, avatar, verified, and stats. Platform-specific blocks add the fields that platform publishes: for example, Instagram has instagram.private, while TikTok has tiktok.likes and tiktok.private. See Look up an account for the full response fields and platform differences.
3. Collect candidates
List each account with the platform-specific selector. The advertiser id is the selector for the Meta page. For the Meta page, request active ads. Each row can represent a near-identical variant group;ad.collationCount tells you how many variants are in that group. If total is large, split the request into ad start-date windows with since and until.
TypeScript
TypeScript
TypeScript
page.nextCursor as cursor alone. The cursor already carries the platform, account, and filters, so do not repeat account, type, sort, or other filters on the next call. TikTok and the Ad Library have no cursor. See List an account’s items for the complete paging rules and response fields.
4. Rank candidates in your code
Refmatter returns candidates; it does not rank them for you. Build a score that fits the product’s goal from the fields available on each platform:- Use
stats.views,stats.likes, andstats.commentswhere the platform provides them. Instagram reels provide those engagement fields; YouTube provides views; TikTok provides a view count but its item rows do not provide likes or comments. - Use
ad.startedAt,ad.endedAt, andad.collationCountto compare active periods and the number of near-identical ad variants. Ad Library rows do not provide public engagement counts. - Use
publishedAtandpublishedTextwhere present. Several values arenull: list rows normally havepublishedAt: nullfor YouTube, Instagram does not providepublishedText, and TikTok does not providepublishedText. - Keep the platform’s
nullvalues as unknown rather than treating them as zero. The item list guide describes what each platform provides and omits.
publishedText for YouTube, views and recency for TikTok, and start date plus ad.collationCount for Meta ads. The weights and the treatment of missing values belong in your application.
5. Import the chosen items
Import each selected row’surl. Use imports.create when you want to manage the import job yourself, or use the SDK’s importUrl convenience wrapper to create the import and wait for its reference.
id and, once the reference is readable, a referenceId. Read that reference with GET /v1/references/{referenceId}. In the SDK, importUrl returns { importJob, reference }; reference is null when the import failed before a reference existed. Use primaryMediaId with GET /v1/media/{mediaId}/download-url or refmatter.media.access(mediaId) for a media download URL. See Import a URL, References, and Media access.
6. Budget the scan
Plan roughly one credit for each live page that has at least one row, or for the first stored serving of a page with a row. Repeats withinmaxAge are free, empty pages are free, and every error is free. That means the scan can usually reuse a fresh advertiser search, account lookup, or item page without charging again; the two Instagram list types are separate pages. See Search, Look up an account, and List an account’s items for the endpoint-specific credit rules.
Every response includes Refmatter-Credits-Remaining, the workspace balance after the response. A live request at a zero balance returns 402 insufficient_credits. If the service returns 429 rate_limited, use the Retry-After header before trying again. Errors do not charge credits.