n8n

How to Connect OpenAI and MySQL Sales Assistant?

Give buyers quick answers while your team focuses on closing deals. A chat assistant greets each user, searches products by city and state, and brings facts from a knowledge source. It fits teams that sell many plans or SKUs and need fast, accurate replies.

A public chat entry starts the flow. An If check and Set nodes prepare an intro message that stores user context into a Postgres table with a short memory window. The main OpenAI assistant runs with a longer Postgres memory and can call three tools. It queries MySQL for matching products using filters like cityQuery, state, modality, and holder count, reads a knowledge base URL for extra info, and posts to an external service with name and birth date to validate records. The assistant then writes a clear answer back to the chat.

You will need an OpenAI API key, plus access to PostgreSQL and MySQL. Create or confirm the aimessages table for chat memory, and check that your Products table and column names match the query. Expect faster replies, less manual lookup, and better qualified leads on your site or in an internal sales console.

What are the key features?

  • Chat Trigger starts a public chat session that the assistant can answer in real time
  • Two Postgres Chat Memory nodes store dialogue with short and long context windows
  • OpenAI assistant composes natural language replies and decides when to call tools
  • MySQL tool runs a filtered product query by city, state, modality, and holder count
  • HTTP knowledge base tool fetches product and pricing details from a URL endpoint
  • External POST API tool validates records using full name and birth date
  • If and Set nodes route messages and prepare inputs for the assistant

What are the benefits?

  • Reduce manual product lookup from 15 minutes to 1 minute per conversation
  • Automate up to 70% of first response messages in sales chat
  • Improve data accuracy by 90% by pulling answers from databases and APIs
  • Handle 3 times more chat volume without adding staff
  • Connect OpenAI, PostgreSQL, and MySQL in one place for unified answers

How do you set it up?

  1. Import the template into n8n: Create a new workflow in n8n > Click the three dots menu > Select 'Import from File' > Choose the downloaded JSON file.
  2. You'll need accounts with OpenAI, PostgreSQL and MySQL. See the Tools Required section above for links to create accounts with these services.
  3. In the n8n credentials manager, create an OpenAI API Key credential. Get your key from the OpenAI API page and paste it into the credential. Give it a clear name like OpenAI Sales Chat.
  4. Create a PostgreSQL credential with host, port, database, user, and password. Test the connection. Make sure the aimessages table exists or create it with id, session_id, role, content, and created_at columns.
  5. Create a MySQL credential with host, port, database, user, and password. Test the connection. Confirm you have a Products table and fields used in the query such as cityQuery, state, modality, removed, and holderCount.
  6. Open the Chat Trigger node and keep it public. Copy the webhook URL for testing the chat from a browser or your app.
  7. Open both Postgres Chat Memory nodes and select your PostgreSQL credential. Confirm the table name aimessages and the session key expression match the Chat Trigger session field.
  8. Open the MySQL tool node and review the SQL. Adjust column names and filters if your schema differs. Run a test query with sample AI variables to ensure results return.
  9. Open the Knowledge Base HTTP tool and confirm the URL template and query parameters. Replace placeholders with fields your assistant will provide, such as city and modality.
  10. Open the External API tool and confirm the endpoint and JSON body fields for name and birthdate. Verify the date format is YYYY MM DD with hyphens as required by the service.
  11. Run the workflow in test mode. Send a chat message that includes a city, state, and desired product details. Check the Execution log to confirm tool calls and see database rows created in aimessages.
  12. If you see errors, verify OpenAI API key permissions, database firewall rules, and table names. For empty product results, relax filters or confirm data exists for the chosen city and state.

Tools Required

$24 / mo or $20 / mo billed annually to use n8n in the cloud. However, the local or self-hosted n8n Community Edition is free.

MySQL

Sign up

MySQL Community Edition (GPL) – Free ($0)

OpenAI

Sign up

Pay-as-you-go: GPT-5 at $1.25 per 1M input tokens and $10 per 1M output tokens

PostgreSQL

Sign up

Free: $0 (open-source PostgreSQL License; self-hosted)

Similar Templates

Join Futurise to access 1,200+ automation templates

Get instant access to ready-made automation workflows for n8n, Make.com, AI agents, and more. Download, customise, and deploy in minutes.