Query n8n Workflow Credentials Using AI & SQLite Database

Discover how to automate querying of your n8n workflow credentials with an AI-powered SQL agent, saving time and improving workflow management. This guide shows you how to extract, store, and search workflow credentials using n8n, SQLite, and OpenAI integration.
n8n
agent
code
+6
Workflow Identifier: 1324
NODES in Use: ManualTrigger, Set, n8n, Code, ChatTrigger, lmChatOpenAi, memoryBufferWindow, toolCode, agent

Press CTRL+F5 if the workflow didn't load.

Learn how to Build this Workflow with AI:

Visit through Desktop for Best experience

What This Workflow Does

This workflow finds which credentials are used in all your n8n workflows. It saves time by stopping you from searching manually. The workflow collects workflow metadata through n8n API, stores credentials in a SQLite database, and answers questions using AI chat.

You get a fast way to see which workflows use which credentials like Slack or OpenAI APIs. This helps in troubleshooting and managing workflows better.


Who Should Use This Workflow

This workflow is for people who manage many n8n workflows and need to track credential use. It is helpful for automation specialists and team leads who want faster audits and fewer mistakes.

If you spend hours checking workflows manually, this tool can save you time and reduce errors.


Tools and Services Used

  • n8n API: Fetches workflow information including credentials.
  • SQLite: Stores workflow and credential data locally.
  • OpenAI Chat API: Powers natural language queries on stored data.

Beginner Step-by-Step: How to Use This Workflow in n8n

Step 1: Download and Import Workflow

  1. Click the Download button on this page to get the workflow file.
  2. Open your n8n editor.
  3. Select Import from File and upload the downloaded workflow.

Step 2: Add Your Credentials

  1. Go to each node that requires API access, like the n8n API node and the OpenAI Chat Model node.
  2. Enter your valid API Keys or other credentials.

Step 3: Update IDs or Names If Needed

  1. Check if any IDs, folder names, or channel names in the workflow need to be changed to match your setup.
  2. Adjust these fields using the expression or text editors inside the nodes.

Step 4: Test the Workflow

  1. Run the manual trigger in the workflow by clicking Execute Workflow.
  2. Watch the nodes run and check for errors.

Step 5: Activate for Production

  1. When testing works, activate the workflow by enabling the trigger node.
  2. Set schedule triggers if you want this to run regularly.
  3. Secure chat webhooks by adding authentication if exposing them.

Inputs, Processing Steps, and Outputs

Inputs:

  • Trigger to start workflow manually or on schedule.
  • API credentials for n8n and OpenAI.
  • User chat messages sent to the chat webhook to query data.

Processing Steps:

  • Use the n8n API node to fetch all workflows metadata including credentials.
  • Map workflows with the Set node to extract workflow ID, name, and credentials.
  • Use a Python Code node to save workflows and credentials into an SQLite database.
  • On receiving chat input through the Chat Trigger webhook, process the message using OpenAI chat model.
  • Maintain conversation context with the Window Buffer Memory node.
  • Run SQL queries on the SQLite database via the ToolCode node based on AI-generated instructions.
  • The Workflow Credentials Helper Agent node combines AI chat, memory, and SQL query execution to give results.

Outputs:

  • List of workflows with their used credentials that match the query.
  • User-friendly AI chat answers including workflow links and credential details.

Customization Ideas

  • Save the SQLite database on disk to keep data after restarts. This is good for self-host n8n setups.
  • Add more data fields like node types or metadata for better reporting in the Set node.
  • Change AI system prompts in the Workflow Credentials Helper Agent to better suit your company’s language.
  • Add security to the Chat Trigger webhook by using API keys or OAuth.
  • Support multiple users with different permissions to see different workflows.

Edge Cases and Troubleshooting

Problem: API calls fail with 401 Unauthorized

This means the API key for the n8n API node is missing or wrong.

Fix by updating the API key in the node settings and re-run the workflow.

Problem: SQLite database lost after restarting n8n

In-memory database resets with workflow restarts.

Fix by changing the Python Code node to save the database file on disk in a persistent folder. This needs self-host n8n or similar.

Problem: AI shows errors or no results

Check that the database was filled by previous workflow runs. Also confirm the AI generates correct SQL SELECT queries only.

Adjust AI prompt messages or review database content if errors persist.


Summary Results

✓ Easily find which workflows use specific credentials without manual checking.

✓ Save hours weekly by automating credential mapping and queries.

✓ Get AI-powered natural language answers for complex queries.

→ Improves audit and troubleshooting speed for large n8n environments.

→ Supports better security and operational management of workflow credentials.


Code Snippets for Reference

Save to Database Python Code

This code creates, inserts, and updates the workflows and credentials in SQLite.

import json
import sqlite3
con = sqlite3.connect("n8n_workflow_credentials.db")

cur = con.cursor()
cur.execute("CREATE TABLE IF NOT EXISTS n8n_workflow_credentials (workflow_id TEXT PRIMARY KEY, workflow_name TEXT, credentials TEXT);")

for item in _input.all():
    cur.execute('INSERT OR REPLACE INTO n8n_workflow_credentials VALUES(?,?,?)', (
        item.json.workflow_id,
        item.json.workflow_name,
        json.dumps(item.json.credentials.to_py())
    ))

con.commit()
con.close()

return [{ "affected_rows": len(_input.all()) }]

Query Database Python Code for SQL SELECT

This code runs SQL queries sent by AI and returns JSON results.

import json
import sqlite3
con = sqlite3.connect("n8n_workflow_credentials.db")

cur = con.cursor()
res = cur.execute(query);

output = json.dumps(res.fetchall())

con.close()
return output;


Frequently Asked Questions

No. The workflow needs OpenAI API keys to process natural language queries.
By default, the database is in-memory and lost when n8n restarts. Persistent storage needs changing code to save on disk.
Yes. The AI agent converts natural language to SQL queries to filter results by workflow names or credentials.
No. It stores credential metadata, not secret values, but secure the n8n setup and webhook access to protect data.

Promoted by BULDRR AI

Related Workflows

Automate Viral UGC Video Creation Using n8n + Degaus (Beginner-Friendly Guide)

Learn how to automate viral UGC video creation using n8n, AI prompts, and Degaus. This beginner-friendly guide shows how to import, configure, and run the workflow without technical complexity.
Form Trigger
Google Sheets
Gmail
+37
Free

AI SEO Blog Writer Automation Workflows in n8n

A complete beginner guide to building an AI SEO blog writer automation using n8n.
AI Agent
Google Sheets
httpRequest
+5
Free

Automate CrowdStrike Alerts with VirusTotal, Jira & Slack

This workflow automates processing of CrowdStrike detections by enriching threat data via VirusTotal, creating Jira tickets for incident tracking, and notifying teams on Slack for quick response. Save hours daily by transforming complex threat data into actionable alerts effortlessly.
scheduleTrigger
httpRequest
jira
+5
Free

Automate Telegram Invoices to Notion with AI Summaries & Reports

Save hours on financial tracking by automating invoice extraction from Telegram photos to Notion using Google Gemini AI. This workflow extracts data, records transactions, and generates detailed spending reports with charts sent on schedule via Telegram.
lmChatGoogleGemini
telegramTrigger
notion
+9
Free

Automate Email Replies with n8n and AI-Powered Summarization

Save hours managing your inbox with this n8n workflow that uses IMAP email triggers, AI summarization, and vector search to draft concise replies requiring minimal review. Automate business email processing efficiently with AI guidance and Gmail integration.
emailReadImap
vectorStoreQdrant
emailSend
+12
Free

Automate Email Campaigns Using n8n with Gmail & Google Sheets

This n8n workflow automates personalized email outreach campaigns by integrating Gmail and Google Sheets, saving hours of manual follow-up work and reducing errors in email sequences. It ensures timely follow-ups based on previous email interactions, optimizing communication efficiency.
googleSheets
gmail
code
+5
Free