This workflow automates SEO keyword research using:
- Google Gemini (PaLM) for keyword idea generation
- DataForSEO API for search volume and competition metrics
- A custom ranking algorithm to score and select the top 50 keywords
- Email delivery of results as a CSV attachment
- Accepts a seed keyword and recipient email via webhook
- Expands the seed into multiple related keyword ideas using Google Gemini LLM
- Cleans and formats the keywords into an array
- Queries DataForSEO for search volume, CPC, and competition index
- Ranks keywords by a custom formula:
→ high volume + high CPC + low competition rank higher
score = (search_volume * (cpc + 0.1)) / (competition_index + 1) - Selects the top 50 keywords
- Converts the results into a CSV file
- Sends the CSV report by email
graph TD
A[Webhook - Receive Seed Keyword + Email] --> B[Edit Fields - Map Input]
B --> C[Gemini LLM Chain - Generate Keyword Ideas]
C --> D[Code - Clean & Parse JSON Keywords]
D --> E[Edit Fields - Prepare for API]
E --> F[HTTP Request - DataForSEO Search Volume]
F --> G[Code - Rank, Score & Generate CSV]
G --> H[Send Email - Deliver CSV Report]
- Running n8n (Docker recommended)
- Credentials:
- Google Gemini API key (configured in n8n credentials)
- DataForSEO API credentials (Base64 encoded in HTTP header)
- SMTP credentials (for Send Email node)
- Import the workflow JSON into n8n.
- Configure credentials for:
- Google Gemini (PaLM)
- SMTP (Send Email node)
- DataForSEO → update
Authorizationheader in HTTP Request node.
- Activate the workflow.
Send a POST request to your n8n instance:
curl -X POST "http://<your-n8n-host>/webhook/keyword-research" \
-H "Content-Type: application/json" \
-d '{"seed": "best smartphones", "mailto": "[email protected]"}'- The workflow generates related keyword ideas
- Queries DataForSEO for metrics
- Ranks keywords by score
- Sends a CSV with the top 50 keywords to the provided email
keyword,search_volume,competition_index,cpc,score
best smartphone for photography,5400,22,1.12,275.72
affordable cell phone options,2900,15,0.85,154.26
premium smartphone vs budget device,1800,30,1.40,81.62
...
Different use cases require different scoring strategies. Here are the variations you can use by modifying the Code node:
score = search_volume / (competition_index + 1);- Prioritizes low competition
- Best if your site is new or has low domain authority
score = (search_volume * (cpc + 0.1)) / (competition_index + 1);- Balances traffic + CPC value
- Best for affiliate, ecommerce, or paid campaign planning
score = search_volume;- Ignores CPC and competition
- Best if you just want high traffic blog topics
score = (Math.log(search_volume + 1) * (cpc + 1)) / (competition_index + 1);- Penalizes very high difficulty more strongly
- Useful if you want steady traffic growth with realistic targets
- Add SERP analysis using SerpApi or custom scraper
- Keyword clustering for topic groups
- Integrate with Google Sheets instead of email
- Schedule automatic daily/weekly runs
- Email not attaching CSV → Ensure
attachments = datain Send Email node matches the binary property from Function node. - Unexpected socket close → Check SMTP port/SSL settings (465 = SSL/TLS, 587 = STARTTLS).
- Gemini output parse errors → Verify it returns valid JSON (use prompt to enforce JSON array output).