Drive API - Insufficient permissions to delete a file with service account

wugge
New Member

Hi,

I'm using googleapi's node package to upload files to my google drive with a service account.

Uploading works fine, but when I try to delete a file I get the following Error:

"Error: The user does not have sufficient permissions for this file."

The directory is shared (as a Content Manager) to the email of the service account user. I couldn't find a way to give the service account more permissions to be able to delete a file.

What is the proper way of doing this?

 

Thanks in advance,

Wugge

 

0 5 5,612
5 REPLIES 5

Please Edit your user Account and grant it the Editor or Administrator role.[1][2]

[1] https://support.google.com/analytics/answer/9305788#zippy=%2Cin-this-article

[2] https://cloud.google.com/iam/docs/service-accounts

 

 

when i do this is not able to copy files and not able to delete files

For any of those still looking for the answer to this, it's due to how shared drives and specifically content managers work with file deletion. The files().delete request bypasses the trash, however content managers don't have access to "clear trash" so that returns the insufficient permissions error. In the drive api v3, the files().trash request was removed, but you can still have the same effect by using the files().update request. With the update request, you just need to include {"trashed": True} in the request body.  Just also make sure that as a parameter of the request, you include supportsAllDrives=true so it works with the shared drives. 

Another possible solution that I did not test is changing the service account to "manager" instead of "content manager" as managers have the permissions to delete files from the trash. 

I have the same problem and I tried to do as you said, but unfortunately I have the same error. Could you describe in more detail how it all works. Thank you in advance!)

hello. can you give me your code. please