Google Drive (Apps step)
Google Drive
Finds files in Google Drive, reads their details and downloads them.
Use it to pick up files people drop in Google Drive: a supplier's price list in a shared folder, drawings to attach to a document, or a daily export to load into another system.
Beta. This step has not yet been checked against a live Google Drive account, so treat its first runs as a test, and tell us if an operation does not answer as described.
Find it in the workflow editor's palette under Apps. See Apps steps for what every Apps step has in common.
Set it up
- In Google Cloud Console, choose or create a project, open APIs & Services › Library and enable the Google Drive API.
- Open APIs & Services › OAuth consent screen and set it up; for a Google Workspace company choose Internal, so the sign-in does not expire. An External app left in Testing must list the signing-in account as a test user, and Google ends its sign-in after 7 days.
- Open APIs & Services › Credentials › Create credentials › OAuth client ID, choose Web application, and keep the client ID and client secret for the DataMagik credential. The same client can serve Google Sheets and Gmail too.
- Add www.googleapis.com to Allowed Domains in the workflow's Script settings.
Credential: An OAuth 2.0 credential for your Google OAuth client, connected with the Google account whose Drive files the step reads.
Signing in with OAuth 2.0
| Grant type | Sign in with the provider (authorization code). Save the credential, then click Connect on it. |
| Sign-in (authorization) URL | https://accounts.google.com/o/oauth2/v2/auth |
| Token URL | https://oauth2.googleapis.com/token |
| Scope | https://www.googleapis.com/auth/drive |
Register the Redirect URI the credential form shows in the provider's app settings.
Create the OAuth client in Google Cloud Console as type Web application, enable the Google Drive API in the same project, and add the Redirect URI the DataMagik credential shows to the client's Authorized redirect URIs.
Hosts it calls: www.googleapis.com
Operations
| Operation | What it does |
|---|---|
| File › List | Finds files with a Drive search query, following every page up to the step's page limit. |
| File › Get | Reads one file's details by its id. |
| File › Download | Downloads an uploaded file's contents (not Google Docs, Sheets or Slides files, which must be exported). |
File › List
Finds files with a Drive search query, following every page up to the step's page limit.
Calls GET /files. Follows the pages, up to Most pages (10 unless you change it).
| Field | Required | What to put |
|---|---|---|
| Query | No | A Drive search query, such as name contains 'scrap' and mimeType = 'application/pdf'. Leave empty to list every file the account can see. For example '1AbCdEfGh' in parents and trashed = false. |
| Fields to return | No | Which details Drive sends. Keep nextPageToken in it, or only the first page is read; add more inside files(…), such as webViewLink or parents. |
| Page size | No | Files per request (Drive's limit is 1000). For example 100. |
What comes out: One item per file, with the details asked for in Fields to return: by default {{ $json.id }}, {{ $json.name }}, {{ $json.mimeType }}, {{ $json.modifiedTime }} and {{ $json.size }} (in bytes, as text; missing for folders and Google Docs files).
Example: List mimeType = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' and '1AbC…' in parents to find every Excel file in the Pricing folder.
File › Get
Reads one file's details by its id.
Calls GET /files/{fileId}.
| Field | Required | What to put |
|---|---|---|
| File ID | Yes | The file's id: {{ $json.id }} from List, or the long part of the file's address. For example 1AbCdEfGhIjKlMnOpQrStUvWxYz. |
| Fields to return | No | Which details Drive sends, comma-separated; * sends every detail. |
What comes out: One item: the file, with the details asked for, by default {{ $json.id }}, {{ $json.name }}, {{ $json.mimeType }}, {{ $json.modifiedTime }}, {{ $json.size }}, {{ $json.webViewLink }} (its address in Drive) and {{ $json.parents }}.
Example: Get {{ $json.drive_file_id }} to put its name and webViewLink in a notification email.
File › Download
Downloads an uploaded file's contents (not Google Docs, Sheets or Slides files, which must be exported).
Calls GET /files/{fileId}. Puts out the downloaded file in {{ $json.file }}.
| Field | Required | What to put |
|---|---|---|
| File ID | Yes | The file's id: {{ $json.id }} from List, or the long part of the file's address. For example 1AbCdEfGhIjKlMnOpQrStUvWxYz. |
| Download | No | Leave as File contents: it tells Drive to send the file itself instead of its details. One of: File contents. |
What comes out: One item: {{ $json.file }}, the downloaded file (with filename, mimeType and size), ready for Read Excel, Send Email attachments or another upload, plus {{ $json.status }}. When Drive sends no file name with the contents, the filename is the file's id with an extension from its type, so take the real name from List or Get.
Example: Download each file List found in the Receiving folder and pass {{ $json.file }} to a Read Excel step.
Trigger: Google Drive: New Items
Under Triggers in the palette. It looks at Google Drive on a schedule (every 15 minutes unless you change Look every) with one of these operations: File › List, and starts the workflow with the items it has not seen on an earlier look, one item each. Saving the workflow sets up the schedule.
- New means: not seen before, by the item's id (or the field you name in Item field), or newer than the newest one last time, by a date or increasing number.
- On the first run it only remembers what is there, unless you choose Start with everything.
- Test runs show what would be new without remembering it. It remembers the last 5000 ids, so filter the list to keep it shorter than that.
Example
A schedule runs each morning; Google Drive › List files with the query '1AbC…' in parents and trashed = false finds the files in the Receiving folder, and Download fetches each one for a Read Excel step.
Tips
- The query uses Drive's search syntax: name contains 'price list', mimeType = 'application/pdf', '<folder id>' in parents and trashed = false. Combine terms with and.
- A file's or folder's id is the long part of its address: 1AbC…xyz in drive.google.com/drive/folders/1AbC…xyz.
- Google Docs, Sheets and Slides files have no file contents to download; they must be exported, which this step does not do. Download works for uploaded files such as PDF, Excel and images.
- For files on a shared drive, add supportsAllDrives = true (and for List, includeItemsFromAllDrives = true and corpora = allDrives) under More query parameters.
- A download is held in the run, so files larger than 10 MB cannot be downloaded here.
Settings every Apps step has
- More query parameters: any query parameter the fields do not offer, sent as is.
- More body fields: a JSON object merged into the request body; nested objects merge, other values replace.
- Most requests per second: spaces the calls out for rate limits. A "too many requests" (429) answer is retried after the wait the API asks for.
- Most pages: for operations that follow pages, the most pages to fetch (10 unless you change it, up to 100). The run warns when it stops with more to get.
- Fail on a non-2xx response: on by default. Turn it off to handle errors yourself.
Google Drive's own API documentation: https://developers.google.com/drive/api/reference/rest/v3