{
  "id": "hJFlKxwyCBMMeIxJ",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Discover and save niche web content to Google Sheets with Kagi and AI",
  "tags": [],
  "nodes": [
    {
      "id": "7e8e2d82-556c-4f64-9840-491a55af44fc",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1312,
        1952
      ],
      "parameters": {
        "width": 480,
        "height": 832,
        "content": "## Discover and save niche web content to Google Sheets with Kagi and AI\n\n### How it works\n\n1. A webhook trigger receives a request.\n2. The Kagi API token is set and a request is made to Kagi\u2019s enrich endpoint.\n3. Raw search results are extracted and split into individual items.\n4. Each item is sent to an AI agent for categorisation and scoring, then merged with metadata.\n5. The combined data is appended to a Google Sheet and a response is sent back to the webhook caller.\n\n### Setup steps\n\n- - [ ] Add your webhook URL to the service that will call this workflow.\n- - [ ] Store your Kagi API token in the workflow\u2019s credentials or set it in the \u201cSet Kagi Token\u201d node.\n- - [ ] Configure the OpenRouter chat model credentials inside the AI Agent sub\u2011node.\n- - [ ] Connect a Google Sheets credential and specify the target spreadsheet and worksheet in the \u201cAppend Row to Sheet\u201d node.\n\n### Customization\n\nAdjust the prompt in the AI Agent node to change how content is categorized or scored, and modify the sheet columns in the Merge Data code if additional fields are needed."
      },
      "typeVersion": 1
    },
    {
      "id": "36368431-9f2d-46a4-97cd-097a3928bdbf",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1872,
        2032
      ],
      "parameters": {
        "color": 7,
        "width": 992,
        "height": 304,
        "content": "## Fetch and extract Kagi results\n\nHandles the incoming webhook, sets the Kagi API token, calls Kagi enrich endpoint and extracts raw search results."
      },
      "typeVersion": 1
    },
    {
      "id": "9f37cb10-7313-43e4-b6d5-a2d4ad30cb56",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2912,
        1952
      ],
      "parameters": {
        "color": 7,
        "width": 1008,
        "height": 672,
        "content": "## AI processing and sheet write\n\nIterates over each result, uses an AI agent to categorize and score, merges data, appends it to Google Sheets, and finally responds to the webhook."
      },
      "typeVersion": 1
    },
    {
      "id": "c20a99e4-d096-4413-a19b-04c6bb0e417e",
      "name": "Respond to Webhook Request",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        3168,
        2080
      ],
      "parameters": {
        "options": {},
        "respondWith": "json",
        "responseBody": "={\n  \"status\": \"success\",\n  \"saved\": true\n}"
      },
      "typeVersion": 1
    },
    {
      "id": "44bf82c6-83aa-4ba0-af18-5f667f8f55fe",
      "name": "Merge AI Output with Metadata",
      "type": "n8n-nodes-base.code",
      "position": [
        3520,
        2240
      ],
      "parameters": {
        "jsCode": "const ai = JSON.parse($input.first().json.output);\n\nreturn [{\n  json: {\n    title: $('Loop Over Items').first().json.title,\n    url: $('Loop Over Items').first().json.url,\n    snippet: $('Loop Over Items').first().json.snippet,\n    category: ai.category || '',\n    summary: ai.summary || '',\n    usefulness_score: ai.usefulness_score || 0\n  }\n}];"
      },
      "typeVersion": 2
    },
    {
      "id": "9e2cbfcd-9aac-4879-aecd-d5649cdc21c2",
      "name": "GET Kagi Enrich Web Data",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        2480,
        2160
      ],
      "parameters": {
        "url": "https://kagi.com/api/v0/enrich/web",
        "options": {},
        "sendQuery": true,
        "sendHeaders": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "q",
              "value": "={{ $('Small Web Discovery Trigger').item.json.body.topic }}"
            }
          ]
        },
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Bot {{ $json.KagiToken }}"
            }
          ]
        }
      },
      "typeVersion": 4
    },
    {
      "id": "2e5150ff-9ba5-4166-b38a-719bf4927849",
      "name": "Small Web Discovery Trigger",
      "type": "n8n-nodes-base.webhook",
      "position": [
        1920,
        2160
      ],
      "parameters": {
        "path": "small-web-discovery",
        "options": {},
        "httpMethod": "POST",
        "responseMode": "responseNode"
      },
      "typeVersion": 1
    },
    {
      "id": "2567e590-ebc2-4368-b893-ebff2605dbec",
      "name": "Set Kagi API Token",
      "type": "n8n-nodes-base.set",
      "position": [
        2256,
        2160
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "346b65d7-0e12-49c2-a02e-9f9ad1c93583",
              "name": "KagiToken",
              "type": "string",
              "value": ""
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "468c84d2-fb99-4c61-91b5-d8d426329350",
      "name": "Extract Enrich Search Results",
      "type": "n8n-nodes-base.code",
      "position": [
        2720,
        2160
      ],
      "parameters": {
        "jsCode": "const results = $input.first().json.data || [];\n\nreturn results.map(item => {\n    return {\n      json: {\n        title: item.title || '',\n        url: item.url || '',\n        snippet: item.snippet || ''\n      }\n    };\n  });"
      },
      "typeVersion": 2
    },
    {
      "id": "2eab169c-fed9-4ab8-b0ae-85815157d748",
      "name": "AI Categorize and Score Content",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        3168,
        2240
      ],
      "parameters": {
        "text": "=Analyze the following web result and return valid JSON only.\n\nTitle: {{$json.title}}\nURL: {{$json.url}}\nSnippet: {{$json.snippet}}\n\nReturn format:\n{\n  \"category\": \"\",\n  \"summary\": \"\",\n  \"usefulness_score\": 1-10\n}",
        "options": {
          "systemMessage": "You are a research analyst specializing in niche and independent web content. Categorize and summarize the given result, and score its usefulness from 1 to 10. Return only valid JSON \u2014 no explanation, no markdown."
        },
        "promptType": "define"
      },
      "executeOnce": false,
      "typeVersion": 3.1
    },
    {
      "id": "c6676c76-3b05-4942-84db-f74f60e8f1b5",
      "name": "OpenRouter Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenRouter",
      "position": [
        3168,
        2464
      ],
      "parameters": {
        "model": "openai/gpt-oss-120b:free",
        "options": {}
      },
      "credentials": {
        "openRouterApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "961e9870-0391-4ce3-8104-18f03b6dfb35",
      "name": "Append Content Row to Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        3776,
        2240
      ],
      "parameters": {
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "",
          "cachedResultUrl": "",
          "cachedResultName": ""
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "",
          "cachedResultUrl": "",
          "cachedResultName": ""
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "ccd35be1-0585-488f-8bac-002cbbd07139",
      "name": "Loop Over Enrich Results",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        2960,
        2160
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    }
  ],
  "active": false,
  "settings": {
    "binaryMode": "separate",
    "executionOrder": "v1"
  },
  "versionId": "c9ae084d-5a70-4d9f-98b1-3ac77957da24",
  "connections": {
    "Set Kagi API Token": {
      "main": [
        [
          {
            "node": "GET Kagi Enrich Web Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenRouter Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Categorize and Score Content",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "GET Kagi Enrich Web Data": {
      "main": [
        [
          {
            "node": "Extract Enrich Search Results",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Enrich Results": {
      "main": [
        [
          {
            "node": "Respond to Webhook Request",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "AI Categorize and Score Content",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Small Web Discovery Trigger": {
      "main": [
        [
          {
            "node": "Set Kagi API Token",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Append Content Row to Sheets": {
      "main": [
        [
          {
            "node": "Loop Over Enrich Results",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Enrich Search Results": {
      "main": [
        [
          {
            "node": "Loop Over Enrich Results",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge AI Output with Metadata": {
      "main": [
        [
          {
            "node": "Append Content Row to Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Categorize and Score Content": {
      "main": [
        [
          {
            "node": "Merge AI Output with Metadata",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}