DEV Community

Joakim Nystrom
Joakim Nystrom

Posted on

Changing ownership for files using Google Drive v3 API

This is just a warning fellow developers to waste hours to come to the same conclusion as I did.

With the v3 version of the Drive Api one cannot transfer ownership for files and folders using the Api for users using gmail.com.

If it's within a Workspace accounts you might pull it off. However, since approval is needed for transfer these days, you need to modify the permission request

// 💾 The old way
 const transaction = await drive.permissions.create({
        fileId: fileId, 
        resource: {
          role: "owner", // easy-peasy....
          type: "user",
          emailAddress: newOwnerEmail,
        }
      });
Enter fullscreen mode Exit fullscreen mode
// 🙄 The new way
 const transaction = await drive.permissions.create({
        fileId: fileId, 
        resource: {
          role: "writer", // Share it to the new owner
          type: "user",
          emailAddress: newOwnerEmail,
          domain: 'everything-but-gmail.com',
        },
        transferOwnership: true, // In order to make a request for approval
      });
Enter fullscreen mode Exit fullscreen mode

Hope this helps anyone out there!

Top comments (0)