{
  "openapi": "3.0.1",
  "info": {
    "title": "TikTok Ad Library Scraper — Ads, Targeting & Spend",
    "description": "Extract ad creatives, targeting data, and spend estimates from TikTok Ad Library. Search ads by keyword, discover advertisers, and track commercial content across 33 EU/EEA regions.",
    "version": "0.3",
    "x-build-id": "K6b4TlVI47SxdMVrI"
  },
  "servers": [
    {
      "url": "https://api.apify.com/v2"
    }
  ],
  "paths": {
    "/acts/rastriq~tiktok-ad-library-scraper/run-sync-get-dataset-items": {
      "post": {
        "operationId": "run-sync-get-dataset-items-rastriq-tiktok-ad-library-scraper",
        "x-openai-isConsequential": false,
        "summary": "Executes an Actor, waits for its completion, and returns Actor's dataset items in response.",
        "tags": [
          "Run Actor"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/inputSchema"
              }
            }
          }
        },
        "parameters": [
          {
            "name": "token",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Enter your Apify token here"
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/acts/rastriq~tiktok-ad-library-scraper/runs": {
      "post": {
        "operationId": "runs-sync-rastriq-tiktok-ad-library-scraper",
        "x-openai-isConsequential": false,
        "summary": "Executes an Actor and returns information about the initiated run in response.",
        "tags": [
          "Run Actor"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/inputSchema"
              }
            }
          }
        },
        "parameters": [
          {
            "name": "token",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Enter your Apify token here"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/runsResponseSchema"
                }
              }
            }
          }
        }
      }
    },
    "/acts/rastriq~tiktok-ad-library-scraper/run-sync": {
      "post": {
        "operationId": "run-sync-rastriq-tiktok-ad-library-scraper",
        "x-openai-isConsequential": false,
        "summary": "Executes an Actor, waits for completion, and returns the OUTPUT from Key-value store in response.",
        "tags": [
          "Run Actor"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/inputSchema"
              }
            }
          }
        },
        "parameters": [
          {
            "name": "token",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Enter your Apify token here"
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "inputSchema": {
        "type": "object",
        "properties": {
          "startUrl": {
            "title": "🔗 TikTok Ad Library URL",
            "type": "string",
            "description": "Paste a URL from <a href='https://library.tiktok.com/ads' target='_blank'>TikTok Ad Library</a> and the actor will extract all search parameters automatically.<br><br><b>How to get a URL:</b><br>1. Go to <a href='https://library.tiktok.com/ads' target='_blank'>library.tiktok.com/ads</a><br>2. Set your filters (region, keyword, dates…)<br>3. Copy the URL from your browser<br><br><b>Valid URL example:</b><br><code>https://library.tiktok.com/ads?region=DE&query_type=1</code><br><br><b>❌ Invalid URLs (these won't work):</b><br>• <code>https://www.tiktok.com/@username</code> — this is a TikTok profile, not the Ad Library<br>• <code>https://ads.tiktok.com/...</code> — this is TikTok Ads Manager, not the public Ad Library<br><br>⚠️ <b>If you paste a URL here, all manual fields below (query, region, dates…) are ignored.</b>"
          },
          "mode": {
            "title": "🎯 Scraping mode",
            "enum": [
              "search_ads",
              "discover_advertisers",
              "search_commercial_content"
            ],
            "type": "string",
            "description": "Choose what to scrape:<br>• <b>Search Ads</b> — search paid ads by keyword or advertiser name. Use the fields below to set query, region, and dates.<br>• <b>Discover Advertisers</b> — find all advertisers via TikTok's suggestion API. Only uses <b>Max results</b> and <b>Discovery prefixes</b>.<br>• <b>Commercial Content</b> — search branded/organic promotional content by keyword.",
            "default": "search_ads"
          },
          "searchQuery": {
            "title": "🔍 Search query",
            "type": "string",
            "description": "Type a keyword or an advertiser name to search for.<br><br><b>Examples:</b><br>• <code>running shoes</code> — finds ads mentioning 'running shoes'<br>• <code>Nike</code> — finds ads from or mentioning Nike<br>• Leave empty to browse <b>all ads</b> in the selected region (no keyword filter).<br><br>⚡ <i>Ignored if a URL is provided above.</i>"
          },
          "queryType": {
            "title": "📝 Query type",
            "enum": [
              "keyword",
              "advertiser"
            ],
            "type": "string",
            "description": "How to interpret the search query above:<br>• <b>Keyword</b>: searches in ad text, titles, and descriptions<br>• <b>Advertiser name</b>: finds the advertiser's business ID automatically and returns all their ads<br><br>💡 <b>Example:</b> To find all Nike ads, type <code>Nike</code> above and select <b>Advertiser name</b>.<br><br>⚡ <i>Ignored if a URL is provided above.</i>",
            "default": "keyword"
          },
          "region": {
            "title": "🌍 Region",
            "enum": [
              "all",
              "AT",
              "BE",
              "BG",
              "CH",
              "CY",
              "CZ",
              "DE",
              "DK",
              "EE",
              "ES",
              "FI",
              "FR",
              "GB",
              "GR",
              "HR",
              "HU",
              "IE",
              "IS",
              "IT",
              "LI",
              "LT",
              "LU",
              "LV",
              "MT",
              "NL",
              "NO",
              "PL",
              "PT",
              "RO",
              "SE",
              "SI",
              "SK",
              "TR"
            ],
            "type": "string",
            "description": "Filter ads shown in a specific country.<br>Select <b>All regions</b> to search across all 33 EU/EEA countries at once.<br><br>⚡ <i>Ignored if a URL is provided above.</i>",
            "default": "all"
          },
          "maxResults": {
            "title": "💯 Max results",
            "minimum": 1,
            "maximum": 10000,
            "type": "integer",
            "description": "Maximum number of results to return.<br><br><b>Recommended starting points:</b><br>• <code>20</code> — quick test (~30 seconds, ~$0.02)<br>• <code>100</code> — standard run (~2 min, ~$0.09)<br>• <code>1000</code> — large dataset (~15 min, ~$0.90)<br><br>⚠️ TikTok limits each search to ~3,600 ads (300 pages × 12 results per page).",
            "default": 100
          },
          "startDate": {
            "title": "📅 Start date",
            "type": "string",
            "description": "Only show ads first displayed <b>after</b> this date.<br><br><b>Accepts:</b><br>• Relative: <code>7 days</code>, <code>30 days</code>, <code>90 days</code><br>• Absolute: <code>2025-01-15</code> (YYYY-MM-DD format)<br><br>Default: 31 days ago.<br><br>⚡ <i>Ignored if a URL is provided above.</i>"
          },
          "endDate": {
            "title": "📅 End date",
            "type": "string",
            "description": "Only show ads last displayed <b>before</b> this date.<br><br><b>Accepts:</b><br>• Relative: <code>0 days</code> (today), <code>7 days</code> (a week ago)<br>• Absolute: <code>2025-06-30</code> (YYYY-MM-DD format)<br><br>Default: today.<br><br>⚡ <i>Ignored if a URL is provided above.</i>"
          },
          "includeDetails": {
            "title": "📊 Include ad details (targeting & spend)",
            "type": "boolean",
            "description": "Fetch full details for each ad: advertiser info, targeting by location/age/gender, audience size, and sponsor data.<br><br>⚠️ <b>Impact:</b> Makes 1 extra API request per ad. A run with 100 ads takes ~2× longer with this enabled.<br>• <b>OFF</b> = fast, basic ad data (title, image, video URL, dates)<br>• <b>ON</b> = rich competitive analysis (targeting, demographics, reach estimates)",
            "default": false
          },
          "sortBy": {
            "title": "📊 Sort by",
            "enum": [
              "last_shown_date,desc",
              "last_shown_date,asc",
              "first_shown_date,desc",
              "first_shown_date,asc"
            ],
            "type": "string",
            "description": "Sort order for search results.<br><br>💡 Use <b>Last shown (newest)</b> to find currently active ads, or <b>First shown (oldest)</b> to find long-running campaigns.",
            "default": "last_shown_date,desc"
          },
          "adIds": {
            "title": "🆔 Ad IDs (direct lookup)",
            "type": "string",
            "description": "Skip the search and fetch specific ads directly by their IDs.<br><br><b>Format:</b> Comma-separated IDs, one or more.<br><b>Example:</b><br><code>1848459287600130, 1820197122833570</code><br><br><b>Where to find Ad IDs:</b><br>• In the results of a previous run (the <code>id</code> field)<br>• In TikTok Ad Library URLs: <code>library.tiktok.com/ads/detail/?id=<b>1848459287600130</b></code><br><br>⚠️ When ad IDs are provided, <b>all other search parameters are ignored</b> (query, region, dates, mode)."
          },
          "advertiserIds": {
            "title": "🏢 Advertiser business IDs",
            "type": "string",
            "description": "Fetch all ads from specific advertisers by their business IDs.<br><br><b>Format:</b> Comma-separated IDs.<br><b>Example:</b> <code>7281934526183, 6928345120947</code><br><br><b>Where to find Advertiser IDs:</b><br>• Run this actor in <b>Discover Advertisers</b> mode first<br>• Or copy from a TikTok Ad Library URL: <code>...&adv_biz_ids=<b>7281934526183</b></code><br><br>⚡ <i>Ignored if a URL is provided above.</i>"
          },
          "discoveryPrefixes": {
            "title": "🔤 Discovery prefixes",
            "type": "string",
            "description": "Only used in <b>🏢 Discover Advertisers</b> mode. Ignored in other modes.<br><br>Comma-separated text prefixes to search for advertiser names.<br><br><b>Examples:</b><br>• <code>nike, adidas, puma</code> — find advertisers starting with these brands<br>• <code>a, b, c</code> — alphabetical discovery<br>• Leave empty → searches full alphabet A–Z + digits 0–9 (comprehensive but slower)"
          },
          "proxyConfiguration": {
            "title": "🔒 Proxy configuration",
            "type": "object",
            "description": "TikTok's Ad Library requires <b>residential proxies</b> to avoid HTTP 421 'system busy' rejections.<br><br>The default configuration uses Apify's residential proxy pool, which works reliably. Datacenter proxies are usually blocked by TikTok's anti-bot fingerprinting."
          },
          "requestDelay": {
            "title": "⏱️ Delay between requests",
            "minimum": 0,
            "maximum": 10000,
            "type": "integer",
            "description": "Milliseconds to wait between API requests.<br><br><b>Recommended values:</b><br>• <code>500</code> — default, works for most runs<br>• <code>1000–2000</code> — use if you get rate-limited (HTTP 429 errors)<br>• <code>0</code> — fastest, but higher chance of rate limiting",
            "default": 500
          }
        }
      },
      "runsResponseSchema": {
        "type": "object",
        "properties": {
          "data": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string"
              },
              "actId": {
                "type": "string"
              },
              "userId": {
                "type": "string"
              },
              "startedAt": {
                "type": "string",
                "format": "date-time",
                "example": "2025-01-08T00:00:00.000Z"
              },
              "finishedAt": {
                "type": "string",
                "format": "date-time",
                "example": "2025-01-08T00:00:00.000Z"
              },
              "status": {
                "type": "string",
                "example": "READY"
              },
              "meta": {
                "type": "object",
                "properties": {
                  "origin": {
                    "type": "string",
                    "example": "API"
                  },
                  "userAgent": {
                    "type": "string"
                  }
                }
              },
              "stats": {
                "type": "object",
                "properties": {
                  "inputBodyLen": {
                    "type": "integer",
                    "example": 2000
                  },
                  "rebootCount": {
                    "type": "integer",
                    "example": 0
                  },
                  "restartCount": {
                    "type": "integer",
                    "example": 0
                  },
                  "resurrectCount": {
                    "type": "integer",
                    "example": 0
                  },
                  "computeUnits": {
                    "type": "integer",
                    "example": 0
                  }
                }
              },
              "options": {
                "type": "object",
                "properties": {
                  "build": {
                    "type": "string",
                    "example": "latest"
                  },
                  "timeoutSecs": {
                    "type": "integer",
                    "example": 300
                  },
                  "memoryMbytes": {
                    "type": "integer",
                    "example": 1024
                  },
                  "diskMbytes": {
                    "type": "integer",
                    "example": 2048
                  }
                }
              },
              "buildId": {
                "type": "string"
              },
              "defaultKeyValueStoreId": {
                "type": "string"
              },
              "defaultDatasetId": {
                "type": "string"
              },
              "defaultRequestQueueId": {
                "type": "string"
              },
              "buildNumber": {
                "type": "string",
                "example": "1.0.0"
              },
              "containerUrl": {
                "type": "string"
              },
              "usage": {
                "type": "object",
                "properties": {
                  "ACTOR_COMPUTE_UNITS": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATASET_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATASET_WRITES": {
                    "type": "integer",
                    "example": 0
                  },
                  "KEY_VALUE_STORE_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "KEY_VALUE_STORE_WRITES": {
                    "type": "integer",
                    "example": 1
                  },
                  "KEY_VALUE_STORE_LISTS": {
                    "type": "integer",
                    "example": 0
                  },
                  "REQUEST_QUEUE_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "REQUEST_QUEUE_WRITES": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATA_TRANSFER_INTERNAL_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATA_TRANSFER_EXTERNAL_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "PROXY_SERPS": {
                    "type": "integer",
                    "example": 0
                  }
                }
              },
              "usageTotalUsd": {
                "type": "number",
                "example": 0.00005
              },
              "usageUsd": {
                "type": "object",
                "properties": {
                  "ACTOR_COMPUTE_UNITS": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATASET_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATASET_WRITES": {
                    "type": "integer",
                    "example": 0
                  },
                  "KEY_VALUE_STORE_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "KEY_VALUE_STORE_WRITES": {
                    "type": "number",
                    "example": 0.00005
                  },
                  "KEY_VALUE_STORE_LISTS": {
                    "type": "integer",
                    "example": 0
                  },
                  "REQUEST_QUEUE_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "REQUEST_QUEUE_WRITES": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATA_TRANSFER_INTERNAL_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATA_TRANSFER_EXTERNAL_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "PROXY_SERPS": {
                    "type": "integer",
                    "example": 0
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}