Developer resources · API V2

Adflex API examples, OpenAPI, and Postman collection

Start with a public contract, importable requests, and server-side examples for filters, platform search, Mega Search, snapshot pagination, and ad details.

Resource version 2.0.0 · checked against the public Adflex API guide on September 2, 2026.

First request

Discover filters before building a search

Filter keys, options, defaults, and component shapes can differ by platform. Fetch the live filter definition instead of copying a cached request between sources.

cURL · free filter endpoint

curl --get "https://api.adflex.io/api/v2/ads/facebook/filters" \
  --header "x-api-key: YOUR_API_KEY"

cURL · Mega Search page 1

curl --request POST "https://api.adflex.io/api/v2/ads/mega/search" \
  --header "Content-Type: application/json" \
  --header "x-api-key: YOUR_API_KEY" \
  --data '{
    "page": 1,
    "advanced_order": {"orderby": "newest", "order": "desc"},
    "search_field": [{"type": "text", "text": "smart ring"}]
  }'
Server-side examples

Check application success, not only HTTP status

Adflex can return an application failure inside an HTTP 200 response. Production clients should require status = ok and meta.code = 1000.

Node.js 18+

const response = await fetch(
  "https://api.adflex.io/api/v2/ads/mega/search",
  {
    method: "POST",
    headers: {
      "content-type": "application/json",
      "x-api-key": process.env.ADFLEX_API_KEY,
    },
    body: JSON.stringify({
      page: 1,
      advanced_order: { orderby: "newest", order: "desc" },
      search_field: [{ type: "text", text: "smart ring" }],
    }),
  },
);

const payload = await response.json();
if (payload.status !== "ok" || payload.meta?.code !== 1000) {
  throw new Error(payload.meta?.message || "Adflex API request failed");
}

console.log(payload.data.ads);

Python 3 + requests

import os
import requests

response = requests.post(
    "https://api.adflex.io/api/v2/ads/mega/search",
    headers={"x-api-key": os.environ["ADFLEX_API_KEY"]},
    json={
        "page": 1,
        "advanced_order": {"orderby": "newest", "order": "desc"},
        "search_field": [{"type": "text", "text": "smart ring"}],
    },
    timeout=30,
)
response.raise_for_status()
payload = response.json()

if payload.get("status") != "ok" or payload.get("meta", {}).get("code") != 1000:
    raise RuntimeError(payload.get("meta", {}).get("message") or "Adflex API request failed")

print(payload["data"]["ads"])
Pagination

Keep the page-one snapshot unchanged

Page 1

  • Set page to 1.
  • Omit last_hit.
  • Store the returned data.last_hit.
  • A page returns up to 18 ads.

Page 2 and later

  • Increment page.
  • Reuse the exact page-one last_hit.
  • Keep every filter and sort unchanged.
  • Continue while data.has_next_page is true.

Mega detail rule: /v2/ads/mega/{id} does not exist. Read platform and id from the Mega result, then request /v2/ads/{platform}/{id}.

Production checklist

Keep credentials private and retries bounded

Security

  • Send the key in the x-api-key header.
  • Keep keys out of browsers, URLs, request bodies, analytics, logs, and public repositories.
  • Use a server-side secret manager or protected environment variable.
  • Rotate a key immediately if it is exposed.

Reliability and credits

  • Retry only connection errors, timeouts, or temporary server failures.
  • Use exponential backoff with jitter and stop after three attempts.
  • Do not retry validation, authentication, permission, or not-found failures.
  • Filters are free; search and detail requests currently cost 100 credits each.

These starter resources intentionally use placeholders and permissive platform-specific schemas. The live filter endpoints and official endpoint reference remain authoritative.