n8n Credential Setup Guide

Step-by-step instructions for connecting Gmail, Google Sheets, and OpenAI to n8n. Follow this guide when setting up a new credential or troubleshooting an existing one.

Gmail OAuth2 Google Sheets Service Account OpenAI API Key
ⓘ

Overview

ℹ️
Gmail and Google Sheets use different authentication methods. Gmail uses OAuth2 (signs in as a real user). Google Sheets uses a Service Account (a bot identity — simpler and more reliable for automation).
ServiceMethodWhat you need
GmailOAuth2Google Cloud OAuth Client ID + Secret
Google SheetsService AccountGoogle Cloud Service Account JSON key
OpenAIAPI KeyOpenAI secret key from platform.openai.com

Both Gmail and Google Sheets use the same Google Cloud project (esquire-automation). You only need to create the project once.

1

Google Cloud Project Setup

Do this once. If the esquire-automation project already exists, skip to section 2 or 3.

Create the Project

  1. Go to console.cloud.google.com and sign in with the Esquire Google account
  2. Click the project dropdown at the top → New Project → name it esquire-automation → Create

Enable Required APIs

  1. Go to APIs & Services → Library
  2. Search Gmail API → Enable
  3. Search Google Sheets API → Enable
  4. Search Google Drive API → Enable

OAuth Consent Screen (required for Gmail OAuth2 only)

  1. Go to APIs & Services → OAuth consent screen → Audience
  2. Set User Type to External → Save
  3. Go to Branding → App name: Esquire Automation, support email, developer email → Save
  4. Go back to Audience → under Test users → add the email of whoever will connect Gmail → Save
⚠️
The app stays in Testing mode. Only emails added as test users can authorize it. Add any new staff email here before they try to connect Gmail.
2

Gmail — OAuth2

📧 Gmail OAuth2 API n8n credential type
Client IDFrom Google Cloud Console (see steps below)
Client SecretFrom Google Cloud Console (see steps below)

Step 1 — Create OAuth Client in Google Cloud

  1. Go to APIs & Services → Credentials → Create Credentials → OAuth client ID
  2. Application type: Web application → Name: n8n-google
  3. Under Authorized redirect URIs → Add URI → enter exactly:

    https://n8n.esquireembroidery.com/webhook/rest/oauth2-credential/callback
  4. Click Create → copy the Client ID and Client Secret shown in the dialog
🔴
The redirect URI must be exactly right. A common mistake is adding /webhook/ in the path — this causes Error 400: redirect_uri_mismatch.

Correct: https://n8n.esquireembroidery.com/webhook/rest/oauth2-credential/callback
Wrong  : https://n8n.esquireembroidery.com/rest/oauth2-credential/callback (missing /webhook/)

Step 2 — Add Credential in n8n

  1. In n8n, open a workflow → add a Gmail node → click the credential field → Create New Credential → Gmail OAuth2 API
  2. Paste the Client ID and Client Secret
  3. Click Sign in with Google → sign in with the Gmail account you want n8n to use
  4. Approve the permissions → you should see Connection tested successfully

Important: n8n Server Config Requirement

The n8n server must have WEBHOOK_URL set correctly in /home/ec2-user/n8n.config.js — this is what determines the redirect URL n8n sends to Google. The current config is:

WEBHOOK_URL:         "https://n8n.esquireembroidery.com/webhook/"
N8N_EDITOR_BASE_URL: "https://n8n.esquireembroidery.com"

If n8n is ever reinstalled, verify both lines are present. After any config change, restart n8n:

pm2 delete n8n && pm2 start /home/ec2-user/n8n.config.js
3

Google Sheets — Service Account

✓
Service Account is simpler than OAuth2 — no browser sign-in, no token expiry. Recommended for all automated Sheets access.
📊 Google Sheets Service Account n8n credential type
Service Account EmailFrom the JSON key file — "client_email" field
Private KeyFrom the JSON key file — "private_key" field (long text starting with -----BEGIN PRIVATE KEY-----)

Step 1 — Create Service Account in Google Cloud

  1. Go to APIs & Services → Credentials → Create Credentials → Service Account
  2. Name: n8n-sheets → click Create and Continue → skip optional steps → Done
  3. Click on the n8n-sheets service account in the list
  4. Go to the Keys tab → Add Key → Create new key → JSON → click Create
  5. A JSON file downloads automatically — open it in a text editor (Notepad, VS Code, etc.)

Step 2 — Add Credential in n8n

  1. In n8n, add a Google Sheets node → credential field → Create New Credential → Google Sheets Service Account
  2. Copy "client_email" value from the JSON file → paste into Service Account Email
  3. Copy the entire "private_key" value (including the -----BEGIN PRIVATE KEY----- and -----END PRIVATE KEY----- lines) → paste into Private Key
  4. Click Save → you should see Connection tested successfully

Step 3 — Share Your Spreadsheet with the Service Account

⚠️
Service accounts cannot access spreadsheets they haven't been shared with. You must share each sheet manually — one-time per spreadsheet.
  1. Open the Google Sheet in your browser → click Share (top right)
  2. Paste the service account email (from "client_email" in the JSON — looks like n8n-sheets@esquire-automation.iam.gserviceaccount.com)
  3. Set role to Editor → uncheck "Notify people" → click Share
4

OpenAI — API Key

🤖 OpenAI API n8n credential type
API KeySecret key from platform.openai.com — starts with sk-

Step 1 — Get an API Key

  1. Go to platform.openai.com → sign in or create an account
  2. Click your profile icon (top right) → API Keys → Create new secret key
  3. Name it n8n-po-automation → click Create
  4. Copy the key immediately — you can only see it once. Paste it somewhere safe before closing the dialog.

Step 2 — Add Billing Credits

⚠️
New OpenAI accounts have no credits by default. Go to Settings → Billing → Add payment method. Start with $10 — at ~$3/mo for this project it will last a long time.

Step 3 — Add Credential in n8n

  1. In n8n, add an OpenAI node → credential field → Create New Credential → OpenAI API
  2. Paste the API key into the API Key field → click Save

Model to Use

When configuring the OpenAI node, select gpt-4.1 as the model. It produces the best results for reading and understanding email content and PO documents.

5

Troubleshooting

ErrorCauseFix
Error 400: redirect_uri_mismatch Redirect URI in Google Cloud doesn't match what n8n sends Google Cloud → Credentials → n8n-google → Authorized redirect URIs. Must be exactly: https://n8n.esquireembroidery.com/webhook/rest/oauth2-credential/callback — no /webhook/
Access blocked: This app's request is invalid Your email is not added as a test user in the OAuth consent screen Google Cloud → OAuth consent screen → Audience → Test users → add your email
OAuth callback returns 404 webhook not registered N8N_EDITOR_BASE_URL missing from n8n config on the server Check /home/ec2-user/n8n.config.js has N8N_EDITOR_BASE_URL: "https://n8n.esquireembroidery.com" then run: pm2 delete n8n && pm2 start /home/ec2-user/n8n.config.js
403: The caller does not have permission (Sheets) Spreadsheet not shared with the service account Open the sheet → Share → add the service account email as Editor
Column names were updated after the node's setup Sheet headers changed after the n8n node was configured Click the Google Sheets node → Columns field → click the refresh icon to reload the schema
You exceeded your current quota (OpenAI) No credits in OpenAI account platform.openai.com → Settings → Billing → add credits
Gmail body empty / GPT classifies everything as Needs Review Simplify is ON in Gmail Trigger node, which strips the email body Click the Gmail Trigger node → turn Simplify OFF. Body is then in $json.text, sender in $json.from.value[0].address, date in $json.date