{
  "name": "Create Videotok product ads from new catalog items",
  "nodes": [
    {
      "parameters": {
        "content": "## Videotok product drop ad factory\n\nFor e-commerce teams launching new SKUs.\n\nTrigger this from Shopify, Airtable, a webhook, or a manual test payload. OpenAI writes ad angles. Videotok creates one static product ad and one short video ad.\n\nRequired variables: VIDEOTOK_API_KEY, OPENAI_API_KEY, VIDEOTOK_BRAND_KIT_ID.",
        "height": 280,
        "width": 480,
        "color": 5
      },
      "id": "note-overview",
      "name": "Overview and setup",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [-700, -240]
    },
    {
      "parameters": {},
      "id": "manual",
      "name": "Manual product test",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [-620, 120]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "title",
              "name": "product_title",
              "type": "string",
              "value": "Vitamin C serum"
            },
            {
              "id": "description",
              "name": "product_description",
              "type": "string",
              "value": "Brightening serum for dull skin with clean ingredients."
            },
            {
              "id": "image",
              "name": "product_image_url",
              "type": "string",
              "value": "https://example.com/product.png"
            }
          ]
        }
      },
      "id": "sample-product",
      "name": "Replace with product source",
      "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\":\"Write JSON for a product ad launch. Include static_prompt, video_prompt, caption, primary_claim, offer_angle. Product: \" + JSON.stringify($json)}"
      },
      "id": "openai-angles",
      "name": "OpenAI writes ad angles",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [-80, 120]
    },
    {
      "parameters": {
        "jsCode": "const product = $('Replace with product source').first().json;\nconst raw = $input.first().json.output_text || '{}';\nlet angles;\ntry { angles = JSON.parse(raw); } catch { angles = { static_prompt: raw, video_prompt: raw, caption: raw }; }\nreturn [\n  { json: { type: 'static_ad', template_slug: 'product-shoot', prompt: angles.static_prompt, aspect_ratio: '1:1', resolution: '1K', reference_image_urls: [product.product_image_url], brand_kit_id: $vars.VIDEOTOK_BRAND_KIT_ID, idempotency_key: `product-static-${$execution.id}` } },\n  { json: { type: 'video_ad', template_slug: 'viral-video-ads', prompt: angles.video_prompt, aspect_ratio: '9:16', duration: 8, quality_tier: 'high', reference_image_urls: [product.product_image_url], brand_kit_id: $vars.VIDEOTOK_BRAND_KIT_ID, idempotency_key: `product-video-${$execution.id}` } }\n];"
      },
      "id": "split-payloads",
      "name": "Create static and video payloads",
      "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": "videotok-generate",
      "name": "Create Videotok ads",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [520, 120]
    },
    {
      "parameters": {
        "amount": 90,
        "unit": "seconds"
      },
      "id": "wait",
      "name": "Wait before polling",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [780, 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 generated assets",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [1040, 120]
    }
  ],
  "connections": {
    "Manual product test": {
      "main": [
        [{ "node": "Replace with product source", "type": "main", "index": 0 }]
      ]
    },
    "Replace with product source": {
      "main": [
        [{ "node": "OpenAI writes ad angles", "type": "main", "index": 0 }]
      ]
    },
    "OpenAI writes ad angles": {
      "main": [
        [
          {
            "node": "Create static and video payloads",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create static and video payloads": {
      "main": [[{ "node": "Create Videotok ads", "type": "main", "index": 0 }]]
    },
    "Create Videotok ads": {
      "main": [[{ "node": "Wait before polling", "type": "main", "index": 0 }]]
    },
    "Wait before polling": {
      "main": [
        [{ "node": "Poll generated assets", "type": "main", "index": 0 }]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "tags": ["videotok", "openai", "ecommerce", "product ads"],
  "active": false,
  "versionId": "videotok-product-drop-ad-factory-1"
}
