Google Drive API: Folder creation in Shared Drive fails with corpora parameter

11 hours ago 3
ARTICLE AD BOX

Problem

I'm trying to create folders in a Google Shared Drive using the Google Drive API v3, but the folder search is not finding existing folders, causing duplicate folders to be created.

Environment

This is a browser-based JavaScript application running in a single HTML file. I'm using Google Drive API v3 with OAuth 2.0 authentication with the scope https://www.googleapis.com/auth/drive and the Google Identity Services (GIS) library.

What's Happening

I have a function called getOrCreateFolder that takes a parent folder ID and a folder name. The first time I call this function, it successfully creates a folder in the Shared Drive. However, when I call it again with the exact same parameters, instead of finding the existing folder, it creates a duplicate folder.

The search query I'm using includes the following parameters: Query filter with name equals folder name, parent ID matches, mimeType is folder, not trashed. Fields parameter is set to files(id,name). I'm also using supportsAllDrives: true, includeItemsFromAllDrives: true, and corpora: allDrives.

The search always returns an empty array even though I can see the folder exists in the Google Drive web interface.

What I've Tried

I've added supportsAllDrives: true and includeItemsFromAllDrives: true parameters. I've added corpora: allDrives parameter to the search. I've verified the folder exists in the Shared Drive and it's visible in Google Drive UI. I've confirmed the parentId is the Shared Drive root folder ID. I've tried different search query formats.

OAuth Configuration

The scope I'm using is https://www.googleapis.com/auth/drive. Test users are added in Google Cloud Console and the OAuth consent screen is configured for external users.

Questions

Why is the search not finding folders in the Shared Drive? Is there a missing parameter or permission required for searching in Shared Drives? Does the OAuth scope need to be different for Shared Drive operations? Could this be a caching or indexing delay issue with Google Drive API?

Expected Behavior

The search should find the existing folder in the Shared Drive and return its ID, preventing duplicate folder creation.

Actual Behavior

The search always returns an empty array (files: []) even when the folder clearly exists and is visible in the Google Drive web interface.

Additional Context

This exact same code works perfectly with "My Drive" (non-shared drives). The issue only occurs with Shared Drives. The folder is visible and accessible through the Google Drive web interface. I can manually navigate to the folder in Drive. Multiple attempts over 100+ iterations with various parameter combinations have all failed.

Read Entire Article