Google Drive API V3: How can I add files to Team Drive (Shared Drive)?

I’m struggling with uploading files to a Team Drive using Google Drive API V3. Can someone help me figure out what I’m doing wrong?

I keep getting a 404 error when trying to upload files to our shared drive. I tried using the parent folder ID but it doesn’t work properly.

Here’s my current code:

function uploadToTeamDrive(fileStream, fileSize, mimeType, filename, folderId, onComplete) {
    // Setup progress tracking
    this.emit('upload-progress', {
        category: 'document',
        filename: filename,
        bytesUploaded: 0,
        totalBytes: fileSize
    });
    
    console.log('Starting upload for %s with folder ID: %s', filename, folderId);
    
    const driveService = google.drive({ version: 'v3', auth: this.authClient });
    
    let documentMetadata = {
        name: filename,
        mimeType: mimeType,
        'parents': ["0BFjjwdVdxetuUk9PVB"],
        'sharedDriveId': "0BFjjwdVdxetuUk9PVB"
    }
    
    if (folderId) {
        documentMetadata['parents'] = [folderId];
    }
    
    const uploadRequest = driveService.files.create({
        resource: documentMetadata,
        media: {
            mimeType: mimeType,
            body: fileStream
        }
    }, (error, response) => {
        console.log('File %s uploaded successfully', filename);
        this.emit("upload-complete", {
            totalBytes: fileSize,
            filename: filename,
            errorStatus: error
        });
        if (onComplete)
            onComplete(error, response);
    });
    
    return uploadRequest;
}

The error I’m getting is:

code: 404,
errors: [{
    domain: 'global',
    reason: 'notFound', 
    message: 'File not found: 0BFjjwdVdxetuUk9PVB.',
    locationType: 'parameter',
    location: 'fileId'
}]

What am I missing here? Do I need special permissions or different parameters for Team Drive uploads?

The problem’s your supportsAllDrives parameter - you need to explicitly tell the API you’re working with shared drives. Hit this exact issue last year migrating our company files. Add supportsAllDrives: true to your parameters. Without it, Drive API only searches personal drives and throws that 404 you’re seeing. Modify your driveService.files.create call like this: const uploadRequest = driveService.files.create({ resource: documentMetadata, media: { mimeType: mimeType, body: fileStream }, supportsAllDrives: true }, (error, response) => { // your callback code });. Also double-check your folder ID’s actually valid - test it with a simple files.get request first. Format looks right but worth verifying the folder exists and your service account has proper access.

you’re using the shared drive ID wrong - it goes in the request parameters, not the resource metadata. Move sharedDriveId out of documentMetadata and put it with supportsAllDrives: true in the main request object. also, that folder ID looks like a drive ID format. make sure it’s pointing to an actual folder inside the shared drive, not the drive root.

Been fighting Drive API issues for years - manual coding is way too fragile for production.

Yeah, you need supportsAllDrives: true and correct parameter placement. But that’s just the start. You’ll still deal with rate limits, auth token refreshes, retry logic, and tons of other edge cases.

I ditched manual coding for Latenode after weeks of debugging the same API nonsense. It handles all the Drive complexity - shared drives, permissions, batch operations, everything.

Just connect your Google account and set up a workflow that watches for new files and uploads them to your shared drive. No more debugging 404 errors at 2am.

We’re processing thousands of files monthly with zero maintenance. The visual builder makes adding conditional logic, file processing, or notifications super easy.

Skip the debugging headache and automate it right: https://latenode.com