# Ad Swipe File public API

A small JSON API over the Ad Swipe File ad library, for accounts on Pro, Agency or their 7-day free trial. Account endpoints cover your saved ads, boards and followed brands.

Every list returns every page, through `limit` and `cursor`. Every ad comes as a card:

- What Meta's Ad Library stores for it: status and run dates, platforms, copy, call to action, advertiser, image and video.
- Its brand, niche, formats, standard tags and page URL.

The [MCP server](https://adswipefile.com/docs/mcp) reads the same library, and the same token works there.

## Authentication

Every `/api/v1` request needs one of:

- **An API key**: `Authorization: Bearer asf_…`. Make one at https://adswipefile.com/app/api-keys while signed in. It is shown once. A key acts as your account, with its plan and allowance, for reads and writes alike. It works on the [MCP server](https://adswipefile.com/docs/mcp) too. Revoke it there when a script no longer needs it.
- **A signed-in session**, in the browser: [sign in](https://adswipefile.com/login) and call the API from a page on https://adswipefile.com. The session cookie is sent automatically. A session writes only from the site's own pages (`Sec-Fetch-Site: same-origin`), never from another site.
- **An OAuth 2.1 access token**: `Authorization: Bearer <token>`. The MCP flow issues it, so a client already connected over MCP can reuse it.

Getting a token, for a client of your own:

1. Discover: a request without credentials answers `401` with `WWW-Authenticate: Bearer resource_metadata="…"`. That document names the authorization server. Its metadata is at https://adswipefile.com/.well-known/oauth-authorization-server.
2. Register a client with `POST https://adswipefile.com/api/auth/oauth2/register`. Dynamic client registration is open.
3. Authorize with code and PKCE (S256) at https://adswipefile.com/api/auth/oauth2/authorize. Send `resource=https://adswipefile.com/api/mcp` and `scope=mcp:read`. Add `mcp:write` for the account endpoints' `POST` and `DELETE`, and `offline_access` for a refresh token. The person signs in by email link, code or Google, and approves the access asked for.
4. Exchange the code at https://adswipefile.com/api/auth/oauth2/token.

Tokens are bound to the audience `https://adswipefile.com/api/mcp` and the scope `mcp:read`, for this API and the MCP server alike. Changing saves, boards and follows also needs `mcp:write`.

- A missing, invalid or expired token, or a revoked key, is a `401` problem.
- So is a token whose app the person disconnected at https://adswipefile.com/app/connect, from its next call. Its refresh token stops too: authorize again.
- A token without `mcp:read` is a `403`.
- A write with a token without `mcp:write` is a `403`. Its `WWW-Authenticate` carries `error="insufficient_scope", scope="mcp:read mcp:write"`: authorize again with both scopes.

A token approved before `mcp:write` existed reads only until you do.

The machine-readable description is https://adswipefile.com/openapi.json (OpenAPI 3.1; every operation has an `operationId`, so it imports as function-calling tools).

## Endpoints

Every operation has its own page, with its parameters, an example and its responses. This list is generated from [https://adswipefile.com/openapi.json](https://adswipefile.com/openapi.json), so it is the whole API.

### Library

The ad library as JSON.

- [`GET /api/v1/search`](https://adswipefile.com/docs/api/search-library): Search ads, brands, niches and formats
- [`GET /api/v1/ads`](https://adswipefile.com/docs/api/list-ads): The newest ads, optionally by brand, niche, format and standard tags
- [`GET /api/v1/visual-formats`](https://adswipefile.com/docs/api/list-visual-formats): The standard visual formats in use
- [`GET /api/v1/formats`](https://adswipefile.com/docs/api/list-formats): The visual formats, with their page URLs
- [`GET /api/v1/formats/{slug}`](https://adswipefile.com/docs/api/get-format): A visual format's guide
- [`GET /api/v1/niches/{slug}`](https://adswipefile.com/docs/api/get-niche): A niche in brief
- [`GET /api/v1/hooks/{slug}`](https://adswipefile.com/docs/api/get-hook): A hook tactic in brief
- [`GET /api/v1/hooks`](https://adswipefile.com/docs/api/list-hooks): The hook tactics in use
- [`GET /api/v1/trends`](https://adswipefile.com/docs/api/get-trends): A niche's rising formats, hooks and asset types
- [`GET /api/v1/brands/by-domain`](https://adswipefile.com/docs/api/get-brand-by-domain): Find a brand by its website
- [`GET /api/v1/ads/batch`](https://adswipefile.com/docs/api/get-ads): Several ads in full
- [`GET /api/v1/ads/{id}`](https://adswipefile.com/docs/api/get-ad): One ad in full
- [`GET /api/v1/ads/{id}/similar`](https://adswipefile.com/docs/api/get-similar-ads): Ads like one ad, from other brands
- [`GET /api/v1/brands`](https://adswipefile.com/docs/api/list-brands): The library's brands
- [`GET /api/v1/niches`](https://adswipefile.com/docs/api/list-niches): The library's niches
- [`GET /api/v1/ads/counts`](https://adswipefile.com/docs/api/count-ads): Ads by visual format, hook tactic or niche
- [`GET /api/v1/brands/{slug}`](https://adswipefile.com/docs/api/get-brand): A brand's profile, stats and patterns
- [`GET /api/v1/brands/{slug}/activity`](https://adswipefile.com/docs/api/get-brand-activity): What a brand changed each week

### Saved ads

A workspace's saved ads and the notes on them. Listing them counts like listAds; saving, unsaving and notes are free. Writes need an API key, an OAuth token with mcp:write, or a session on the site's own pages.

- [`GET /api/v1/saved-ads`](https://adswipefile.com/docs/api/list-saved-ads): A workspace's saved ads
- [`POST /api/v1/saved-ads`](https://adswipefile.com/docs/api/save-ad): Save an ad
- [`DELETE /api/v1/saved-ads/{id}`](https://adswipefile.com/docs/api/unsave-ad): Unsave an ad
- [`PUT /api/v1/saved-ads/{id}/note`](https://adswipefile.com/docs/api/set-ad-note): Write a note on a saved ad

### Boards

The account's boards: create, rename, delete, share by link, and the ads on them. Free. Writes need an API key, an OAuth token with mcp:write, or a session on the site's own pages.

- [`GET /api/v1/boards`](https://adswipefile.com/docs/api/list-boards): A workspace's boards
- [`POST /api/v1/boards`](https://adswipefile.com/docs/api/create-board): Create a board
- [`PATCH /api/v1/boards/{board}`](https://adswipefile.com/docs/api/rename-board): Rename a board
- [`DELETE /api/v1/boards/{board}`](https://adswipefile.com/docs/api/delete-board): Delete a board
- [`POST /api/v1/boards/{board}/share`](https://adswipefile.com/docs/api/share-board): Turn on a board's share link
- [`DELETE /api/v1/boards/{board}/share`](https://adswipefile.com/docs/api/unshare-board): Turn off a board's share link
- [`POST /api/v1/boards/{board}/ads`](https://adswipefile.com/docs/api/add-ad-to-board): Add an ad to a board
- [`DELETE /api/v1/boards/{board}/ads/{id}`](https://adswipefile.com/docs/api/remove-ad-from-board): Remove an ad from a board

### Following

The brands the account follows and their newest ads. Following is free; the ads count like listAds.

- [`GET /api/v1/following/brands`](https://adswipefile.com/docs/api/list-followed-brands): The brands a workspace follows
- [`GET /api/v1/following/ads`](https://adswipefile.com/docs/api/list-followed-ads): New ads from followed brands
- [`GET /api/v1/ads/followed`](https://adswipefile.com/docs/api/list-followed-library-ads): Every ad of the followed brands, filtered and paged
- [`POST /api/v1/brands/{slug}/follow`](https://adswipefile.com/docs/api/follow-brand): Follow a brand, in the library or any on Meta
- [`DELETE /api/v1/brands/{slug}/follow`](https://adswipefile.com/docs/api/unfollow-brand): Stop following a brand

### Briefs

A workspace's creative briefs, the documents its team writes and approves in the app. Reading one or the list counts like listAds; writing and setting a status are free. Writes need an API key, an OAuth token with mcp:write, or a session on the site's own pages.

- [`GET /api/v1/briefs`](https://adswipefile.com/docs/api/list-briefs): A workspace's briefs
- [`POST /api/v1/briefs`](https://adswipefile.com/docs/api/create-brief): Start a brief
- [`GET /api/v1/briefs/{brief}`](https://adswipefile.com/docs/api/get-brief): Read a brief
- [`PUT /api/v1/briefs/{brief}`](https://adswipefile.com/docs/api/update-brief): Save a new version of a brief
- [`PATCH /api/v1/briefs/{brief}`](https://adswipefile.com/docs/api/set-brief-properties): Set a brief's properties
- [`GET /api/v1/briefs/{brief}/versions`](https://adswipefile.com/docs/api/list-brief-versions): A brief's versions
- [`POST /api/v1/briefs/{brief}/versions/{version}/restore`](https://adswipefile.com/docs/api/restore-brief-version): Restore a brief's version

### Workspace brand

The reader's own brand, the one they make ads for (Your brand), not a library brand or a followed competitor: name, niche, site, Meta page and markdown notes on what it sells, who buys it and how it sounds. Free. Writes need an API key, an OAuth token with mcp:write, or a session on the site's own pages.

- [`GET /api/v1/workspace/brand`](https://adswipefile.com/docs/api/get-my-brand): The reader's own brand
- [`PATCH /api/v1/workspace/brand`](https://adswipefile.com/docs/api/update-my-brand): Update the reader's own brand

### Account

The account's calls left this period, and its organization's workspaces (what `workspace` takes on the saved-ads, boards and following endpoints). Free.

- [`GET /api/v1/account/usage`](https://adswipefile.com/docs/api/get-usage): Calls left this period
- [`GET /api/v1/workspaces`](https://adswipefile.com/docs/api/list-workspaces): The organization's workspaces

### Pages

Any page as markdown.

- [`GET /{path}`](https://adswipefile.com/docs/api/get-page-as-markdown): Any page as markdown, at its own URL
- [`GET /md/{path}`](https://adswipefile.com/docs/api/get-markdown-rendition): The same markdown at a URL of its own

### Ops

Service status.

- [`GET /api/health`](https://adswipefile.com/docs/api/get-health): Liveness and the running build

## Search and names

`GET /api/v1/search?q=`:

- `q` needs at least 2 characters. A longer query is cut to 64. The MCP tool `search_library` takes longer queries, so send a long question there.
- `limit` is 1 to 25, and 10 when left out. It counts one call per 10 results asked for.

`/ads`, `/trends` and `/brands` accept a plain name, an alias or a niche group wherever they take a slug. When they read a name differently from how it was written, the answer says so:

- `/ads`: `corrected_filters` and `unused_filters`, with a `hint`.
- `/trends`: `corrected_filters`.
- `/brands`: `corrected_filters` and a `hint`.

`GET /api/v1/ads/batch?ids=` reads up to 25 ads in one request. Pass ids, page URLs or 8-character prefixes. Each ad counts one call. With `compact=true` it answers each ad as its `/ads` card instead, at one call per 10 ads, as a list page. Ads it could not find are listed under `missing`.

## Ad cards

Every card, in a list or read alone, carries what Meta's Ad Library stores for the ad, from our stored copy of it (as of `run.last_seen`, not a fresh request to Meta):

- `run`: `active`, `started`, `ended`, `last_seen` and `days_running`.
- `platforms`: where it ran, e.g. `Facebook`, `Instagram`.
- `copy`: its `headline` and `body` (the primary text).
- `cta`: the button's `text`, its `type` (Meta's enum, e.g. `SHOP_NOW`) and the landing page `url`.
- `advertiser`: the Facebook page that ran it (`page_id`, `name`, `ad_library_url`).
- `image`: the creative (a video's poster) on our CDN. `video`: a video ad's page, where it plays; never the file.

An ad imported before tracking has them `null` or empty, except its `copy` when read alone.

`GET /api/v1/ads/{id}` returns one ad's card, plus:

- `why_it_works`: the mechanism of its hook, format and offer, from its tags: why it works.
- `breakdown`, once the ad is read: what it says, its traits, its units, its structure and its `remix` script.
- `remix_spec`, with the breakdown on the plan: the ad as a spec to build from, as MCP `get_ad`. `compact=true` keeps the script once, there.
- `duplicates`: the other ads showing the same creative, the same file or the same image re-encoded or resized. Other brands come first.
- `meta`, for an ad tracked on Meta: `platforms`, `cta`, `display_format` and `variants`. It adds `brand_median_run_days` and `brand_tracked_ads` when the brand has at least 5 tracked ads.

With `brand`, `GET /api/v1/ads` adds `brand_patterns`: read counts per type, the trait shares (from 5 read ads), and the top structure, format and hook, and `brand_mix`: its offers, landing pages and angles. It takes what MCP `list_ads` takes, from the same body: `query`, `followed` (with `per_brand` and `workspace`), `distinct`, `fields` (`angle`, `lands_on`) and `sort=most_variants`.

Every card carries the ad's standard tags:

- `visual_formats`: up to three.
- `hook_tactic` and `hook_line`, the hook as written.
- `asset_type`, `offer_type`, `season` and `talent`.
- `awareness`: how much the viewer is assumed to know, from `unaware` to `most-aware`.

They are empty or `null` until the library has tagged the ad. `awareness` is also `null` on ads tagged before it was added. They describe the creative.

## Your saves, boards and followed brands

The saved-ads, boards, following and account endpoints above read or change your account only. None counts against the allowance except the two lists of ads: saved ads and new ads from followed brands.

The writes (`POST`, `PUT`, `PATCH`, `DELETE`) take an API key, a token with `mcp:write`, or a session on the site's own pages. They have their own window of 30 a minute per account.

No input names an owner. Every call reads or changes one workspace of your organization: a client or brand, with its own saves, notes, boards and follows.

- Add `?workspace=` with a workspace's id or exact name, in any case, to any of these endpoints. Without it, the call acts in your current workspace, the one you last opened in the app.
- Every answer names the workspace it acted in as `workspace` (`id`, `name`).
- A workspace your organization does not have is a `404 workspace_not_found`. One past your plan's workspaces is a `403 workspace_locked`.
- A board is named by its id or its exact name, inside that workspace. Another workspace's board answers `404`.

```bash
curl -s -X POST -H "Authorization: Bearer $ADSWIPEFILE_API_KEY" -H 'content-type: application/json' -d '{"name":"March brief"}' 'https://adswipefile.com/api/v1/boards'
curl -s -X POST -H "Authorization: Bearer $ADSWIPEFILE_API_KEY" 'https://adswipefile.com/api/v1/brands/glossier/follow?workspace=Acme'
curl -s -H "Authorization: Bearer $ADSWIPEFILE_API_KEY" 'https://adswipefile.com/api/v1/workspaces'
curl -s -H "Authorization: Bearer $ADSWIPEFILE_API_KEY" 'https://adswipefile.com/api/v1/account/usage'
```

Slugs are the last part of a page URL: https://adswipefile.com/niches/beauty is the niche `beauty`. Find them with search.

```bash
curl -s -H "Authorization: Bearer $ADSWIPEFILE_API_KEY" 'https://adswipefile.com/api/v1/search?q=protein'
curl -s -H "Authorization: Bearer $ADSWIPEFILE_API_KEY" 'https://adswipefile.com/api/v1/ads?niche=beauty&format=ugc&limit=5'
curl -s -H "Authorization: Bearer $ADSWIPEFILE_API_KEY" 'https://adswipefile.com/api/v1/ads?visual_format=testimonial&season=black-friday'
```

## Rate limits

60 requests a minute per account, over a sliding window. Every authenticated response says where you stand:

```http
RateLimit-Policy: "account";q=60;w=60
RateLimit: "account";r=59;t=42
```

(`RateLimit-Limit`, `RateLimit-Remaining` and `RateLimit-Reset` carry the same numbers.) Past the limit the answer is `429` with the code `rate_limited` and `Retry-After` in seconds.

## Allowance: monthly on Pro and Agency

Every MCP tool call and every `/api/v1` request counts against the allowance of the account's plan. It resets in UTC. The allowance is 10,000 a month on Pro and 50,000 a month on Agency. It is 200 a day during the 7-day free trial of either.

A paid month also has a daily ceiling, so it cannot all go in one day. The ceiling is 1,000 on Pro and 3,000 on Agency. A call refused at the ceiling does not count against the month.

`get_ad` and `get_ads` read ads in full: each ad counts one call. Lists and searches answer summary cards, with no full copy, transcript or breakdown: on Pro and Agency, a `list_ads` or `search_library` page, or a `get_ads` call with `compact: true`, counts one call per 10 ads asked for. A `limit` of 50 counts 5. So list or search first, and read in full only the ads you will analyse.

Some calls are free of the allowance. The library's map is free: `list_niches`, `list_formats`, `list_visual_formats`, `list_hooks` and their `/api/v1` endpoints. Your own boards, followed brands, workspaces and usage are free too: `list_boards`, `list_followed_brands`, `list_workspaces`, `get_usage` and their `/api/v1` endpoints. So is every write: saves, notes, follows, boards, briefs and `submit_feedback`. Reading briefs counts: `list_briefs` and `get_brief` are one call each.

An account that never had a plan gets a preview of 20 calls in all. Each MCP list or search is cut to its first 10 results, without breakdowns. Past the 20 calls, every call that counts is refused, with a link to the plans page. Once a plan or its trial ends, there is no preview: every call that counts is refused, with a link to choose a plan again.

Past the allowance, the API answers `429` with the code `quota_exceeded` and `Retry-After` set to the reset. The reset is in UTC: the first of next month on Pro and Agency. MCP tools answer with a message instead of results. Both say when the allowance resets and how to raise it, with the link.

See [pricing](https://adswipefile.com/pricing).

## Errors

Every error is `application/problem+json` (RFC 9457), including unknown paths under `/api/`. Responses are never cached (`Cache-Control: private, no-store`).

```json
{ "type": "https://adswipefile.com/docs/api#errors", "title": "Not found", "status": 404,
  "detail": "No niche with slug \"beuty\".", "code": "not_found",
  "resolution": "Find slugs with /api/v1/search?q=<name>, …" }
```

Branch on `code` (one of `not_found`, `bad_request`, `unauthorized`, `forbidden`, `plan_limit`, `workspace_not_found`, `workspace_locked`, `method_not_allowed`, `rate_limited`, `conflict`, `read_only`, `quota_exceeded`, `not_acceptable`, `service_unavailable`), show `detail`, follow `resolution`.

## Markdown instead of JSON

Add `.md` to any page URL for that page as markdown (https://adswipefile.com/niches.md, https://adswipefile.com/index.md for the home page). The page URL itself also answers `Accept: text/markdown` with the same markdown: `curl -H 'Accept: text/markdown' https://adswipefile.com/niches`. A client that accepts neither markdown nor HTML gets `406`.
