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
Query n8n workflow credentials with OpenAI

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

Learn how to Build this Workflow with AI:

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;


Query n8n workflow credentials with OpenAI

Visit through Desktop to Interact with the Workflow.

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 Twist Channel Creation and Messaging with n8n

This workflow automates creating and updating a channel in Twist and sending a personalized message to specific users. It eliminates manual setup errors and saves time managing Twist communications.

Automate Ideogram Image Generation with Google Sheets & Gmail

This workflow automates graphic design image generation via Ideogram AI, storing image data in Google Sheets and Google Drive, with email alerts via Gmail. It saves designers hours by automating image creation, remixing, review, and record-keeping.

Automate IT Support with Slack and OpenAI in n8n

Streamline IT support by automating Slack message handling using n8n and OpenAI. This workflow handles Slack DMs, filters bots, queries a Confluence knowledge base, and delivers AI-generated responses, improving support efficiency and response time.

Automate Crypto Analysis with CoinMarketCap & n8n AI Agent

Discover how this unique n8n workflow leverages CoinMarketCap’s multi-agent AI to deliver precise, real-time cryptocurrency insights directly via Telegram. Manage crypto data analysis efficiently with automated multi-source API integration.

Automate Gumroad to Beehiiv Subscriber Sync with n8n

Learn how to automatically add new Gumroad sales customers as Beehiiv newsletter subscribers using n8n automation. This workflow saves time by syncing sales data to Google Sheets CRM and notifying your Telegram channel instantly.

Generate On-Brand Blog Articles Using n8n and OpenAI

This workflow automates the creation of on-brand blog articles by analyzing existing company content using n8n and OpenAI. It extracts article structures and brand voice to produce consistent draft articles, saving significant content creation time.
1:1 Free Strategy Session
Your competitors are already automating. Are you still paying for it manually?

Do you want to adopt AI Automation?

Every hour your team does repetitive work, you're burning real money.
While you wait, faster businesses are cutting costs and moving quicker.
AI and automations aren't the future anymore — they're the present.

Book a live 1-on-1 session where we show you exactly which of your daily tasks can be automated — and what it’s costing you not to.