DEV Community

Cristian Tala
Cristian Tala

Posted on

Google Service Account in n8n: Complete 2026 Guide

Do you need to configure a Google Service Account in n8n for your automations? If you're using OAuth to connect to Google Sheets, Drive, or Gmail, you're probably making a mistake that will cost you time (and headaches) down the road.

When I first started automating workflows in n8n, I used OAuth like everyone else. It's easier, faster... until it stops working. Tokens expire, credentials get invalidated when you change your password, and worst of all: if someone on the team leaves, all the workflows connected to their account die.

The professional solution: configure Google Service Accounts in n8n correctly from the start.

Here's what they are, why they matter, and how to set them up step by step.

What Is a Service Account and Why Does It Matter?

A Service Account is a special Google account designed for applications and automations, not for humans.

Key differences from OAuth:

OAuth (the "easy" method):

  • Connected to a specific user
  • Requires periodic re-authorization
  • Breaks if you change your Google password
  • If the user loses access, workflows fail

Service Account (the professional method):

  • Independent of human users
  • No re-authorizations (permanent credentials)
  • Works even if you change passwords
  • Ideal for production and teams

For entrepreneurs and startups: If you're automating critical business processes (CRM, billing, reports), you need stability. Service Accounts give you that.

When to Use Service Accounts in n8n

Use Service Accounts if:

  • You're automating critical business processes
  • You work with Google Sheets as a database
  • You need workflows to run without supervision
  • You share workflows among multiple people
  • You want to avoid re-authentication every few months

Real use cases:

  • Automated CRM: Sync leads between forms and Google Sheets
  • Automatic reports: Daily report generation in Sheets from your database
  • File management: Upload/move files in Google Drive automatically
  • Transactional emails: Send emails from Gmail without depending on a personal account

Step 1: Create a Google Cloud Project

You need a Google Cloud project. It's free for basic use.

  • Go to Google Cloud Console
  • Click on the projects dropdown (top left)
  • Select "New Project"
  • Give it a descriptive name (e.g., "n8n-automations")
  • Click Create

Step 2: Enable the Required APIs

Google requires you to explicitly enable each API you'll use.

Common APIs for n8n:

  • Google Sheets API
  • Google Drive API
  • Gmail API
  • Google Calendar API

How to enable: Menu → "APIs & Services" → "Library" → Search for the API → Click "Enable"

Which ones to enable? Depends on your workflows. For Google Sheets, enable Sheets + Drive (Drive is required for file permissions).

Step 3: Create the Service Account

  • Go to "APIs & Services" → "Credentials"
  • Click "Create credentials" → "Service account"
  • Fill in the fields:
    • Name: Something descriptive (e.g., "n8n-service-account")
    • ID: Auto-generated (leave it)
  • Click Create and continue
  • Role: Leave blank for now (we'll handle this with Sheets permissions)
  • Click Continue then Done

Important: The Service Account has its own email (something like name@project.iam.gserviceaccount.com). You'll need this later.

Step 4: Generate the JSON Key

The JSON file contains the credentials n8n will use to authenticate.

  • In the list of service accounts, click on the one you just created
  • Go to the "Keys" tab
  • Click "Add key" → "Create new key"
  • Select JSON format
  • Click Create

The file downloads automatically. Save it somewhere secure. It's like a password: whoever has this file can act as your Service Account.

File structure:

{
  "type": "service_account",
  "project_id": "your-project",
  "private_key_id": "...",
  "private_key": "-----BEGIN PRIVATE KEY-----\n...",
  "client_email": "name@project.iam.gserviceaccount.com",
  "client_id": "...",
  "auth_uri": "https://accounts.google.com/o/oauth2/auth",
  "token_uri": "https://oauth2.googleapis.com/token"
}
Enter fullscreen mode Exit fullscreen mode

Step 5: Share Google Sheets with the Service Account

Here's the trick that most people miss.

The Service Account has its own email. For it to access your Google Sheets, you must explicitly share the document with it.

  • Open the Google Sheet you want to use in n8n
  • Click Share (top right)
  • Paste the Service Account email (the one ending in @....iam.gserviceaccount.com)
  • Give permissions:
    • Editor: If n8n will write/modify data
    • Viewer: If it will only read
  • Uncheck "Notify people" (pointless, it's a bot)
  • Click Share

Repeat this for each Sheet/Drive you use in n8n.

Step 6: Configure the Credential in n8n

  • In n8n, go to Credentials
  • Click "Add Credential"
  • Search for "Google Service Account"
  • Open the downloaded JSON file with a text editor
  • Fill in the fields in n8n:
    • Service Account Email: Copy the value from client_email in the JSON
    • Private Key: Copy the complete value from private_key (including -----BEGIN PRIVATE KEY----- and -----END PRIVATE KEY-----)
  • Give it a descriptive name (e.g., "Google Service Account - Production")
  • Click Test connection to verify
  • If you see "Connection tested successfully ✅", click Save

Tip: You can use the same Service Account for multiple nodes (Sheets, Drive, Gmail, etc.). You don't need one per service.

When to use "Impersonate a User": Only if working with Google Workspace and you need the Service Account to act as a specific user in your organization. For normal use with shared Sheets, leave it OFF.

Step 7: Use the Service Account in Workflows

  • Add a Google Sheets node
  • In "Credential to connect with," select your Service Account
  • Configure the operation (Read, Append, Update, etc.)
  • Enter the Sheet ID (from the Sheet URL)
  • Done!

Key difference: With Service Account it won't ask for browser authorization. Works directly.

Common Errors and Solutions

"The caller does not have permission"

Cause: You didn't share the Google Sheet with the Service Account.

Solution: Repeat Step 5.

"API has not been used in project"

Cause: You forgot to enable the API in Google Cloud Console.

Solution: Repeat Step 2.

"Connection test failed"

Cause: You incorrectly copied the client_email or private_key from the JSON.

Solution:

  • Verify you copied the complete email (ending in @....iam.gserviceaccount.com)
  • Make sure to copy the complete private_key, including the BEGIN/END markers
  • Don't add extra spaces or line breaks

Workflow executes but doesn't read/write data

Cause: Service Account has "Viewer" permission but the workflow tries to write.

Solution: In Google Sheets, change the Service Account's permissions to "Editor."

OAuth vs Service Accounts — Technical Comparison

Feature OAuth Service Account
Initial setup Easier (1 click) More complex (6 steps)
Stability Tokens expire Permanent credentials
Binding Specific user Independent
Permissions Inherited from user Configurable per resource
Production use Not recommended Ideal
Password change Breaks connection No effect

My recommendation: OAuth for quick prototypes and tests. Service Accounts for everything running in production.

Security: Protect Your JSON File

The JSON file is sensitive. Whoever has it can act as your Service Account.

Best practices:

  • Don't commit it to GitHub (add *.json to .gitignore)
  • Store it in a password manager (1Password, Bitwarden, etc.)
  • Use environment variables when working in a team
  • Rotate keys every 6-12 months (optional but recommended)
  • Never share it via email/Slack unencrypted

If you think it was compromised:

  • Go to Google Cloud Console
  • Delete the compromised key
  • Generate a new one
  • Update the credential in n8n

Conclusion: Service Accounts = Professional Automations

If you're building serious automations for your business, properly configuring Google Service Accounts in n8n isn't optional — it's mandatory.

Yes, the setup takes longer than OAuth. But you avoid:

  • Re-authenticating every few months
  • Broken workflows from password changes
  • Dependency on specific users
  • Permission issues in teams

Configuring a Google Service Account in n8n takes 15-20 minutes. But the stability you gain is worth months of avoided headaches.

Have questions about Service Accounts or n8n? Join my entrepreneur community Cágala, Aprende, Repite — we can help each other with any technical implementation questions.

📝 Originally published in Spanish at cristiantala.com

Top comments (0)