# Google Drive

Send and retrieve data from Google Drive

## Overview

Get access to files anywhere through secure cloud storage and file backup for your photos, videos, files and more.

## API Information

The Google Drive connector has the following Base URL: **<https://www.googleapis.com/drive/v3>**. More information can be found on their main [API documentation (v3)](https://developers.google.com/drive) site. Details regarding their API limitations can be found [here](https://developers.google.com/drive/api/guides/limits).

## Authentication

Within the builder, click on the Google Drive connector to display the connector properties panel. Select the **Auth** tab and click on the **New authentication** button.
In the Tray.io authentication pop-up modal name your authentication in a way that will quickly identify it within a potentially large list. For example whether it is a Sandbox or Production auth, etc.
Consider who/ how many people will need access to this authentication when choosing where to create this authentication ('Personal' vs 'Organisational').
The next page asks you to set the scopes for your authentication. Select these depending on your project needs.
![google-drive-scopes](https://tray.ai/documentation/images/connectors/service/google-drive/a38d4d77-93dad1c4_alksdjfh.png)
Once you have added these fields to your Tray.io authentication pop-up window click the **Create authentication** button. 
Your connector authentication setup should now be complete. Please run the simplest operation available to test and make sure you can retrieve data as expected.

## Note on Operations usage

### Sharing permissions

If you wish to share or give people access to different components of the Google suite (such as Google Sheets, Docs, or Calendar), note that permissions for granting access fall under the capabilities of the Google Drive connector. Here’s how you can do it:
Add the Google Drive Connector to Your Workflow Select the 'Create permission' operation to specify the kind of access you wish to grant your user(s).
**Set Up Parameters**

* **File ID**: Enter the ID of the Google file you want to share.
  You can find the ID in your document's URL. It is the string between `/d/` and `/edit`
  * Consider this is your file's URL: `https://docs.google.com/spreadsheets/d/1aBcD1234EfGhIjKlMnOpQrStUvWxYz1234567890/edit`
  * The id is the string between `/d/` and `/edit`: `1aBcD1234EfGhIjKlMnOpQrStUvWxYz1234567890`
* **Email Message**: Optionally, include a message to the recipient.
* **Send Notification Email**: Choose whether to send a notification email to the recipient.
* **Transfer Ownership**: Decide if you want to transfer ownership of the file.
* **Use Domain Admin Access**: Enable this if you are using domain-level admin access.
* **Role**: Select the role you want to assign (e.g., Viewer, Commenter, Editor).
* **Grantee Type**: Choose the type of grantee:
  * **User or Group**: Requires an email address for the user or group.
  * **Domain**: Requires a domain.
  * **Anyone**: No additional information is required.
* **Allow File Discovery**: Choose whether to allow the file to be discoverable.
* **Email Address**: Provide the email address of the user or group you are sharing the file with.
  ![google-drive-create-permissions](https://tray.ai/documentation/images/connectors/service/google-drive/3KSGGDuh4ymD6F0v3Af9eO_google-drive-create-permissions.png)

### List Spreadsheets & Google Drive

> **Warning:** **IMPORTANT!**: You now **need to use the Google Drive connector in conjunction with the Google Sheets connector** in order to list all available spreadsheets from within a user's account.
> **This update effectively breaks all / any previous workflows that were dependent upon this ability within the Google Sheets connector.**

Due to security updates from Google we have had to separate the ability to **List Spreadsheets** from the Google Sheets connector itself.
This operation now resides in the Google Drive connector in its entirety.
If you have a workflow which uses an old version of Google Sheets (one where the List spreadsheets operation is still available) we recommended revising your workflow in one of the following ways to avoid any potential downloading or security issues:

1. **Retrieve multiple sheets**: Add a Google Drive connector to an earlier point within your current workflow.

* Select List spreadsheets from the operations list.
* Set it up in conjunction with your Google Sheets user.

2. **Retrieve a single sheet**: Select via sheet ID

* Put the Google Sheet ID into the relevant operation field.

### Download types

> **Warning:** **IMPORTANT!**: There is a difference between **Download File** vs **Download Google File**.

You must make sure you accurately set / know your file type before selecting a download operation. **Incorrect setup will result in a failed workflow run**.
Here are some examples of when it is best to use each:

* **Download Google file**:
  * To \*\*export a Google document \*\*for use in other services or programme (such as MS word etc).
  * When downloading a file you can specify the file type. For example you can choose 'rich text' to convert a Word document to rich text format for simple downstream processing in your workflow.
* **Download file**:
  * To **download a file from your Drive that is in an** **unrecognised file format**. One that Google Drive does not support. It will only need the Google file ID.

## Example Usage

Below is an example of a way in which you could potentially use the Google Drive connector to download a Google Drive file for later use.
The basic logic of the workflow is as follows:

1. Setup using a manual trigger and use a Google Drive connector to list your files.
2. Download said file to the current run.
3. Use the CSV Editor to download the specified file.
   Your completed workflow should look similar to this:
   ![google-drive-complete-workflow](https://tray.ai/documentation/images/connectors/service/google-drive/a38d4d77-8ae2448c_asfljkhg.png)

### 1 - Setup Manual trigger & Get file ID

Once the **Manual Trigger** is in place set the Google Drive connector to **List files**.
**Your Source property will depend on your Drive structure and where the file you wish to download is located.** Note that the **Drive ID** is only required if the aforementioned **Source** is set to -> **Drive**.
If you know the file you are looking for you can speed up your query by utilising both filter options i.e. **Filter by Folder** and **Filter by Name**.

> **Info:** **PLEASE NOTE**: The drop down for **Filter by folder** will only show a limited number of your potential options. This is because the operation itself cannot paginate your list once it hits a certain number.
> You may need to use the ID of the folder in order to specify it as shown here.

![google-drive-step-1](https://tray.ai/documentation/images/connectors/service/google-drive/a38d4d77-d489a109_alskdjfh%20%281%29.png)

### 2 - Download file

Set your next Google Drive connector operation to **Download Google file**.
Remember that t**he Download file and Download Google file operations are not interchangeable**. If you dont chose the right one this workflow will fail.
You must also choose the **File Type** before continuing.
![google-drive-step-2](https://tray.ai/documentation/images/connectors/service/google-drive/a38d4d77-6bf8025a_Untitled%2012.32.17.png)

### 3 - Create CSV

Using a **CSV Editor** set the operation to **Create CSV From File**.
The file is only needed for short term storage so the \*\*Scope \*\*is set to **Current run**. This will mean that the file created will remain in a temporary status and not be 'held anywhere'. Once the workflow has completed its run it will 'disappear' from short term storage.
The downloaded the file from our earlier step came with a **File URL** which we can now jsonpath to.
When run the workflow will create a simple CSV file from the original Google file. One that remains in scope and can be manipulated and edited within and across workflows.
![google-drive-step-3](https://tray.ai/documentation/images/connectors/service/google-drive/a38d4d77-dee88a99_adslfkjh.png)
