AI Agent to chat with you Search Console Data, using OpenAI and Postgres n8n Workflow Template

n8n workflow template · 16 nodes · Postgres

AI Agent to chat with you Search Console Data, using OpenAI and Postgres is a free n8n workflow template that starts when its webhook receives an HTTP request and works with Postgres and OpenAI. It has 16 nodes, 4 of them AI nodes (Postgres Chat Memory, OpenAI Chat Model, Call n8n Workflow Tool and AI Agent). The notes inside the workflow say: “This node is triggered when the AI Agent needs to retrieve the website_list (accessible Search Console properties) or custom_insights based on user data.” To run it, you add your own credentials for Generic OAuth2, HTTP Basic Auth, OpenAI API and Postgres.

At a glance

Trigger
Webhook (Webhook - ChatInput)
Nodes
16
Apps
Postgres and OpenAI
AI nodes
4
Credentials
4 types
Category
Spreadsheets, databases and docs

Apps and integrations

  • Postgres
  • OpenAI

Node types used

  • Postgres Chat Memory
  • OpenAI Chat Model
  • Edit Fields (Set)
  • Webhook
  • Respond to Webhook
  • Call n8n Workflow Tool
  • Execute Workflow Trigger
  • Switch
  • HTTP Request
  • Aggregate
  • AI Agent

How it works

The text below comes from the sticky notes inside the workflow. We removed links, code samples and anything that looks like a key or token.

Tool Call Trigger

This node is triggered when the AI Agent needs to retrieve the website_list (accessible Search Console properties) or custom_insights based on user data.

Webhook - ChatInput

This webhook serves as the endpoint for receiving ChatInput data. Ensure that you include

  • chatInput – the content you wish to send
  • sessionId – a unique identifier for the session

If you're using an interface such as Open WebUI, the sessionId will be generated automatically.

Set fields

This node sets three fields

  • chatInput: retrieved from the previous webhook node
  • sessionId: retrieved from the previous webhook node
  • date_message: formatted within this node. This will be used later to help the AI agent determine the date range for retrieving Search Console data.

Search Console - Get Custom Insights

This node performs the API call to retrieve data from Search Console.

Search Console - Get List of Properties

This node performs the API call to retrieve the list of accessible properties from Search Console.

AI Agent Sub-node - Call Search Console Tool

This tool is used by the AI Agent to

  • Retrieve the list of accessible properties in Search Console
  • Fetch Search Console data based on the user’s natural language request

Array Aggregation - Response to AI Agent

These nodes aggregate the array from the previous step and send it back to the AI Agent through the field named output as response.

Setup notes

The text below comes from the sticky notes inside the workflow. We removed links, code samples and anything that looks like a key or token.

AI Agent to Chat with Your Search Console Data

This AI Agent enables you to interact with your Search Console data through a chat interface. Each node is documented within the template, providing sufficient information for setup and usage. You will also need to configure Search Console OAuth credentials.

Follow this n8n documentation to set up the OAuth credentials.

Important Notes

Correctly Configure Scopes for Search Console API Calls

  • It’s essential to configure the scopes correctly in your Google Search Console API OAuth2 credentials. Incorrect configuration can cause issues with the refresh token, requiring frequent reconnections. Below is the configuration I use to avoid constant re-authentication

Of course, you'll need to add your client_id and client_secret from the Google Cloud Platform app you created to access your Search Console data.

Configure Authentication for the Webhook

Since the webhook will be publicly accessible, don’t forget to set up authentication. I’ve used Basic Auth, but feel free to choose the method that best meets your security requirements.

Example of awesome things you can do with this AI Agent

Set Fields - Construct API Call

This node configures fields based on the JSON sent by the AI agent

  • The request_type field determines the route: website_list (to retrieve the list of websites) or custom_insights (to get insights from Search Console)
  • Additional fields are set to construct the API call, following the Search Console API Documentation

AI Agent Sub-node - OpenAI Chat Model

This sub-node utilizes the selected OpenAI Chat Model. You can replace it with any LLM that supports tool calling.

Choose Your Model

In this template, the default model is gpt-4o, a costly option. If you'd like a more affordable alternative, select gpt4-o-mini, though note that responses may occasionally be of slightly lower quality compared to gpt-4o.

AI Agent - Tools Agent

This AI Agent is configured with a system prompt that instructs it to

  • On the first user message, retrieve available Search Console properties and offer the user the option to fetch data from these properties
  • Based on the user’s natural language input, construct an API call to the selected Search Console property and retrieve the requested data
  • Present the data in a markdown-formatted table

The AI Agent has a friendly tone and is designed to confirm the user’s data requirements accurately before executing any API requests.

AI Agent Sub-node - Postgres Chat Memory

Connect your Postgres credentials and specify a table name to store the chat history. In this template, the default table name is insights_chat_histories, and the context window length is set to 5.

Tip: If you don’t have a Postgres database, you can quickly set one up with Supabase.

Set Fields - Create searchConsoleDataArray

These nodes create an array based on the response from the Search Console API.

Respond to Webhook

This node is used to send a response back to the user.

Tip: intermediateSteps are configured, allowing you to use raw data fetched from Search Console to create charts or other visualizations if desired.

Nodes in this workflow

The 16 nodes in file order (sticky notes excluded). Branches and connections determine execution order in n8n:

  1. Postgres Chat Memory (Postgres Chat Memory)
  2. OpenAI Chat Model (OpenAI Chat Model)
  3. Set fields (Edit Fields (Set))
  4. Webhook - ChatInput (Webhook)
  5. Respond to Webhook (Respond to Webhook)
  6. Call Search Console Tool (Call n8n Workflow Tool)
  7. Tool calling (Execute Workflow Trigger)
  8. Switch (Switch)
  9. Set fields - Consruct API CALL (Edit Fields (Set))
  10. Set fields - Create searchConsoleDataArray (Edit Fields (Set))
  11. Set fields - Create searchConsoleDataArray 2 (Edit Fields (Set))
  12. Search Console - Get Custom Insights (HTTP Request)
  13. ## Search Console - Get List of Properties (HTTP Request)
  14. Array aggregation - response to AI Agent (Aggregate)
  15. Array aggregation - response to AI Agent1 (Aggregate)
  16. AI Agent (AI Agent)

Credentials you need

  • Generic OAuth2 – used by ## Search Console - Get List of Properties and Search Console - Get Custom Insights
  • HTTP Basic Auth – used by Webhook - ChatInput
  • OpenAI API – used by OpenAI Chat Model
  • Postgres – used by Postgres Chat Memory

Configure your own credentials after importing. Create each credential in n8n, then select it in the node.

How to import into n8n

  1. Download the JSON file with the button above.
  2. In n8n, open a new workflow, select the ... menu and choose Import from File. You can also paste the JSON straight into the editor canvas.
  3. Open each node that shows a warning and select or create its credential.
  4. Read the notes on the canvas, test the workflow with sample data, then activate it.

Do you need somewhere to run it? Read our guide to self-hosted n8n.

Need this customised?

We can adapt this workflow to your apps, data and process, then deploy and support it.

Contact Us