{
  "name": "Generate AI UGC videos with HeyGen and post to Instagram and Facebook daily",
  "nodes": [
    {
      "id": "0d005363-17ba-43e8-8046-68845d1be070",
      "name": "Code: Check HeyGen Status",
      "type": "n8n-nodes-base.code",
      "position": [
        416,
        176
      ]
    },
    {
      "id": "0912ba07-81f8-47f7-9875-9d9b9adb056c",
      "name": "Google Sheets: Log Failure",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -704,
        1072
      ]
    },
    {
      "id": "04668811-7ae7-4fa2-999c-35fa8bb58f87",
      "name": "Code: Calculate Content Index",
      "type": "n8n-nodes-base.code",
      "position": [
        -528,
        -528
      ]
    },
    {
      "id": "0387f5dd-c55f-4118-a9e5-3d4cc7e72ad1",
      "name": "Google Sheets: Get Workbook Content",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -304,
        -528
      ]
    },
    {
      "id": "6005b492-ca52-4646-a64f-9f0d5bfa50c1",
      "name": "Code: Select Today's Section",
      "type": "n8n-nodes-base.code",
      "position": [
        -80,
        -528
      ]
    },
    {
      "id": "6e44dd92-3fe6-4fd4-9d85-68989046f858",
      "name": "Code: Select Random Avatar & Combine Data",
      "type": "n8n-nodes-base.code",
      "position": [
        128,
        -528
      ]
    },
    {
      "id": "a9016ce7-dc0d-48a4-9213-620bc46ebe9f",
      "name": "Code: Parse AI Response",
      "type": "n8n-nodes-base.code",
      "position": [
        -416,
        -176
      ]
    },
    {
      "id": "9a9bafc5-9d6f-4ed6-88ff-b5e1a8d0b5cb",
      "name": "Google Sheets: Create Production Log",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -192,
        -176
      ]
    },
    {
      "id": "a436d05f-16f9-48e9-9c43-c30da42a8452",
      "name": "Google Sheets: Save HeyGen Video ID",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -288,
        176
      ]
    },
    {
      "id": "37aef713-65d0-4237-a821-2c28f301ef58",
      "name": "Google Sheets: Save Raw Video URL",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1184,
        176
      ]
    },
    {
      "id": "24eab730-94c9-41a7-93f3-f574b066e6dc",
      "name": "Google Sheets: Update Complete",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -672,
        688
      ]
    },
    {
      "id": "8bd4bfce-9c10-48cd-b6cf-d3d223796010",
      "name": "Google Sheets: Mark Posted",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        0,
        688
      ]
    },
    {
      "id": "844dcc78-47ae-4040-b270-f345929f2a12",
      "name": "Schedule: Daily 9am",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -752,
        -528
      ]
    },
    {
      "id": "c0ad64e8-51c2-44a5-9c28-da26111f6658",
      "name": "Code: Prepare HeyGen Request",
      "type": "n8n-nodes-base.code",
      "position": [
        32,
        -176
      ]
    },
    {
      "id": "1e748632-a584-47b2-b778-5e92880a9d39",
      "name": "HTTP: HeyGen Generate Video",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -720,
        176
      ]
    },
    {
      "id": "8a64e175-4ead-439f-adb2-0e3ba78f4615",
      "name": "Code: Extract HeyGen Video ID",
      "type": "n8n-nodes-base.code",
      "position": [
        -512,
        176
      ]
    },
    {
      "id": "059dc443-3d50-4a2c-83f5-c625e647ad3a",
      "name": "Wait: HeyGen Processing",
      "type": "n8n-nodes-base.wait",
      "position": [
        -48,
        176
      ]
    },
    {
      "id": "8132f8a7-37fd-4b28-b9ab-bf6b4f4dff3f",
      "name": "HTTP: Poll HeyGen Status",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        208,
        176
      ]
    },
    {
      "id": "dd47044e-c6fe-40b2-84aa-74b2e6fc7380",
      "name": "Code: Extract HeyGen Video URL",
      "type": "n8n-nodes-base.code",
      "position": [
        960,
        176
      ]
    },
    {
      "id": "d9102495-18e6-4e9c-a132-cd92de6c353f",
      "name": "Code: Set Final Video URL",
      "type": "n8n-nodes-base.code",
      "position": [
        1408,
        176
      ]
    },
    {
      "id": "2f971e89-70bd-4203-9a39-9288e0ac7121",
      "name": "facebook",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -448,
        592
      ]
    },
    {
      "id": "eb9eb797-a36c-4dcc-8567-201bd4aeb84e",
      "name": "instagram",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -448,
        768
      ]
    },
    {
      "id": "f54ea360-8c57-4c18-902d-49999821186c",
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "position": [
        -224,
        688
      ]
    },
    {
      "id": "9be10c2c-0c7b-41fd-acec-d13bc381ccc7",
      "name": "Switch",
      "type": "n8n-nodes-base.switch",
      "position": [
        704,
        160
      ]
    },
    {
      "id": "e000ac72-1068-44e4-ab0e-21fc93db491e",
      "name": "Generate Script",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        -704,
        -176
      ]
    },
    {
      "id": "82972bfd-5a43-4a3d-8dfa-060bd52eeb14",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1408,
        -656
      ],
      "parameters": {
        "width": 528,
        "height": 288,
        "content": " # Overall Workflow Overview \n  This workflow runs daily, picks a content section from Google Sheets, generates a 30-second spoken script using GPT-4.1-mini, renders a talking-head video via HeyGen, t"
      }
    },
    {
      "id": "e3e5d2d6-04db-445b-8d44-f1488b63c697",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -864,
        -656
      ],
      "parameters": {
        "width": 1168,
        "height": 288,
        "content": "## 1. Content Selection\nPicks today's content using day-of-year modulo total sections, so content rotates automatically without repeating. Only rows with Status = \"Idea\" are eligible. Add new rows to "
      }
    },
    {
      "id": "4220b5f6-01e7-4370-b5f9-a5f52d35b175",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -864,
        -336
      ],
      "parameters": {
        "width": 1184,
        "height": 320,
        "content": "## 2. Script Generation\nUses GPT-4.1-mini with \"The Shepherd\" persona. Target: 75-90 words (~30 seconds spoken). Must end with \"Visit the link in bio to learn more.\" Output is strict JSON { \"script\": "
      }
    },
    {
      "id": "d1c54f7c-1390-48da-9df2-7df43b7142a8",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -864,
        16
      ],
      "parameters": {
        "width": 2464,
        "height": 384,
        "content": "## 3. HeyGen Polling Loop\nHeyGen video generation is async. This loop polls every 50 seconds, up to 20 times (~16 min max). Switch routes to: retry (still processing), completed (extract URL), or fail"
      }
    },
    {
      "id": "d9f6b768-3bc6-4d43-94fc-10a5e25e5b12",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -864,
        448
      ],
      "parameters": {
        "width": 1232,
        "height": 480,
        "content": "## 4. Social Publishing\nPosts to Facebook and Instagram via upload-post.com API. The caption is auto-generated from the section title + first 100 chars of script + \"... Link in Bio\". Note: Facebook no"
      }
    },
    {
      "id": "1da61638-53f7-48f8-838f-d29b615bb6aa",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -864,
        976
      ],
      "parameters": {
        "width": 1216,
        "height": 304,
        "content": "## 5. Error Handling\nIf HeyGen fails or times out, the failure reason and status are written back to the Production Logs sheet. The workflow also has an error workflow configured for unexpected crashe"
      }
    }
  ],
  "connections": {
    "Merge": {
      "main": [
        [
          {
            "node": "Google Sheets: Mark Posted",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch": {
      "main": [
        [
          {
            "node": "Wait: HeyGen Processing",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Code: Extract HeyGen Video URL",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Google Sheets: Log Failure",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "facebook": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "instagram": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Generate Script": {
      "main": [
        [
          {
            "node": "Code: Parse AI Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule: Daily 9am": {
      "main": [
        [
          {
            "node": "Code: Calculate Content Index",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code: Parse AI Response": {
      "main": [
        [
          {
            "node": "Google Sheets: Create Production Log",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait: HeyGen Processing": {
      "main": [
        [
          {
            "node": "HTTP: Poll HeyGen Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP: Poll HeyGen Status": {
      "main": [
        [
          {
            "node": "Code: Check HeyGen Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code: Check HeyGen Status": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code: Set Final Video URL": {
      "main": [
        [
          {
            "node": "Google Sheets: Update Complete",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP: HeyGen Generate Video": {
      "main": [
        [
          {
            "node": "Code: Extract HeyGen Video ID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code: Prepare HeyGen Request": {
      "main": [
        [
          {
            "node": "HTTP: HeyGen Generate Video",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code: Select Today's Section": {
      "main": [
        [
          {
            "node": "Code: Select Random Avatar & Combine Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code: Calculate Content Index": {
      "main": [
        [
          {
            "node": "Google Sheets: Get Workbook Content",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code: Extract HeyGen Video ID": {
      "main": [
        [
          {
            "node": "Google Sheets: Save HeyGen Video ID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code: Extract HeyGen Video URL": {
      "main": [
        [
          {
            "node": "Google Sheets: Save Raw Video URL",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets: Update Complete": {
      "main": [
        [
          {
            "node": "facebook",
            "type": "main",
            "index": 0
          },
          {
            "node": "instagram",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets: Save Raw Video URL": {
      "main": [
        [
          {
            "node": "Code: Set Final Video URL",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets: Get Workbook Content": {
      "main": [
        [
          {
            "node": "Code: Select Today's Section",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets: Save HeyGen Video ID": {
      "main": [
        [
          {
            "node": "Wait: HeyGen Processing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets: Create Production Log": {
      "main": [
        [
          {
            "node": "Code: Prepare HeyGen Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code: Select Random Avatar & Combine Data": {
      "main": [
        [
          {
            "node": "Generate Script",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}