Issue with Google Sheets API OAuth2 Callback While Creating Sheets with Headers in n8n

Hey everyone,

I’m setting up a workflow in n8n to filter lead data from a Google Sheet based on a title (e.g., dentist, plumber, HVAC) and create a new Google Sheet with only the filtered data. Here’s a breakdown of my process:

What I’m Trying to Achieve:

  1. I have a Google Sheet with random lead data (e.g., first name, last name, email, phone, company, title: dentist, dermatologist, plumber, etc.).
  2. Based on the input I provide via a Set node (let’s say I input “dentist”), I want to filter the existing leads and create a new sheet for dentists.
  3. The new sheet should have specific headers like first name, last name, email, phone, and company, and append the filtered data into these columns.

The Problem:

  • The built-in Google Sheets node in n8n can create the new sheet but without headers.
  • To work around this, I decided to make API calls directly to the Google Sheets API to create the sheet and add headers.
  • However, I’m running into an OAuth2 error when trying to authenticate my API requests to Google Sheets.

The Error:

I’ve successfully generated the client ID and client secret from Google Cloud Console, but when I try to get the access token using the following authorization URL:

https://accounts.google.com/o/oauth2/v2/auth?response_type=code&client_id=3363879969-5c5ao5lfdfdjftl4o5p16j2bfaivavbr.apps.googleusercontent.com&redirect_uri=https://simonacolaco.app.n8n.cloud/rest/oauth2-credential/callback&scope=https://www.googleapis.com/auth/spreadsheets&access_type=offline

I receive this error:

Error: Insufficient parameters for OAuth2 callback.

Received following query parameters: {“code”:“4/0AXxxxxxxxxxxxxxxxxxxx”,“scope”:“https://www.googleapis.com/auth/spreadsheets”}

Failed to connect. The window can be closed now.

Steps I’ve Followed:

  1. Client ID and Secret: Created the credentials in Google Cloud and enabled the Google Sheets API.

  2. Redirect URI: Set the redirect URI to n8n - OAuth Callback.

  3. API Scope: Using the scope https://www.googleapis.com/auth/spreadsheets.

  4. Authentication: Tried to exchange the authorization code for an access token but got the above error.
    My Questions:

  5. How can I properly handle the OAuth2 callback in n8n to get the access token and authenticate my API calls?

  6. Once authenticated, what’s the best way to structure the API call to create a new sheet with specific headers and append filtered data?

  7. Is there a better workaround or built-in method to achieve this directly in n8n without relying on API calls?

Any help or insights would be really appreciated!

Thanks in advance!

1 Like

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

Hey @Rohit_Gurav , can you try the solution for adding the header below. No need for a direct Google Sheets API calls.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.