Adding Gmail OAuth2 to n8n
Before you start, make sure you have:
- A Google Cloud Project with the Gmail API enabled
- OAuth 2.0 credentials created in Google Cloud Console
(Google's official guide →)
Step 1: Get your OAuth credentials from Google Cloud
- Go to console.cloud.google.com
- Select your project
- Go to APIs & Services → Credentials
- Find your OAuth 2.0 Client ID and click it
- Copy your Client ID and Client Secret. You will need these in the next step
Step 2: Create the credential in n8n
- Open your n8n instance
- Click Settings in the left sidebar
- Click Credentials
- Click Add credential in the top right
- Search for Gmail and select Gmail OAuth2 API
- Paste your Client ID and Client Secret from Step 1
- Click Sign in with Google
- A browser window will open. Sign in with the Google Workspace admin account
- Grant the requested permissions
- You will be redirected back to n8n. The credential will show as connected
Step 3: Copy your credential ID
You will need this ID when configuring your workflow.
- After saving the credential, look at the URL in your browser
- Copy the ID at the end of the URL
Example:
https://your-n8n.com/credentials/abc123 → your credential ID is abc123
Keep this handy. You will paste it into the configurator form.
Troubleshooting
"Error: redirect_uri_mismatch"
Your OAuth redirect URI is not configured correctly in Google Cloud Console.
In your OAuth credential settings, add this to the authorised redirect URIs:
https://your-n8n.com/rest/oauth2-credential/callback
"Error: access_denied"
Make sure the Google account you used to sign in has access to the Gmail API
and that the OAuth consent screen is configured correctly in Google Cloud Console.