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!

Image of Datadog

How to Diagram Your Cloud Architecture

Cloud architecture diagrams provide critical visibility into the resources in your environment and how they’re connected. In our latest eBook, AWS Solution Architects Jason Mimick and James Wenzel walk through best practices on how to build effective and professional diagrams.

Download the Free eBook

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more