{
  "info": {
    "_postman_id": "70f45fd1-8dc8-4a1e-b328-260b73d3fe68",
    "name": "Adflex API V2",
    "description": "Safe starter collection for filters, search, pagination, Mega Search, and ad details. Add the API key only to your private Postman environment.",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "auth": {
    "type": "apikey",
    "apikey": [
      { "key": "key", "value": "x-api-key", "type": "string" },
      { "key": "value", "value": "{{api_key}}", "type": "string" },
      { "key": "in", "value": "header", "type": "string" }
    ]
  },
  "variable": [
    { "key": "base_url", "value": "https://api.adflex.io/api" },
    { "key": "api_key", "value": "" },
    { "key": "platform", "value": "facebook" },
    { "key": "filter", "value": "interests" },
    { "key": "ad_id", "value": "123" },
    { "key": "last_hit", "value": "" }
  ],
  "event": [
    {
      "listen": "test",
      "script": {
        "type": "text/javascript",
        "exec": [
          "pm.test('HTTP response is 200', function () { pm.response.to.have.status(200); });",
          "const json = pm.response.json();",
          "pm.test('Adflex application response is successful', function () {",
          "  pm.expect(json.status).to.eql('ok');",
          "  pm.expect(json.meta && json.meta.code).to.eql(1000);",
          "});"
        ]
      }
    }
  ],
  "item": [
    {
      "name": "1. Discover filters",
      "item": [
        {
          "name": "Get platform filters (free)",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{base_url}}/v2/ads/{{platform}}/filters",
              "host": [ "{{base_url}}" ],
              "path": [ "v2", "ads", "{{platform}}", "filters" ]
            },
            "description": "Fetch this before constructing a search. Accepted keys and options can differ by platform."
          },
          "response": []
        },
        {
          "name": "Get dynamic filter items (free)",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{base_url}}/v2/ads/{{platform}}/filters/{{filter}}?search=running",
              "host": [ "{{base_url}}" ],
              "path": [ "v2", "ads", "{{platform}}", "filters", "{{filter}}" ],
              "query": [ { "key": "search", "value": "running" } ]
            }
          },
          "response": []
        }
      ]
    },
    {
      "name": "2. Search",
      "item": [
        {
          "name": "Search page 1",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "const json = pm.response.json();",
                  "if (json.status === 'ok' && json.meta && json.meta.code === 1000 && json.data && json.data.last_hit !== undefined) {",
                  "  pm.collectionVariables.set('last_hit', String(json.data.last_hit));",
                  "}"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [ { "key": "Content-Type", "value": "application/json" } ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"page\": 1,\n  \"advanced_order\": {\n    \"orderby\": \"newest\",\n    \"order\": \"desc\"\n  },\n  \"search_field\": [\n    { \"type\": \"text\", \"text\": \"smart ring\" }\n  ]\n}",
              "options": { "raw": { "language": "json" } }
            },
            "url": {
              "raw": "{{base_url}}/v2/ads/{{platform}}/search",
              "host": [ "{{base_url}}" ],
              "path": [ "v2", "ads", "{{platform}}", "search" ]
            },
            "description": "Returns up to 18 ads and stores data.last_hit for the page 2 request."
          },
          "response": []
        },
        {
          "name": "Search page 2 with the page-one snapshot",
          "request": {
            "method": "POST",
            "header": [ { "key": "Content-Type", "value": "application/json" } ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"page\": 2,\n  \"last_hit\": {{last_hit}},\n  \"advanced_order\": {\n    \"orderby\": \"newest\",\n    \"order\": \"desc\"\n  },\n  \"search_field\": [\n    { \"type\": \"text\", \"text\": \"smart ring\" }\n  ]\n}",
              "options": { "raw": { "language": "json" } }
            },
            "url": {
              "raw": "{{base_url}}/v2/ads/{{platform}}/search",
              "host": [ "{{base_url}}" ],
              "path": [ "v2", "ads", "{{platform}}", "search" ]
            },
            "description": "Run page 1 first. Keep filters and sorting unchanged and reuse the exact page-one last_hit."
          },
          "response": []
        },
        {
          "name": "Mega Search page 1",
          "request": {
            "method": "POST",
            "header": [ { "key": "Content-Type", "value": "application/json" } ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"page\": 1,\n  \"advanced_order\": {\n    \"orderby\": \"newest\",\n    \"order\": \"desc\"\n  },\n  \"search_field\": [\n    { \"type\": \"text\", \"text\": \"smart ring\" }\n  ]\n}",
              "options": { "raw": { "language": "json" } }
            },
            "url": {
              "raw": "{{base_url}}/v2/ads/mega/search",
              "host": [ "{{base_url}}" ],
              "path": [ "v2", "ads", "mega", "search" ]
            },
            "description": "Mega Search aggregates supported sources. Use each result's platform and id for an individual detail request."
          },
          "response": []
        }
      ]
    },
    {
      "name": "3. Ad details",
      "item": [
        {
          "name": "Get ad details from the source platform",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{base_url}}/v2/ads/{{platform}}/{{ad_id}}",
              "host": [ "{{base_url}}" ],
              "path": [ "v2", "ads", "{{platform}}", "{{ad_id}}" ]
            },
            "description": "The platform must be an individual source, not mega."
          },
          "response": []
        }
      ]
    }
  ]
}
