{
  "name": "AutoFeed: New sheet row -> Would You Rather video -> Google Drive",
  "nodes": [
    {
      "parameters": {
        "content": "# New row -> Would You Rather video\nWhen a row is added to the sheet, this makes a Would You Rather video from its **topic**, saves the MP4 to Google Drive for review and writes the link back to the row.\n\n**Sheet columns:** `topic`, `comparisons` (optional, 1-10), `status`, `drive_url`\n\n## AutoFeed API key\n1. On AutoFeed.ai (Ultimate plan) open **Dashboard > API Keys** and create a key.\n2. In n8n create a **Header Auth** credential named `AutoFeed API key`:\n   - Name: `Authorization`\n   - Value: `Bearer af_live_...`\n3. Select it on every node that calls `www.autofeed.ai`.\n\nCost: 1,000 credits per video. Swap the Drive node for YouTube or TikTok (via your scheduler) to post directly.",
        "height": 520,
        "width": 460,
        "color": 4
      },
      "id": "0bf50a02-8fec-4499-ba4e-0d7ed4bfa9a6",
      "name": "Setup",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -520,
        -380
      ]
    },
    {
      "parameters": {
        "content": "## How the wait works\nThe create call passes `{{ $execution.resumeUrl }}` as `webhookUrl`. AutoFeed posts the finished video there and the **Wait** node resumes with it in `$json.body` (`status`, `url`, `error`).\n\nYour n8n must be reachable on public **https** (n8n Cloud is). On a local n8n, set the **Wait** node to wait 5 minutes, then add an HTTP GET to `/v1/videos/{{ id }}`, or use the AutoFeed community node with **Wait for Completion** on.\n\nA failed video is refunded automatically.",
        "height": 360,
        "width": 420,
        "color": 7
      },
      "id": "bfeeeb07-f947-4a7b-a223-59a8ba3c251d",
      "name": "Webhook note",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        740,
        -380
      ]
    },
    {
      "parameters": {
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "documentId": {
          "__rl": true,
          "mode": "url",
          "value": ""
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Sheet1"
        },
        "event": "rowAdded",
        "options": {}
      },
      "id": "f5694241-1bf9-4ccd-8d25-4b32cfd3b763",
      "name": "New row",
      "type": "n8n-nodes-base.googleSheetsTrigger",
      "typeVersion": 1,
      "position": [
        0,
        0
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://www.autofeed.ai/api/v1/videos",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({\n  type: 'would_you_rather',\n  input: {\n    topic: $json.topic,\n    numberOfComparisons: Math.min(10, Math.max(1, Number($json.comparisons) || 8)),\n    format: '9:16'\n  },\n  webhookUrl: $execution.resumeUrl,\n  idempotencyKey: 'wyr-row-' + $json.row_number\n}) }}",
        "options": {}
      },
      "id": "a51796ce-351e-4fd3-a39a-dd0d9236e486",
      "name": "Create Would You Rather",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        220,
        0
      ]
    },
    {
      "parameters": {
        "resume": "webhook",
        "httpMethod": "POST",
        "limitWaitTime": true,
        "limitType": "afterTimeInterval",
        "resumeAmount": 2,
        "resumeUnit": "hours",
        "options": {}
      },
      "id": "c9aaf7d7-b71a-4a0f-b2fe-a7b51d4af993",
      "name": "Wait for AutoFeed",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        440,
        0
      ],
      "webhookId": "c0af4e83-482e-4e4a-ac9f-9d171917efaf"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "91b470f6-f473-40d4-a420-46914f2d8e75",
              "leftValue": "={{ $json.body.status }}",
              "rightValue": "completed",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "59a8e919-d720-404e-b1b4-7a5748998a6f",
      "name": "Completed?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        660,
        0
      ]
    },
    {
      "parameters": {
        "url": "={{ $json.body.url }}",
        "options": {
          "response": {
            "response": {
              "responseFormat": "file"
            }
          }
        }
      },
      "id": "beefcdc6-a794-47c9-9c25-392ea8ad6b02",
      "name": "Download MP4",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        880,
        -100
      ]
    },
    {
      "parameters": {
        "name": "=wyr-{{ $('New row').item.json.topic.slice(0, 60) }}.mp4",
        "driveId": {
          "__rl": true,
          "mode": "list",
          "value": "My Drive"
        },
        "folderId": {
          "__rl": true,
          "mode": "list",
          "value": "root",
          "cachedResultName": "/ (Root folder)"
        },
        "options": {}
      },
      "id": "104a99b9-f330-433f-8312-2ee82316cfb5",
      "name": "Save to Google Drive",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        1100,
        -100
      ]
    },
    {
      "parameters": {
        "operation": "update",
        "documentId": {
          "__rl": true,
          "mode": "url",
          "value": ""
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Sheet1"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "row_number": "={{ $('New row').item.json.row_number }}",
            "status": "ready",
            "drive_url": "={{ $json.webViewLink }}"
          },
          "matchingColumns": [
            "row_number"
          ],
          "schema": [
            {
              "id": "row_number",
              "displayName": "row_number",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "number",
              "canBeUsedToMatch": true,
              "removed": false,
              "readOnly": true
            },
            {
              "id": "status",
              "displayName": "status",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "drive_url",
              "displayName": "drive_url",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            }
          ]
        },
        "options": {}
      },
      "id": "a400cff1-8c97-4d77-8cf6-83b827a69b89",
      "name": "Mark ready",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        1320,
        -100
      ]
    },
    {
      "parameters": {
        "operation": "update",
        "documentId": {
          "__rl": true,
          "mode": "url",
          "value": ""
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Sheet1"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "row_number": "={{ $('New row').item.json.row_number }}",
            "status": "=failed: {{ $json.body.error || 'unknown error' }} (credits refunded)"
          },
          "matchingColumns": [
            "row_number"
          ],
          "schema": [
            {
              "id": "row_number",
              "displayName": "row_number",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "number",
              "canBeUsedToMatch": true,
              "removed": false,
              "readOnly": true
            },
            {
              "id": "status",
              "displayName": "status",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            }
          ]
        },
        "options": {}
      },
      "id": "529729cc-2479-444b-8181-18ffe5df2d8e",
      "name": "Mark failed",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        880,
        120
      ]
    }
  ],
  "connections": {
    "New row": {
      "main": [
        [
          {
            "node": "Create Would You Rather",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Would You Rather": {
      "main": [
        [
          {
            "node": "Wait for AutoFeed",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait for AutoFeed": {
      "main": [
        [
          {
            "node": "Completed?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Completed?": {
      "main": [
        [
          {
            "node": "Download MP4",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Mark failed",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download MP4": {
      "main": [
        [
          {
            "node": "Save to Google Drive",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save to Google Drive": {
      "main": [
        [
          {
            "node": "Mark ready",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "meta": {
    "templateCredsSetupCompleted": false,
    "description": "Makes an AutoFeed Would You Rather video for every new Google Sheets row and saves it to Google Drive."
  },
  "pinData": {},
  "tags": []
}