n8n Web Search API Workflow Template

n8n search api workflow

HTTPS REQUEST NODE SETUP:

Method: POST

URL: https://google.serper.dev/search

Header Parameter:
Name: X-API-KEY

API Key: Paste in your API key

Send Body:

Use JSON

Expression:
{
"q": "search term"
}

Do not include ", which may conflict with syntax error unless you wrap it

Code Nodes JAVASCRIPT CODE to Copy:

Unpack OBJ (Convert organic search output OBJ to JSON):

const items = $items("SEARCHING UPC")[0].json.organic;

return items.map((entry, index) => {
return {
json: {
index: index + 1,
title: entry.title || '',
snippet: entry.snippet || '',
link: entry.link || ''
}
};
});

Consolidate Organic Data Into One Schema Item:

const items = $input.all();

const formattedText = [];
const links = [];

for (const item of items) {
const { title, snippet, link } = item.json;

if (title || snippet) {
formattedText.push(`Title: ${title || 'N/A'}\nSnippet: ${snippet || 'N/A'}`);
}

if (link) {
links.push(link);
}
}

return [
{
json: {
searchSummary: formattedText.join('\n\n'),
combinedLinks: links.join('\n')
}
}
];

Scroll to Top