Google Drive Component

Manage files in Google Drive
Component key: google-drive#
DescriptionGoogle Drive is Google's cloud storage for work and home. This component allows you to create, copy, download, update, list, and delete files stored in a Google Drive Account.
Documentation for the Node.js client used in this component can be found at https://developers.google.com/drive/api/v3/quickstart/nodejs.
A common integration pattern involves listing files in a file store, and performing a series of actions on the array of files that are returned. See our looping over files quickstart for information about how to create a loop over an array of files.
#
Tracking Changes in Google DriveTo track changes within Google Drive, use the List Changes action with a schedule trigger. You can have your integration run on a schedule (say, once every 5 minutes), look for changes since it last ran, and execute on those changes.
#
Google Drive Connections#
OAuth2The Google Drive component authenticates requests through the Google Cloud Platform (GCP) OAuth 2.0 service. You'll need to create a GCP OAuth 2.0 app so your integration can authenticate and perform Google Drive tasks on your customers' behalf.
To create a Google Drive OAuth 2.0 app, first make sure you have a Google Developer account - you can sign up at https://console.cloud.google.com/. Then:
- Open up the Google Drive API console - https://console.cloud.google.com/apis/api/drive.googleapis.com
- Click CREATE PROJECT if you would like to create a new GCP project, or select an existing project.
- You will be prompted to enable Google Drive API for your project. Click ENABLE.
- On the sidebar, select Credentials.
- An OAuth 2.0 app includes a "Consent Screen" (the page that asks "Do you want to allow (Your Company) to access Google Drive on your behalf?"). Click CONFIGURE CONSENT SCREEN.
- Your app will be externally available to your customers, so choose a User Type of External.
- Fill out the OAuth consent screen with an app name (your company or product's name), support email, app logo, domain, etc.
- You can ignore domains for now.
- On the next page, ignore scopes - this component knows what scopes it needs to run and will request the right scopes for you.
- Enter some test users for your testing purposes. Your app will only work for those testing users until it is "verified" by Google. When you are ready for verification (they verify your privacy policy statement, etc), click PUBLISH APP on the OAuth consent screen. That'll allow your customers to authorize your integration to access their Google Drive.
- Once your "Consent Screen" is configured open the Credentials page from the sidebar again.
- Click +CREATE CREDENTIALS and select OAuth client ID.
- Under Application type select Web application.
- Under Authorized redirect URIs enter Prismatic's OAuth 2.0 callback URL:
https://oauth2.prismatic.io/callback
- Click CREATE.
- Take note of the Client ID and Client Secret that are generated.
info
Make sure to publish your OAuth 2.0 app after you've tested it so users outside of your test users can authorize your integration to interact with Google Drive on their behalf.
Now that you have a Client ID and Client Secret, add Google Drive step to your integration in Prismatic.
Open the Configuration Wizard Designer by clicking Configuration Wizard, select your Google Drive Connection and enter your client ID and secret.
You will probably want to keep the default Google Drive scope, https://www.googleapis.com/auth/drive
.
Input | Default | Notes |
---|---|---|
Input Authorize URL string / Required Hidden Field | Default https://accounts.google.com/o/oauth2/v2/auth?access_type=offline&prompt=consent | Notes The Authorization URL for Google Drive. |
Input Client ID string / Required | Default | Notes The Google Drive app's Client Identifier. |
Input Client Secret password / Required | Default | Notes The Google Drive app's Client Secret. |
Input Scopes string / Required | Default https://www.googleapis.com/auth/drive | Notes Space delimited listing of scopes. https://developers.google.com/identity/protocols/oauth2/scopes#drive |
Input Token URL string / Required Hidden Field | Default https://oauth2.googleapis.com/token | Notes The Token URL for Google Drive. |
#
Actions#
Copy FileCopy a file by file id | key: copyFile
Input | Notes | Example |
---|---|---|
Input Connection connection / Required | Notes The Connection to use for authorization. | Example |
Input File ID string / Required | Notes A unique opaque ID for each file. File IDs are stable throughout the life of the file, even if the file name changes. | Example my-example-file-id |
Input File Name string | Notes Provide a string for the name of the new file. | Example myFile |
Input Folder ID string | Notes A unique opaque ID for each folder. | Example my-example-folder-id |
#
Output Example Payload{ "data": { "name": "example", "description": "example" }}
#
Create FileCreate a new file with content and metadata | key: createFile
Input | Default | Notes | Example |
---|---|---|---|
Input Connection connection / Required | Default | Notes The Connection to use for authorization. | Example |
Input Fields string | Default * | Notes Provide a comma separated list of values to be returned in the response. | Example ParentFolder |
Input File Content string / Required | Default | Notes The binary or text body of the file. Some content examples you can store in Google Drive are images, videos, text, and PDF. | Example My Example File Contents |
Input File Name string / Required | Default | Notes Provide a string for the name of the new file. | Example myFile |
Input Parent Folder Id string | Default | Notes A unique opaque ID for each folder. | Example my-example-folder-id |
#
Output Example Payload{ "data": { "kind": "drive#file", "id": "id_example", "name": "example", "mimeType": "example", "description": "example" }}
#
Create FolderCreate a directory file | key: createFolder
Input | Notes | Example |
---|---|---|
Input Connection connection / Required | Notes The Connection to use for authorization. | Example |
Input Folder Name string / Required | Notes Provide a string for the name of the new folder. | Example Pictures |
#
Output Example Payload{ "data": { "name": "example", "description": "example" }}
#
Delete FileDelete a file by file id | key: deleteFile
Input | Default | Notes | Example |
---|---|---|---|
Input Connection connection / Required | Default | Notes The Connection to use for authorization. | Example |
Input Fields string | Default * | Notes Provide a comma separated list of values to be returned in the response. | Example ParentFolder |
Input File ID string / Required | Default | Notes A unique opaque ID for each file. File IDs are stable throughout the life of the file, even if the file name changes. | Example my-example-file-id |
#
Empty TrashEmpty the trash of deleted files | key: emptyTrash
Input | Notes |
---|---|
Input Connection connection / Required | Notes The Connection to use for authorization. |
#
Get AboutGets information about the user's Drive, and system capabilities | key: getAbout
Input | Default | Notes | Example |
---|---|---|---|
Input Connection connection / Required | Default | Notes The Connection to use for authorization. | Example |
Input Fields string | Default * | Notes Provide a comma separated list of values to be returned in the response. | Example ParentFolder |
#
Output Example Payload{ "data": { "user": { "displayName": "example", "emailAddress": "example@email.com", "kind": "example" } }}
#
Get Current UserGet the information and metadata of the user that is currently logged in | key: getCurrentUser
Input | Notes |
---|---|
Input Connection connection / Required | Notes The Connection to use for authorization. |
#
Output Example Payload{ "data": { "kind": "drive#user", "displayName": "Example User", "photoLink": "https://lh3.googleusercontent.com/a/Example", "me": true, "permissionId": "12345678901234567890", "emailAddress": "example@gmail.com" }}
#
Get FileGets a file's metadata and content by ID. | key: getFile
Input | Notes | Example |
---|---|---|
Input Connection connection / Required | Notes The Connection to use for authorization. | Example |
Input Preferred Export Type string | Notes Provide the type of file you want to export as. If the value you provided is not compatible, we will attempt the first option available in the objects export types. This value is only required when exporting a non binary file. | Example application/x-vnd.oasis.opendocument.spreadsheet |
Input File ID string / Required | Notes A unique opaque ID for each file. File IDs are stable throughout the life of the file, even if the file name changes. | Example my-example-file-id |
#
Output Example Payload{ "data": { "type": "Buffer", "data": [ 101, 120, 97, 109, 112, 108, 101 ] }, "contentType": "application/octet"}
#
List ChangesList changes made to files in your Google Drive since the last time this step ran (up to 1000) | key: listChanges
Input | Notes |
---|---|
Input Connection connection / Required | Notes The Connection to use for authorization. |
Input Drive ID string | Notes If omitted, a token for the authenticated user's 'My Drive' will be generated |
The first time this action runs, it takes note of the current pageToken
returned by Google, and returns no changes.
Subsequent runs of this step use that pageToken
to determine what has changed since the last time this step ran.
#
Output Example Payload{ "data": { "kind": "drive#changeList", "newStartPageToken": "247040", "changes": [ { "kind": "drive#change", "removed": false, "file": { "kind": "drive#file", "mimeType": "image/png", "id": "14FSE_ESVGWta4XlzWGHVm0VultNS-1uO", "name": "example.png" }, "fileId": "14FSE_ESVGWta4XlzWGHVm0VultNS-1uO", "time": "2022-09-20T21:36:23.687Z", "type": "file", "changeType": "file" } ] }, "instanceState": { "example-step-id": "example-new-page-token" }}
#
List DrivesList all drives | key: listDrives
Input | Notes |
---|---|
Input Connection connection / Required | Notes The Connection to use for authorization. |
#
List File's Export TypesList the available export types of a file by ID. | key: listExportTypes
Input | Notes | Example |
---|---|---|
Input Connection connection / Required | Notes The Connection to use for authorization. | Example |
Input File ID string / Required | Notes A unique opaque ID for each file. File IDs are stable throughout the life of the file, even if the file name changes. | Example my-example-file-id |
#
Output Example Payload{ "data": [ "application/x-vnd.oasis.opendocument.spreadsheet", "text/tab-separated-values", "application/pdf", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "text/csv", "application/zip", "application/vnd.oasis.opendocument.spreadsheet" ]}
#
List FilesLists all available files and directories | key: listFiles
Input | Default | Notes | Example |
---|---|---|---|
Input Connection connection / Required | Default | Notes The Connection to use for authorization. | Example |
Input Fields string | Default * | Notes Provide a comma separated list of values to be returned in the response. | Example ParentFolder |
Input Page Size string | Default | Notes Provide an integer value for the maximum amount of results that will be returned. Provide a value from 1 to 50. | Example 20 |
Input Page Token string | Default | Notes Specify the pagination token that's returned by a previous request to retrieve the next page of results | Example lslTXFcbLQKkb0vP9Kgh5hy0Y0OnC7Z9ZPHPwPmMnxSk3eiDRMkct7D8E |
Input Query string | Default | Notes Provide a query to be used in the request. Refer to the Google documentation for examples: https://developers.google.com/drive/api/v3/search-files | Example organizerCount = 0 |
#
Output Example Payload{ "data": { "files": [ { "name": "example", "description": "example" } ] }}
#
List FoldersLists all available directories | key: listFolders
Input | Default | Notes | Example |
---|---|---|---|
Input Connection connection / Required | Default | Notes The Connection to use for authorization. | Example |
Input Fields string | Default * | Notes Provide a comma separated list of values to be returned in the response. | Example ParentFolder |
Input Folder ID string | Default | Notes A unique opaque ID for each folder. | Example my-example-folder-id |
Input Page Size string | Default | Notes Provide an integer value for the maximum amount of results that will be returned. Provide a value from 1 to 50. | Example 20 |
Input Page Token string | Default | Notes Specify the pagination token that's returned by a previous request to retrieve the next page of results | Example lslTXFcbLQKkb0vP9Kgh5hy0Y0OnC7Z9ZPHPwPmMnxSk3eiDRMkct7D8E |
#
Output Example Payload{ "data": { "files": [ { "name": "example", "description": "example" } ] }}
#
Raw RequestIssue a raw HTTP request with the configured connection | key: rawRequest
Input | Default | Notes | Example |
---|---|---|---|
Input Connection connection / Required | Default | Notes The Connection to use for authorization. | Example |
Input Data string | Default | Notes The HTTP body payload to send to the URL. Must be a string or a reference to output from a previous step. | Example {"exampleKey": "Example Data"} |
Input Debug Request boolean | Default false | Notes Enabling this flag will log out the current request. | Example |
Input File Data string Key Value List | Default | Notes File Data to be sent as a multipart form upload. | Example [{key: "example.txt", value: "My File Contents"}] |
Input Form Data string Key Value List | Default | Notes The Form Data to be sent as a multipart form upload. | Example [{"key": "Example Key", "value": new Buffer("Hello World")}] |
Input Header string Key Value List | Default | Notes A list of headers to send with the request. | Example User-Agent: curl/7.64.1 |
Input Max Retry Count string | Default 0 | Notes The maximum number of retries to attempt. | Example |
Input Method string | Default | Notes | Example |
Input Query Parameter string Key Value List | Default | Notes A list of query parameters to send with the request. This is the portion at the end of the URL similar to ?key1=value1&key2=value2. | Example |
Input Response Type string | Default json | Notes The type of data you expect in the response. You can request json, text, or binary data. | Example binary |
Input Retry Delay (ms) string | Default 0 | Notes The delay in milliseconds between retries. | Example |
Input Retry On All Errors boolean | Default false | Notes If true, retries on all erroneous responses regardless of type. | Example |
Input Timeout string | Default | Notes The maximum time that a client will await a response to its request | Example 2000 |
Input URL string / Required | Default | Notes This is the URL to call. | Example /sobjects/Account |
Input Use Exponential Backoff boolean | Default false | Notes Specifies whether to use a pre-defined exponential backoff strategy for retries. | Example |
#
Search FilesSearch for an existing file by Name | key: searchFiles
Input | Default | Notes | Example |
---|---|---|---|
Input Connection connection / Required | Default | Notes The Connection to use for authorization. | Example |
Input Fields string | Default * | Notes Provide a comma separated list of values to be returned in the response. | Example ParentFolder |
Input Parent Folder Id string | Default | Notes A unique opaque ID for each folder. | Example my-example-folder-id |
Input Page Size string | Default | Notes Provide an integer value for the maximum amount of results that will be returned. Provide a value from 1 to 50. | Example 20 |
Input Page Token string | Default | Notes Specify the pagination token that's returned by a previous request to retrieve the next page of results | Example lslTXFcbLQKkb0vP9Kgh5hy0Y0OnC7Z9ZPHPwPmMnxSk3eiDRMkct7D8E |
Input Query string | Default | Notes Provide a query to be used in the request. Refer to the Google documentation for examples: https://developers.google.com/drive/api/v3/search-files | Example organizerCount = 0 |
Input Search string | Default | Notes Provide a string of text to perform a search with. | Example Search for this string |
#
Search FoldersSearch for an existing directory by Name | key: searchFolders
Input | Default | Notes | Example |
---|---|---|---|
Input Connection connection / Required | Default | Notes The Connection to use for authorization. | Example |
Input Fields string | Default * | Notes Provide a comma separated list of values to be returned in the response. | Example ParentFolder |
Input Parent Folder Id string | Default | Notes A unique opaque ID for each folder. | Example my-example-folder-id |
Input Page Size string | Default | Notes Provide an integer value for the maximum amount of results that will be returned. Provide a value from 1 to 50. | Example 20 |
Input Page Token string | Default | Notes Specify the pagination token that's returned by a previous request to retrieve the next page of results | Example lslTXFcbLQKkb0vP9Kgh5hy0Y0OnC7Z9ZPHPwPmMnxSk3eiDRMkct7D8E |
Input Search string | Default | Notes Provide a string of text to perform a search with. | Example Search for this string |
#
Output Example Payload{ "data": { "files": [ { "name": "example", "description": "example" } ] }}
#
Update FileUpdates a file's content by file id | key: updateFile
Input | Default | Notes | Example |
---|---|---|---|
Input Connection connection / Required | Default | Notes The Connection to use for authorization. | Example |
Input Fields string | Default * | Notes Provide a comma separated list of values to be returned in the response. | Example ParentFolder |
Input File Content string | Default | Notes The binary or text body of the file. Some content examples you can store in Google Drive are images, videos, text, and PDF. | Example My Example File Contents |
Input File ID string / Required | Default | Notes A unique opaque ID for each file. File IDs are stable throughout the life of the file, even if the file name changes. | Example my-example-file-id |
Input File Name string | Default | Notes Provide a string for the name of the new file. | Example myFile |
#
Output Example Payload{ "data": { "kind": "drive#file", "id": "id_example", "name": "example", "mimeType": "example", "description": "example" }}