{
  "name": "Generate brand ad campaign variants with Videotok",
  "nodes": [
    {
      "parameters": {
        "content": "## Brand ad campaign variant factory\n\nCreates multiple on-brand static and video ad variants from one campaign brief.\n\nUse it for agencies, brand teams, launch campaigns, or paid social creative testing.\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 setup",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [-700, -260]
    },
    {
      "parameters": {},
      "id": "manual",
      "name": "Manual campaign brief test",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [-620, 120]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "brand",
              "name": "brand_name",
              "type": "string",
              "value": "Northstar"
            },
            {
              "id": "brief",
              "name": "campaign_brief",
              "type": "string",
              "value": "Launch campaign for an AI tool that helps teams produce social ads faster"
            },
            {
              "id": "image",
              "name": "hero_image_url",
              "type": "string",
              "value": "https://example.com/brand-hero.png"
            }
          ]
        }
      },
      "id": "campaign-source",
      "name": "Replace with campaign brief",
      "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\":\"Create paid social ad variant JSON for a brand campaign. Return an array called variants with angle, format, prompt, caption. Include 4 variants. Input: \" + JSON.stringify($json)}"
      },
      "id": "openai-variants",
      "name": "OpenAI writes ad variants",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [-80, 120]
    },
    {
      "parameters": {
        "jsCode": "const source = $('Replace with campaign brief').first().json;\nconst raw = $input.first().json.output_text || '{}';\nlet parsed;\ntry { parsed = JSON.parse(raw); } catch { parsed = { variants: [{ angle: 'Launch', format: 'video', prompt: raw, caption: raw }] }; }\nconst variants = Array.isArray(parsed.variants) ? parsed.variants : [];\nreturn variants.map((variant, index) => ({ json: { type: variant.format === 'static' ? 'static_ad' : 'video_ad', template_slug: variant.format === 'static' ? 'product-shoot' : 'viral-video-ads', prompt: variant.prompt, aspect_ratio: '9:16', duration: 8, quality_tier: 'high', reference_image_urls: [source.hero_image_url], brand_kit_id: $vars.VIDEOTOK_BRAND_KIT_ID, idempotency_key: `brand-campaign-${index}-${$execution.id}` } }));"
      },
      "id": "prepare-variants",
      "name": "Prepare Videotok variants",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [220, 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": "={{$json.idempotency_key}}"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{$json}}"
      },
      "id": "create-variants",
      "name": "Create Videotok ad variants",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [540, 120]
    }
  ],
  "connections": {
    "Manual campaign brief test": {
      "main": [
        [{ "node": "Replace with campaign brief", "type": "main", "index": 0 }]
      ]
    },
    "Replace with campaign brief": {
      "main": [
        [{ "node": "OpenAI writes ad variants", "type": "main", "index": 0 }]
      ]
    },
    "OpenAI writes ad variants": {
      "main": [
        [{ "node": "Prepare Videotok variants", "type": "main", "index": 0 }]
      ]
    },
    "Prepare Videotok variants": {
      "main": [
        [{ "node": "Create Videotok ad variants", "type": "main", "index": 0 }]
      ]
    }
  },
  "pinData": {},
  "settings": { "executionOrder": "v1" },
  "tags": ["videotok", "openai", "brand ads", "campaign variants"],
  "active": false,
  "versionId": "videotok-brand-ad-campaign-variant-factory-1"
}
