Skip to main content

Google Drive Component

Manage files in Google Drive

Component key: google-drive

Description

Google 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 Drive

To track changes within Google Drive, use the List Changes action. You can either run List Changes on a schedule with a schedule trigger (for example, check for changes every 5 minutes), or you can use Google Drive's change API to receive notifications in real time when changes occur.

For an example of how to use webhooks with Google Drive, import this example integration available on GitHub.

Connections

OAuth2

The 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:

  1. Open up the Google Drive API console - https://console.cloud.google.com/apis/api/drive.googleapis.com
  2. Click CREATE PROJECT if you would like to create a new GCP project, or select an existing project.
  3. You will be prompted to enable Google Drive API for your project. Click ENABLE.
  4. On the sidebar, select Credentials.
  5. 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.
    1. Your app will be externally available to your customers, so choose a User Type of External.
    2. Fill out the OAuth consent screen with an app name (your company or product's name), support email, app logo, domain, etc.
    3. You can ignore domains for now.
    4. On the next page, ignore scopes - this component knows what scopes it needs to run and will request the right scopes for you.
    5. 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.
  6. Once your "Consent Screen" is configured open the Credentials page from the sidebar again.
  7. Click +CREATE CREDENTIALS and select OAuth client ID.
    1. Under Application type select Web application.
    2. Under Authorized redirect URIs enter Prismatic's OAuth 2.0 callback URL: https://oauth2.prismatic.io/callback
    3. Click CREATE.
  8. 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.

Triggers

Push Notification Webhook

Receive and validate webhook requests from Google Drive for webhooks you configure. | key: pushNotificationWebhook

Output Example Payload

{
"payload": {
"headers": {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate, br",
"Host": "hooks.prismatic.io",
"User-Agent": "APIs-Google; (+https://developers.google.com/webmasters/APIs-Google.html)",
"X-Amz-Cf-Id": "_K9KZtNN78sy1aygl3nJuQ4OoMh65STAsLFsPGENcnm_l68C112345==",
"X-Amzn-Trace-Id": "Root=1-64931762-5665c8324c471b204f212345",
"X-Goog-Channel-Expiration": "Wed, 21 Jun 2023 16:28:01 GMT",
"X-Goog-Channel-ID": "7f0419cf-5477-4bd5-bc86-2aa36af12345",
"X-Goog-Message-Number": "96035",
"X-Goog-Resource-ID": "jkkJZYhd8PPV6-Xto6QIo112345",
"X-Goog-Resource-State": "change",
"X-Goog-Resource-URI": "https://www.googleapis.com/drive/v3/changes?alt=json&pageToken=430&supportsAllDrives=true"
},
"queryParameters": null,
"rawBody": {
"data": null,
"contentType": "application/octet-stream"
},
"body": {
"data": null,
"contentType": "application/octet-stream"
},
"pathFragment": "",
"webhookUrls": {
"Flow 1": "https://hooks.prismatic.io/trigger/WEBHOOK_ID"
},
"webhookApiKeys": {
"Flow 1": ["sample-api-key"]
},
"invokeUrl": "https://hooks.prismatic.io/trigger/WEBHOOK_ID",
"executionId": "SW5zdGFuY2VFeGVjdXRpb25SZXN1bHQ6MGRlZjk2ZjYtYzhhOS00MDgzLWJlOTUtZmIwZDMzNDQ12345",
"customer": {
"id": "testCustomerId",
"name": "Test Customer",
"externalId": "testCustomerExternalId"
},
"instance": {
"id": "testInstanceId",
"name": "Test Instance"
},
"user": {
"id": "testUserId",
"email": "testUserEmail@example.com",
"name": "Test User",
"externalId": "testUserExternalId"
}
}
}

Data Sources

List Files

Lists all available files | key: selectFiles | type: picklist


List Folders

Lists all available directories | key: selectFolder | type: picklist


Select Drive

Select a drive | key: selectDrive | type: picklist


Actions

Copy File

Copy a file by file id | key: copyFile

Output Example Payload

{
"data": {
"name": "example",
"description": "example"
}
}

Create File

Create a new file with content and metadata | key: createFile

Output Example Payload

{
"data": {
"kind": "drive#file",
"id": "id_example",
"name": "example",
"mimeType": "example",
"description": "example"
}
}

Create Folder

Create a directory file | key: createFolder

Output Example Payload

{
"data": {
"name": "example",
"description": "example"
}
}

Create Webhook for Drive

Create a webhook to receive notifications of changes with a Google Drive | key: createDriveWebhook


Create Webhook for File or Folder

Create a webhook to receive notifications of changes for a file or folder | key: createFileWebhook


Delete File

Delete a file by file id | key: deleteFile


Delete Webhook

Stop a webhook channel from sending notifications | key: deleteWebhook


Empty Trash

Empty the trash of deleted files | key: emptyTrash


Get About

Gets information about the user's Drive, and system capabilities | key: getAbout

Output Example Payload

{
"data": {
"user": {
"displayName": "example",
"emailAddress": "example@email.com",
"kind": "example"
}
}
}

Get Current User

Get the information and metadata of the user that is currently logged in | key: getCurrentUser

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 File

Gets a file's metadata and content by ID. | key: getFile

Output Example Payload

{
"data": {
"type": "Buffer",
"data": [
101,
120,
97,
109,
112,
108,
101
]
},
"contentType": "application/octet"
}

List Changes

List changes made to files in your Google Drive since the last time this step ran (up to 1000) | key: listChanges

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 Drives

List all drives | key: listDrives


List File's Export Types

List the available export types of a file by ID. | key: listExportTypes

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 Files

Lists all available files and directories | key: listFiles

Output Example Payload

{
"data": {
"files": [
{
"name": "example",
"description": "example"
}
]
}
}

List Folders

Lists all available directories | key: listFolders

Output Example Payload

{
"data": {
"files": [
{
"name": "example",
"description": "example"
}
]
}
}

Move File

Move a file by file ID | key: moveFile

Output Example Payload

{
"data": {
"name": "example",
"description": "example"
}
}

Raw Request

Send raw HTTP request to Google Drive | key: rawRequest


Search Files

Search for an existing file by Name | key: searchFiles


Search Folders

Search for an existing directory by Name | key: searchFolders

Output Example Payload

{
"data": {
"files": [
{
"name": "example",
"description": "example"
}
]
}
}

Update File

Updates a file's content by file id | key: updateFile

Output Example Payload

{
"data": {
"kind": "drive#file",
"id": "id_example",
"name": "example",
"mimeType": "example",
"description": "example"
}
}