Skip to main content

Zapier doesn't have an action to delete files in Google Drive. Would it be possible to achieve this using Code?


It seems as though it might be possible to do. The first challenge is to understand whether the Google Drive API permits deleting files. A cursory search of their API documentation yields a couple of results:

Files: update  |  Google Drive API

 |  Google Developers
According to that page, the "update" method allows for the "Trashed" property to be modified. This appears to mean that a file can be placed in the trash via the API.

Files: delete  |  Google Drive API

 |  Google Developers
The "delete" method skips the trash and permanently deletes the item. This is a bit more dangerous, for obvious reasons.

In either case, it appears that the user account which is used to authenticate to the Google Drive API must be the "owner" of the file in question. There are some other similar details to watch out for.

But these entries lead me to believe that since the Drive API permits these actions, they might be achievable via Code. The next challenge would be to sort out how to properly authenticate to the API. That is one of the more complex elements that is handled nicely by Zapier for the methods they support. It would take digging into this a bit more deeply to understand how difficult the authentication step would be.

I hope this helps!



Thanks a lot, @TheDavidJohnson. I'll certainly read all of that.



You're welcome, @Martinewski!

Also: it just so happens that your timing is impeccable. I've just been tinkering with a custom Google Drive Integration to do a few things that the standard Zapier integration doesn't do. It wouldn't be difficult to add the functionality that you asked about. If you're interested in testing this for me, please PM me. Thanks!



@TheDavidJohnson Ooo sounds interesting! I'd love to hear more about the functionality you're building within your own integration and all of the places where the current Google Drive integration falls short so we can look into addressing this.



Sure @jesse! I had a client approach me with a need to share an item in Google Drive only with specific users. Google's API allows the creation of permissions based upon email address, but that option isn't exposed in the standard Zapier integration—and probably with good reason. So far my integration has an action step to create an "Edit" permission for one user based upon email address, and then it has a separate action that allows a given permission to be converted into a "View" (read-only) permission. These are pretty specific to the use cases that the client needed, but I have plans to add a few other goodies for other purposes.

The integration is private (invite-only) for now on the Zapier side of things, and it's untrusted/unverified at the moment from Google's side of things (which basically means Google throws a big warning on the consent screen when someone tries to authenticate with it), but I'm happy to share it with a few people if someone needs those functions—at least as long as we don't start bumping up against my quota with Google's API 😂

Edit: Details on this integration here.



@TheDavidJohnson I am also interested in your Google Drive custom integration, please PM me as I'd be happy to test.

One area that is frustrating/lacking is the ability to "move a folder" or "rename a folder". I can't seem to find moving a folder anywhere in the Google Drive API docs, shockingly. Just the ability to move files.

@jesse how does Zapier feel about this "custom integration Zapier plugin" route? Keeping it private is one thing (that I'm sure you're fine with), but making it more public, or even sharable access, does Zapier draw any lines here? Say David spends a lot of time building this thing out and eventually charges for it, will your team see it as a conflict of interest because Google Drive already has a native integration (even though it's limited in the areas described and not likely to be updated anytime soon?)

Have been wondering this because we experience the same thing with Asana. No one is taking the reigns, so if we say built something, would we be able to monetize it direct to our customers, essentially a private Zapier integration? Because I'm guessing there's nearly a 0% chance that you'd ever allow something like this to be a "public" integration?

Thanks so much!

Alex



Hey @alex!

So, there is no way to take a private integration public through our platform unless the person building the integration/app is the owner of the API. Also, we don't allow anyone to sell access to an invite-only Zapier app in a public capacity, as it competes with our offering and may be confusing to users. Hope that helps to add some clarity!



Hey @alex — apologies for the delay! I'm just seeing the latest stuff from this thread just now. PM coming your way shortly!

Also: great question about public vs. private and monetization. Frankly, I can't have too many people using a custom integration that hits Google's APIs via my account because we'll start to hit some cost thresholds. But having a few people test it out and maybe make some recommendations about enhancements is certainly useful.

Thanks also, @jesse, for the insights. Those policies certainly make sense!



Hey @Martinewski --

Sorry I didn't catch this thread earlier! Any luck yet?

FWIW, the short answer is to your question is almost certainly. Anything you can do via API (e.g. via Postman) you should be able to do via the Code by Zapier (if that's what you meant by Code with a capital C.) But @TheDavidJohnson's answer is fair: there may be something pesky about the authorization token. I did some Google integration a few years ago, but I haven't tried any Zapier, because I haven't had a call for anything outside the native integration.




Hey @alex! --

Sorry I didn't catch this thread earlier, I don't know if this will still be helpful to you...

<Insert snarky GIF about preparing for something that will blow your mind😵>

The fundamental reason you can't "move a folder" or "rename a folder" in Google Drive API is they aren't really folders at all, they're essentially tags (with essentially a hidden part of the tag that represents the parentage.) But if you don't understand that folders are really tags, you can encounter a lot of strange and confusing things.

(FYI, I haven't tried this in a while, things may have changed, but I doubt it.)

For example, you delete a file from a folder. Did you delete the file? In a real folder yes. In google drive, you really just removed a tag. Some of these are addressed by the UI. For example, if you delete a file from a shared folder via the UI, google may warn you other users may also have that file in other folders (and provide instructions to really delete the file.) Wait, what? Do they mean a shortcut? Nope! In google drive, the exact same file, not duplicates or a shortcut, can exist in multiple folders... because they're not folders, they're tags.

So with this paradigm, "rename a folder" wouldn't be as simple as in a standard OS. Since it's really a tag, you have to find every file with that tag, remove that tag, and tag it with the name of the new "folder." (i don't remember if there was something specifically for "moving a file" , if so, that removing a tag and adding a new one is essentially what it's doing.)

In a standard OS, moving a folder is just changing it's parent. In google drive, moving a folder is essentially the same as "renaming a folder": once again, you have to find every file with that tag, remove that tag, and tag it with the name of the new "folder" ... which appears to be the same, but isn't, since it has a different hidden part of the tag that represents the parentage.

Hope the paradigm shift helps clarify things!



@john_fohrman really wish the community had alerts, just seeing this now!

And... Wow... 🤯

That was incredibly helpful and insightful! Thank you so much for clarifying! So while it sucks that this doesn't seem possible in the current API, I now understand why it's so much more of a pain than I would typically expect it to be.

Thank you my friend! I'm seeing you a bunch here now! Glad to have you here! ☺️

Cheers!



Thank you, @alex, and thanks for your contributions as well! Look forward to seeing you around here as well, all the best!