{
  "name": "Automate TikTok trend videos with Videotok",
  "nodes": [
    {
      "parameters": {
        "content": "## Automate TikTok trend videos with Videotok\n\n### How it works\n\n1. Manually trigger the workflow to start the TikTok trend video creation process.\n2. Set the TikTok trend source details including trend topic, brand context, and audience.\n3. Use OpenAI to generate a script based on the trend source details.\n4. Build the payload for the Videotok API to create a video.\n5. Post the payload to the Videotok API and wait for 90 seconds before checking.\n6. Fetch and check the status of the created video from the Videotok API.\n\n### Setup steps\n\n- [ ] Ensure OpenAI API key is configured for script generation\n- [ ] Ensure Videotok API access is set up for video creation\n\n### Customization\n\nDifferent TikTok trends or brand contexts can be set in the 'Set TikTok Trend Source' node to generate various types of videos.",
        "width": 480,
        "height": 752
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [-1232, -32],
      "id": "eb69672b-8cf7-4c74-b2d8-59d6fb840288",
      "name": "Sticky Note"
    },
    {
      "parameters": {
        "content": "## Trigger and set trend source\n\nTrigger manually and set TikTok trend source details like trend topic, brand, and audience. Make a POST request to OpenAI to obtain a script based on the trend source.",
        "width": 736,
        "height": 320,
        "color": 7
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [-672, -32],
      "id": "fc6863bf-82d9-4bbf-b062-c90a36ea5c2e",
      "name": "Sticky Note1"
    },
    {
      "parameters": {
        "content": "## Prepare and send Videotok payload\n\nBuild the payload using custom code and send it to Videotok API to create a video.",
        "width": 1008,
        "height": 272,
        "color": 7
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [160, 16],
      "id": "02e2e3d5-5064-4a27-ade0-956c065ad596",
      "name": "Sticky Note2"
    },
    {
      "parameters": {},
      "id": "manual",
      "name": "Manual TikTok Idea Trigger",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [-624, 128]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "topic",
              "name": "trend_topic",
              "type": "string",
              "value": "A new TikTok trend about tiny daily productivity systems"
            },
            {
              "id": "brand",
              "name": "brand_context",
              "type": "string",
              "value": "A SaaS brand helping creators automate social media production"
            },
            {
              "id": "audience",
              "name": "audience",
              "type": "string",
              "value": "Social media managers and founders"
            }
          ]
        }
      },
      "id": "trend-source",
      "name": "Set Trend Source Data",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [-352, 128]
    },
    {
      "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 a TikTok-native video brief. Return strict JSON with title, hook, script, visual_prompt, caption, hashtags. Input: \" + JSON.stringify($json)}"
      },
      "id": "openai-script",
      "name": "Submit to OpenAI for Script",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [-80, 128]
    },
    {
      "parameters": {
        "jsCode": "const raw = $input.first().json.output_text || $input.first().json.output?.[0]?.content?.[0]?.text || '{}';\nlet brief;\ntry { brief = JSON.parse(raw); } catch { brief = { title: 'TikTok trend video', hook: raw.slice(0, 120), script: raw, visual_prompt: raw, caption: raw.slice(0, 220), hashtags: '#tiktok #socialmedia #videotok' }; }\nreturn [{ json: { ...brief, idempotency_key: `tiktok-trend-${$execution.id}` } }];"
      },
      "id": "prepare-payload",
      "name": "Create Videotok Payload",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [208, 128]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://videotok.app/api/v1/faceless-videos",
        "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": "={\"title\":$json.title,\"prompt\":$json.visual_prompt,\"script\":$json.script,\"aspect_ratio\":\"9:16\",\"duration\":\"26\",\"language\":\"en\",\"voice_id\":$vars.VIDEOTOK_VOICE_ID || \"ash\",\"brand_kit_id\":$vars.VIDEOTOK_BRAND_KIT_ID}"
      },
      "id": "create-video",
      "name": "Send to Videotok API",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [496, 128]
    },
    {
      "parameters": {
        "amount": 90,
        "unit": "seconds"
      },
      "id": "wait",
      "name": "Wait for Video Creation",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [768, 128]
    },
    {
      "parameters": {
        "url": "=https://videotok.app/api/v1/videos/{{$json.video_id || $json.id}}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Bearer {{$vars.VIDEOTOK_API_KEY}}"
            }
          ]
        }
      },
      "id": "poll-video",
      "name": "Check Videotok Video Status",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [1024, 128]
    }
  ],
  "connections": {
    "Manual TikTok Idea Trigger": {
      "main": [
        [
          {
            "node": "Set Trend Source Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Trend Source Data": {
      "main": [
        [
          {
            "node": "Submit to OpenAI for Script",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Submit to OpenAI for Script": {
      "main": [
        [
          {
            "node": "Create Videotok Payload",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Videotok Payload": {
      "main": [
        [
          {
            "node": "Send to Videotok API",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send to Videotok API": {
      "main": [
        [
          {
            "node": "Wait for Video Creation",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait for Video Creation": {
      "main": [
        [
          {
            "node": "Check Videotok Video Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "tags": ["videotok", "openai", "tiktok", "short-form video"],
  "active": false,
  "versionId": "videotok-tiktok-trend-video-machine-1"
}
