Trigger: Google Drive trashed files

The idea is:

Per this thread, the community would like to request the N8N Google Drive Trigger to support the “trashing” of a file (e.g. when a file is “deleted” in GDrive, it is moved to the “Trash” folder. See Google Drive API “delete” docs

My use case:

AI RAG use case: I use Google Drive as my data source for my OpenAI RAG storage. When a GDrive file is created or edited, it update my RAG vector store. Currently, n8n does not offer a mechanism to respond when a GDrive file is “trashed”. This creates mis-match between the GDrive data and my RAG vector store.

I think it would be beneficial to add this because:

See community support in this thread

Any resources to support this?

Are you willing to work on this?

I have not contributed to N8N but am open to learning if someone would be willing to guide me. (I’m a C#/Java dev, not nodejs)

Build a Google Drive Trash Monitoring System with n8n and Supabase

This workflow automatically detects files moved to the Google Drive trash and removes their corresponding records from your Supabase database, keeping both systems in sync. maybe this could be a starting point to devs @n8n for this Feature Request

This is my humble Hello world as a no-coder.
Big thanks to all community and n8n for guiding me to this solution here.
Happy No-Coding

Prerequisites

  • n8n account (self-hosted or cloud)
  • Supabase account with a table containing Google Drive file IDs
  • Google Cloud Project with Drive API enabled

Step 1: Create a Google Cloud Project API Credentials

  1. Go to Google Cloud Console
  2. Create a new project or select an existing one
  3. Enable the Google Drive API
  4. Create OAuth 2.0 credentials:
  • Application type: Web application
  • Add authorized redirect URI: Your n8n domain + /rest/oauth2-credential/callback
  • Save your Client ID and Client Secret

Step 2: Set Up OAuth2 in n8n

  1. In n8n, go to Credentials → Create New
  2. Select “OAuth2 API”
  3. Configure as follows:
  • Name: “GDrive API OAuth2 Changes”
  • Access Token URL: https://oauth2.googleapis.com/token
  • Authorization URL: https://accounts.google.com/o/oauth2/auth
  • Client ID: [Your Google API Client ID]
  • Client Secret: [Your Google API Client Secret]
  • Scope: https://www.googleapis.com/auth/drive
  • Auth URI Query Parameters: access_type=offline&prompt=consent
  1. Click “Save” and then “Connect” to authenticate with Google

Step 3: Configure Your Supabase Table

Ensure your Supabase table has a column for Google Drive file IDs:

  • Table name: n8n-rag-1 (or your preferred name)
  • Column: gdrive_file_id (type: TEXT)

Step 4: Create the n8n Workflow

Create a new workflow with these nodes:

Schedule Trigger

  1. Add a “Schedule Trigger” node
  2. Configure to run every 30 minutes (or your preferred interval)

GDrive API Request

  1. Add an “HTTP Request” node
  2. Name it “GDrive API Request”
  3. Configure:
  • Authentication: OAuth2
  • Credential: Select “GDrive API OAuth2 Changes”
  • Request Method: GET
  • URL: https://www.googleapis.com/drive/v3/changes/startPageToken

GDrive GET Files in Trash

  1. Add another “HTTP Request” node
  2. Name it “GDrive GET Files in Trash”
  3. Configure:
  • Authentication: OAuth2
  • Credential: Select “GDrive API OAuth2 Changes”
  • Request Method: GET
  • URL: https://www.googleapis.com/drive/v3/files?q=trashed=true

Filter Deleted Files

  1. Add a “Function” node
  2. Name it “Filter Deleted Files”
  3. Paste this code:

javascript

try {
  const response = items[0].json;
  const files = response.files;
  const returnItems = [];
  
  if (Array.isArray(files)) {
    for (const file of files) {
      returnItems.push({ 
        json: { 
          fileId: file.id,
          fileName: file.name,
          mimeType: file.mimeType
        } 
      });
    }
  }
  
  return returnItems.length > 0 ? returnItems : [];
} catch (error) {
  return [{ json: { error: error.message } }];
}

Delete Supabase Record

  1. Add a “Supabase” node
  2. Name it “Delete Supabase Record”
  3. Configure:
  • Operation: Delete
  • Table ID: “n8n-rag-1” (or your table name)
  • Under Filters → Conditions:
    • Key Name: “gdrive_file_id”
    • Condition: Equal to (eq)
    • Key Value: ={{ $json.fileId }}

Post-Deletion Success

  1. Add a “Function” node
  2. Name it “Post-Deletion Success”
  3. Paste this code:

javascript

try {
  const result = $json;
  return [{ json: { message: "Supabase deletion complete", result } }];
} catch (error) {
  throw new Error(`Error in post-deletion processing: ${error.message}`);
}

Step 5: Connect All Nodes

Connect the nodes in sequence:

  1. Schedule Trigger → GDrive API Request
  2. GDrive API Request → GDrive GET Files in Trash
  3. GDrive GET Files in Trash → Filter Deleted Files
  4. Filter Deleted Files → Delete Supabase Record
  5. Delete Supabase Record → Post-Deletion Success

Step 6: Activate and Test

  1. Save the workflow
  2. Click “Test workflow” to run it manually
  3. Check execution results to ensure it’s detecting trashed files
  4. Activate the workflow for automatic execution

Troubleshooting

  • If you get a “refreshToken is required” error, edit your OAuth2 credential and reconnect it
  • Make sure your column names in Supabase match exactly what’s in the workflow
  • Check Google Cloud Console to ensure your API credentials have proper Drive API access

This workflow brings powerful synchronization capabilities between Google Drive and your Supabase database with little to zero coding required!

1 Like