{
  "name": "Remix competitor ad patterns with Videotok references",
  "nodes": [
    {
      "parameters": {
        "content": "## Competitor reference ad remixer\n\nThis workflow turns public inspiration into a brand-safe Videotok generation.\n\nImportant: use references for pacing, framing, hook structure, and style. Do not copy logos, people, claims, products, or protected brand identity.\n\nRequired variables: VIDEOTOK_API_KEY, OPENAI_API_KEY, VIDEOTOK_BRAND_KIT_ID.",
        "height": 300,
        "width": 500,
        "color": 3
      },
      "id": "note-overview",
      "name": "Overview and guardrails",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [-700, -260]
    },
    {
      "parameters": {},
      "id": "manual",
      "name": "Manual inspiration test",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [-620, 120]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "reference",
              "name": "reference_image_url",
              "type": "string",
              "value": "https://example.com/inspiration.png"
            },
            {
              "id": "product",
              "name": "product_image_url",
              "type": "string",
              "value": "https://example.com/product.png"
            },
            {
              "id": "offer",
              "name": "offer",
              "type": "string",
              "value": "A premium running shoe for city runners"
            }
          ]
        }
      },
      "id": "input",
      "name": "Replace with sheet row",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [-360, 120]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.openai.com/v1/responses",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Bearer {{$vars.OPENAI_API_KEY}}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\"model\":\"gpt-4.1-mini\",\"input\":\"Analyze this ad inspiration for reusable structure only. Return JSON with label, target_template_slug, target_template_category, generation_prompt, caption. Never copy identity. Input: \" + JSON.stringify($json)}"
      },
      "id": "analyze",
      "name": "OpenAI extracts reusable structure",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [-80, 120]
    },
    {
      "parameters": {
        "jsCode": "const source = $('Replace with sheet row').first().json;\nconst raw = $input.first().json.output_text || '{}';\nlet brief;\ntry { brief = JSON.parse(raw); } catch { brief = { label: 'Reference remix', target_template_slug: 'motion-graphics', target_template_category: 'video-templates', generation_prompt: raw }; }\nreturn [{ json: { ...brief, reference_image_url: source.reference_image_url, product_image_url: source.product_image_url } }];"
      },
      "id": "prepare-reference",
      "name": "Prepare reference target",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [200, 120]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://videotok.app/api/v1/reference-inspirations",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Bearer {{$vars.VIDEOTOK_API_KEY}}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\"template_slug\":$json.target_template_slug || \"motion-graphics\",\"template_category\":$json.target_template_category || \"video-templates\",\"media_kind\":\"image\",\"visibility\":\"private\",\"label\":$json.label,\"image_urls\":[$json.reference_image_url]}"
      },
      "id": "save-reference",
      "name": "Save Videotok reference",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [500, 120]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://videotok.app/api/v1/generations",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Bearer {{$vars.VIDEOTOK_API_KEY}}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            },
            {
              "name": "Idempotency-Key",
              "value": "=reference-remix-{{$execution.id}}"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\"type\":\"video_ad\",\"template_slug\":$('Prepare reference target').first().json.target_template_slug || \"motion-graphics\",\"prompt\":$('Prepare reference target').first().json.generation_prompt,\"aspect_ratio\":\"9:16\",\"duration\":8,\"quality_tier\":\"high\",\"brand_kit_id\":$vars.VIDEOTOK_BRAND_KIT_ID,\"reference_image_urls\":[$('Prepare reference target').first().json.product_image_url],\"custom_reference_inspiration_id\":$json.id || $json.reference_inspiration_id,\"idempotency_key\":\"reference-remix-\" + $execution.id}"
      },
      "id": "generate",
      "name": "Generate brand-safe variation",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [800, 120]
    },
    {
      "parameters": {
        "amount": 90,
        "unit": "seconds"
      },
      "id": "wait",
      "name": "Wait before polling",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [1060, 120]
    },
    {
      "parameters": {
        "url": "=https://videotok.app/api/v1/generations/{{$json.id || $json.generation_id}}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Bearer {{$vars.VIDEOTOK_API_KEY}}"
            }
          ]
        }
      },
      "id": "poll",
      "name": "Poll remix status",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [1320, 120]
    }
  ],
  "connections": {
    "Manual inspiration test": {
      "main": [
        [{ "node": "Replace with sheet row", "type": "main", "index": 0 }]
      ]
    },
    "Replace with sheet row": {
      "main": [
        [
          {
            "node": "OpenAI extracts reusable structure",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI extracts reusable structure": {
      "main": [
        [{ "node": "Prepare reference target", "type": "main", "index": 0 }]
      ]
    },
    "Prepare reference target": {
      "main": [
        [{ "node": "Save Videotok reference", "type": "main", "index": 0 }]
      ]
    },
    "Save Videotok reference": {
      "main": [
        [
          {
            "node": "Generate brand-safe variation",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate brand-safe variation": {
      "main": [[{ "node": "Wait before polling", "type": "main", "index": 0 }]]
    },
    "Wait before polling": {
      "main": [[{ "node": "Poll remix status", "type": "main", "index": 0 }]]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "tags": ["videotok", "openai", "reference inspiration", "ad research"],
  "active": false,
  "versionId": "videotok-competitor-reference-ad-remixer-1"
}
