{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "f0738de4-22b6-48eb-a037-727ecb52b682",
      "name": "Manual Trigger",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        260,
        600
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "556149ce-60ab-4188-9c12-06d5ce5846e7",
      "name": "Fetch Keyword List (Google Sheets)",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        500,
        600
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/12GNwRDjdfyDvGbC3Vqiy7lIVdQJcPz3D42xpUOUVpbc/edit#gid=0",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "12GNwRDjdfyDvGbC3Vqiy7lIVdQJcPz3D42xpUOUVpbc",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/12GNwRDjdfyDvGbC3Vqiy7lIVdQJcPz3D42xpUOUVpbc/edit?usp=drivesdk",
          "cachedResultName": "article by keyword"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.5
    },
    {
      "id": "3bc6997f-a6ba-4e23-8c3a-19f2eff35354",
      "name": "Select Keyword of the Day",
      "type": "n8n-nodes-base.code",
      "position": [
        740,
        600
      ],
      "parameters": {
        "jsCode": "const rows = items; // allrows from Google Sheet\n\n// Count the days since July 5, 2025\nconst startDate = new Date(\"2025-07-04\");\nconst today = new Date();\nconst dayDiff = Math.floor((today - startDate) / (1000 * 60 * 60 * 24));\n\n// Calculate today's keyword index\nconst index = dayDiff % rows.length;\nconst selectedKeyword = rows[index].json.Title || rows[index].json.Keyword || \"Unknown\";\n\nreturn [\n  {\n    json: {\n      index,\n      keyword: selectedKeyword,\n      date: today.toISOString()\n    }\n  }\n];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "9458a3a7-a748-429b-8388-bfe9c6df111c",
      "name": "Set Selected Keyword",
      "type": "n8n-nodes-base.set",
      "position": [
        1000,
        600
      ],
      "parameters": {
        "values": {
          "string": [
            {
              "name": "seed_keyword",
              "value": "={{ $json.keyword }}"
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 2
    },
    {
      "id": "bcf65001-8156-4c75-aebb-f58a7ea556e5",
      "name": "Fetch Autocomplete Suggestions (Google Suggest API)",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1260,
        600
      ],
      "parameters": {
        "url": "https://suggestqueries.google.com/complete/search",
        "options": {},
        "queryParametersUi": {
          "parameter": [
            {
              "name": "client",
              "value": "firefox"
            },
            {
              "name": "q",
              "value": "={{$json.keyword}}"
            }
          ]
        }
      },
      "typeVersion": 2
    },
    {
      "id": "16332f94-ad54-4c87-9a43-f4c9afd68a21",
      "name": "Extract Suggestion Keywords",
      "type": "n8n-nodes-base.function",
      "position": [
        520,
        840
      ],
      "parameters": {
        "functionCode": "if (Array.isArray($json) && Array.isArray($json[1])) {\n  const suggestions = $json[1];\n  return suggestions.map(k => ({ json: { keyword: k } }));\n} else {\n  throw new Error(\"Unexpected response format from Google Suggest API\");\n}"
      },
      "typeVersion": 1
    },
    {
      "id": "03299970-288c-461a-82e2-dd5216bb5beb",
      "name": "Search Keywords (Google Custom Search API)",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        780,
        840
      ],
      "parameters": {
        "url": "https://www.googleapis.com/customsearch/v1",
        "options": {},
        "sendQuery": true,
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBasicAuth",
        "queryParameters": {
          "parameters": [
            {
              "name": "q",
              "value": "={{ $json.keyword }}"
            }
          ]
        }
      },
      "credentials": {
        "httpBasicAuth": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "e8263f69-97e2-4d8a-aa8c-a30a9abfbf9a",
      "name": "Format Search Results",
      "type": "n8n-nodes-base.code",
      "position": [
        1040,
        840
      ],
      "parameters": {
        "jsCode": "const results = $json.items || [];\nreturn results.map(item => ({\n  json: {\n    title: item.title,\n    link: item.link,\n    snippet: item.snippet\n  }\n}));\n"
      },
      "typeVersion": 2
    },
    {
      "id": "e4d2fcf8-0c39-4c3b-a282-a998d76def16",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -700,
        -60
      ],
      "parameters": {
        "width": 720,
        "height": 1640,
        "content": "## \ud83d\udcd2 Keyword Research Automation with Google Sheets, Suggest API, and Custom Search\n\n## Who's it for\n\nThis workflow is perfect for SEO specialists, marketers, bloggers, and content creators who want to automate keyword research using Google Sheets, Google Suggest, and Google Custom Search. Ideal for those building content pipelines, researching trends, or powering AI content generation with fresh search data.\n\n\n## What it does\n\nThis workflow automates the process of discovering a new keyword daily. It:\n\n- Rotates through a keyword list in Google Sheets\n- Selects one keyword per day\n- Fetches autocomplete suggestions from Google Suggest\n- Queries the Google Custom Search API for top results\n- Returns structured JSON containing titles, links, and snippets\n\n\n## How it works\n\n1. Manual Trigger \u2013 Initiates workflow manually\n2. Google Sheets \u2013 Reads keywords from a sheet (column: Title or Keyword)\n3. Code Node \u2013 Selects a daily keyword based on the number of days since July 4, 2025\n4. Set Node \u2013 Saves the selected keyword as seed_keyword\n5. HTTP Request \u2013 Fetches autocomplete suggestions from Google Suggest API\n6. Function Node \u2013 Parses suggestions into usable items\n7. HTTP Request \u2013 Calls Google Custom Search API for each suggestion\n8. Code Node \u2013 Formats the search results into JSON\n\n\n## How to set up\n\n- Connect your Google Sheets OAuth2 credentials in n8n\n- Use credential variables for Google Custom Search (\u26a0\ufe0f do not hardcode your key and cx)\n- Replace the sample sheet ID with your own\n- Run the workflow manually or schedule it daily\n\n\n## Requirements\n\n- Google account\n- Enabled Custom Search JSON API on Google Cloud\n- Google Sheet with a column labeled Title or Keyword\n- n8n instance (cloud or self-hosted)\n\n\n## How to customize\n\n- Change the start date to control the keyword rotation cycle\n- Randomize keyword selection instead of rotating\n- Enrich results using tools like Ahrefs or SEMrush\n- Push final output to Telegram, Notion, Slack, or Airtable\n- Add filtering logic based on CPC, volume, or duplicates\n\n\n## Example Sheet\n\n\ud83d\udcc4 [Click Here](https://docs.google.com/spreadsheets/d/12GNwRDjdfyDvGbC3Vqiy7lIVdQJcPz3D42xpUOUVpbc/edit?usp=sharing) to access the example Google Sheet\n\nSheet must contain a column Title or Keyword in the first row:\n\nTitle\n\n - teknologi AI\n\n - berita viral\n\n - tren startup\n"
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "Manual Trigger": {
      "main": [
        [
          {
            "node": "Fetch Keyword List (Google Sheets)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Selected Keyword": {
      "main": [
        [
          {
            "node": "Fetch Autocomplete Suggestions (Google Suggest API)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Select Keyword of the Day": {
      "main": [
        [
          {
            "node": "Set Selected Keyword",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Suggestion Keywords": {
      "main": [
        [
          {
            "node": "Search Keywords (Google Custom Search API)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Keyword List (Google Sheets)": {
      "main": [
        [
          {
            "node": "Select Keyword of the Day",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Search Keywords (Google Custom Search API)": {
      "main": [
        [
          {
            "node": "Format Search Results",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Autocomplete Suggestions (Google Suggest API)": {
      "main": [
        [
          {
            "node": "Extract Suggestion Keywords",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}