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:
- I have a Google Sheet with random lead data (e.g., first name, last name, email, phone, company, title: dentist, dermatologist, plumber, etc.).
- 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.
- 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:
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:
-
Client ID and Secret: Created the credentials in Google Cloud and enabled the Google Sheets API.
-
Redirect URI: Set the redirect URI to n8n - OAuth Callback.
-
API Scope: Using the scope https://www.googleapis.com/auth/spreadsheets.
-
Authentication: Tried to exchange the authorization code for an access token but got the above error.
My Questions: -
How can I properly handle the OAuth2 callback in n8n to get the access token and authenticate my API calls?
-
Once authenticated, what’s the best way to structure the API call to create a new sheet with specific headers and append filtered data?
-
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!