---
related_nodes: ["gmail", "google_calendar", "google_docs", "google_sheets", "google_slides"]
---

# Google Drive

Manage files, folders and sharing in Google Drive from workflows.

## When to Use

- Automating file uploads from workflow outputs
- Downloading files, or exporting Google Docs, Sheets and Slides, for processing
- Renaming, moving, copying and replacing the content of files
- Organizing files into folders automatically
- Trashing, restoring and deleting files
- Sharing files with people, groups, a domain or anyone with the link, and taking access away

## How It Works

The Google Drive node runs one Drive operation, picked from the list. The same operations back the `google_drive` agent tool group and the `verdalia.api.drive` script module.

Before using this node, add a Google OAuth connection in **Settings → Connections** and grant Google Drive access.

## Configuration

**connection** - Google connection to use
- Select from Settings → Connections
- Agents should call `list_connections` and set `connection` to the returned `id` ULID
- Use `name` only for display; node configuration needs the `id`
- Must be a "google" connection type holding the `drive` scope; a call it lacks the scope for fails with an error asking to reconnect the account
- Required

Validation notes:
- The node validates that `connection` is selected when you save.
- Operation fields are evaluated at runtime after interpolation. A blank required id (`file_id`, `permission_id`, a destination folder, a share address) fails before Drive is called.

**operation** - Operation to perform
- `list_files`: List files in a folder
- `search_files`: Search files by name
- `get_file`: Get file metadata
- `download_file`: Download file content
- `export_file`: Export a Google Docs, Sheets or Slides file to pdf, docx, xlsx or pptx
- `upload_file`: Upload a new file
- `create_folder`: Create a folder
- `update_file`: Rename a file, change its description, or replace its content
- `move_file`: Move a file to another folder
- `copy_file`: Duplicate a file
- `trash_file`: Move a file to the trash
- `untrash_file`: Restore a file from the trash
- `delete_file`: Delete a file, to the trash or for good
- `list_permissions`: List who a file is shared with
- `add_permission`: Share a file
- `update_permission`: Change the access one permission grants
- `remove_permission`: Remove one permission

### Operation: List Files

**folder_id** - Parent folder ID
- Empty lists across all of Drive
- Interpolatable from input
- Optional

**query** - Additional query filter
- Drive API query syntax, kept as one group: `'<folder>' in parents and trashed=false and (<query>)`
- Example: `"mimeType='application/pdf'"`
- Interpolatable from input
- Optional

**options** - Repeatable request modifiers
- Optional key/value rows
- Supported key: `page_size`

### Operation: Search Files

**query** - Search text
- Matches file names (`name contains`); quotes in the text are escaped
- Example: `"report"` matches "Q1 Report.pdf"
- Interpolatable from input
- Optional (leave empty to list non-trashed files)

**options** - Repeatable request modifiers
- Optional key/value rows
- Supported keys: `page_size`, `mime_type`

### Operation: Get File

**file_id** - File ID
- The `id` field from ListFiles output
- Interpolatable from input
- Required

### Operation: Download File

**file_id** - File ID
- Interpolatable from input
- Required

**options** - Repeatable request modifiers
- Optional key/value rows
- Supported key: `export_format` (`pdf`, `docx`, `xlsx`, `pptx`). With it set, a Google Docs, Sheets or Slides file is exported to that format, and any other value fails; any other file downloads as stored and the option is ignored. New workflows use `export_file` instead.

**destination** - Where the content goes, by `to`
- `output` (default): the node's output, as below. A config saved without `destination` reads as `output`.
- `library`: saved straight into a Library item as it downloads, never held whole, up to 2 GiB. The node outputs the item's object descriptor. A file Drive reports over 2 GiB is refused before downloading, and the saved bytes are checked against the size and SHA-256 Drive reports; a mismatch leaves nothing behind.
  - `name`: the item's name; empty takes the Drive file's name. Interpolatable.
  - `place`: defaults to Folder (`folder`). Choose Other (`other`) to file the item outside every folder.
  - `folder`: folder slugs or ids from the Library root, separated by `/`, with interpolation. Every folder must already exist. Use the Library node's Create Folder first if you need a new folder.

**Output**: File name, content MIME type, and the content as runtime binary in `content`; with `destination` `library`, the Library item's object descriptor

### Operation: Export File

**file_id** - ID of a Google Docs, Sheets or Slides file
- Interpolatable from input
- Required

**format** - `pdf` (default), `docx`, `xlsx` or `pptx`

**destination** - As for Download File. With `library`, the export is saved under the Drive file's name unless `name` is set; Drive reports no size or checksum for an export.

**Output**: Same shape as Download File, with `mime_type` the export format's

### Operation: Upload File

**name** - File name
- Example: `"document.pdf"`
- Interpolatable from input
- Required

**mime_type** - MIME type
- Example: `"application/pdf"`
- Default: `application/octet-stream`
- Interpolatable from input
- Optional

**content** - File content
- Accepts runtime binary data, for example `{{ input.file }}` from a previous file-producing node
- Also accepts base64 text at the final upload boundary
- Interpolatable from input
- Required

**options** - Repeatable request modifiers
- Optional key/value rows
- Supported key: `folder_id`

### Operation: Create Folder

**name** - Folder name
- Example: `"Project Documents"`
- Interpolatable from input
- Required

**options** - Repeatable request modifiers
- Optional key/value rows
- Supported key: `parent_id`

### Operation: Update File

Blank fields leave that part of the file as it is.

**file_id** - File ID
- Interpolatable from input
- Required

**name** - New name, to rename the file
- Optional

**description** - New description
- Optional

**content** - New content, as runtime binary or base64 text
- Optional

**mime_type** - MIME type of the new content
- Default: `application/octet-stream`
- Optional; used only with `content`

### Operation: Move File

**file_id** - File ID to move
- Interpolatable from input
- Required

**destination_folder_id** - Destination folder ID
- The file leaves every folder it is in now
- Interpolatable from input
- Required

### Operation: Copy File

**file_id** - File ID to copy
- Interpolatable from input
- Required

**options** - Repeatable request modifiers
- Optional key/value rows
- Supported keys: `destination_folder_id`, `new_name`

### Operation: Trash File / Untrash File

**file_id** - File ID
- Interpolatable from input
- Required

### Operation: Delete File

**file_id** - File ID to delete
- Interpolatable from input
- Required

**options** - Repeatable request modifiers
- Optional key/value rows
- Supported key: `permanent` (`true` or `false`, default `false`). Without it the file goes to the trash; with it the file is deleted for good.

### Operation: List Permissions

**file_id** - File ID
- Required

### Operation: Add Permission

Sharing notifies other people: Google emails a user or group unless `notify` is off.

**file_id** - File ID
- Required

**grantee** - Who gets access, by `type`:
- `user`: `email_address`
- `group`: `email_address`
- `domain`: `domain`, such as `example.com`
- `anyone`: anyone with the link

**role** - `reader` (default), `commenter`, `writer`, `fileOrganizer` or `organizer`

**notify** - Email a user or group about the share
- Default: `true`; never sent for a domain or anyone

**message** - Message for the notification email
- Optional; only sent when notifying

### Operation: Update Permission

**file_id** - File ID
- Required

**permission_id** - The permission's `id` from List Permissions
- Required

**role** - The access it grants from now on

### Operation: Remove Permission

**file_id** - File ID
- Required

**permission_id** - The permission's `id` from List Permissions
- Required

### Retry

**retry** - Whether each Drive request is sent again after a failure that passes: a rate limit, a busy server, a dropped connection. Off by default; see [Retries](http_get.md#retries) for how attempts and waits work. Listing, search, get, download, export and listing permissions are reads, sent again freely, as are Delete File with `permanent` and Remove Permission, where a repeated delete can answer "not found" because the first attempt worked. Upload, create folder, update, move, copy, trash, untrash, Delete File without `permanent` (which moves the file to the trash), and adding or changing a permission are writes, sent again only when Google refused them before acting: the connection never opened, or Google answered 425 or 429. The `google_drive` tool group takes the same setting.

## Inputs

**input** - Any input
- Used to trigger the node
- Data can be accessed for template interpolation
- Required

## Outputs

**output** - Drive's response, in Drive's field names

Get File:
```json
{
  "id": "1abc2def3ghi4jkl5mno6pqr7stu8vwx9yz0",
  "name": "Document.docx",
  "mimeType": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
  "size": "524288",
  "createdTime": "2024-03-15T10:30:00Z",
  "modifiedTime": "2024-03-15T14:20:00Z",
  "parents": ["0B123456789abcdef0"],
  "webViewLink": "https://drive.google.com/file/d/1abc.../view",
  "webContentLink": "https://drive.google.com/uc?id=1abc...&export=download",
  "description": "Project documentation"
}
```
`size`, the dates, links and `description` appear when Drive has them.

List Files and Search Files: `{"files": [<file>, ...]}`, each file with `id`, `name`, `mimeType`, `size`, `createdTime`, `modifiedTime`, `parents` and `webViewLink`.

Upload File, Create Folder, Update File, Move File, Copy File, Trash File, Untrash File:
```json
{
  "kind": "drive#file",
  "id": "1abc2def3ghi4jkl5mno6pqr7stu8vwx9yz0",
  "name": "Document.docx",
  "mimeType": "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
}
```

Download File and Export File:
```json
{
  "name": "Document.pdf",
  "mime_type": "application/pdf",
  "content": "<runtime binary>"
}
```

Download File and Export File with `destination` `library`: the saved item's object descriptor, with kind-specific `metadata` beside these fields:
```json
{
  "object_id": "01J...",
  "kind": "video",
  "content_type": "video/mp4",
  "filename": "clip.mp4",
  "size_bytes": 495773445
}
```

Delete File:
```json
{"deleted": true, "permanent": false, "file_id": "1abc2def3ghi4jkl5mno6pqr7stu8vwx9yz0"}
```

A permission (Add Permission, Update Permission):
```json
{
  "id": "01234567890123456789",
  "type": "user",
  "role": "writer",
  "emailAddress": "sam@example.com",
  "displayName": "Sam Lee"
}
```

List Permissions: `{"permissions": [<permission>, ...]}`

Remove Permission: `null`

## Agent tools

The `google_drive` tool group offers `drive_list_files`, `drive_search_files`, `drive_get_file`, `drive_view_file`, `drive_upload_file`, `drive_create_folder`, `drive_update_file`, `drive_move_file`, `drive_copy_file`, `drive_trash_file`, `drive_untrash_file`, `drive_delete_file`, `drive_list_permissions`, `drive_add_permission`, `drive_update_permission` and `drive_remove_permission`. Each has a switch that defaults on. Tool names carry the connection's handle (`google_freja__drive_list_files`).

- [View Drive File](/docs/tools/GoogleDriveViewFileTool) opens the file for the agent to inspect. Docs, Sheets, Slides and Drawings open as PDFs. The `view_file` switch reads saved `download_file` settings; the old `export_file` switch no longer applies.
- List, search, get, view and list permissions are reads. Upload, create folder, update, move, copy and untrash are writes. Adding, changing and removing a permission are sends. Trash and delete are destructive.

## Examples

### Upload File from Form

```
[Form Trigger: File upload]
  → Form data with file

[Google Drive: UploadFile]
  Config:
    name: {{input.form.file.name}}
    mime_type: {{input.form.file.type}}
    content: {{input.form.file}}
    options:
      - key: folder_id
        value: "0B123456789abcdef0"
```

### Export a Report and Share It

```
[Google Drive: SearchFiles]
  Config:
    query: "Q3 report"
    options:
      - key: mime_type
        value: "application/vnd.google-apps.document"
  → Matching files

[Google Drive: ExportFile]
  Config:
    file_id: {{input.files[0].id}}
    format: pdf
  → File object with binary content

[Google Drive: AddPermission]
  Config:
    file_id: {{input.files[0].id}}
    grantee: {type: user, email_address: "sam@example.com"}
    role: commenter
```

### Organize Files by Date

```
[Google Drive: ListFiles]
  Config: folder_id: "source_folder_id"
  → Files to organize

[Branch: For each file]
  → file.id, file.name, file.createdTime

[Google Drive: CreateFolder]
  Config:
    name: {{year}}
    options:
      - key: parent_id
        value: "archive_folder_id"

[Google Drive: MoveFile]
  Config:
    file_id: {{file.id}}
    destination_folder_id: {{folder.id}}
```

## Runtime Errors

| Error | Cause | Remediation |
|-------|-------|-------------|
| Connection not selected or unavailable | `connection` is empty or does not point to a usable Google connection | Use `list_connections`, then set `connection` to the returned `id` ULID |
| This Google connection does not have Google Drive access | The connection lacks the `drive` scope | Reconnect the Google account and allow Google Drive |
| Google Drive could not find the requested item | Invalid file, folder or permission ID | Verify the ID from List Files or List Permissions output |
| content is not valid base64 | Upload content is not valid base64 text | Pass runtime binary data or valid base64 text |
| The export_format option must be pdf, docx, xlsx or pptx | A Google file is downloaded with another `export_format` | Use one of those, or `export_file` |
| This Drive file is … bytes; a download saved into the Library holds at most … bytes | Download File with `destination` `library` on a file over 2 GiB | Save a smaller file; the Library takes downloads up to 2 GiB |

## Common Mistakes

- **Mistake**: Downloading a Google Doc, Sheet or Slides file
  - Error: Drive refuses, because these have no stored content
  - Fix: Use `export_file`

- **Mistake**: Passing an object instead of binary data to UploadFile
  - Error: "content must resolve to runtime binary or base64 text"
  - Fix: Pass a binary value such as `{{ input.file }}` or base64 text

- **Mistake**: Using file names instead of file IDs
  - Fix: Use the `id` field from ListFiles, not the `name`

- **Mistake**: Removing access by email address
  - Fix: List Permissions first and pass the permission's `id`

## Tips

- Binary files (PDFs, images) download directly; Google's own formats export
- The `parents` field is an array - files can have multiple parents
- Use `webViewLink` to give users a link that opens the file
- Folder IDs work the same as file IDs - a folder is a file with MIME type `application/vnd.google-apps.folder`
- Trash is recoverable for 30 days; permanent delete cannot be undone
