Google Drive

1. Overview

Google Drive is a cloud storage service provided by Google that allows users to store files, synchronize them across different devices, and share them. It is deeply integrated with the Google Workspace suite, including Google Docs, Sheets, and Slides.

With GoInsight's Google Drive node, you can automate the integration of file and folder management into your workflows. This makes it easy for you to interact with your cloud storage and achieve full lifecycle management of your files, including:

  • File Operations: Create, read, update, and delete files in specified folders.
  • Folder Management: Create new folders in your Google Drive.
  • Permission Control: Share files or folders with specified users and remove sharing permissions at any time.

2. Prerequisites

Before using this node, you need to meet the following conditions:

  • Have a valid Google account.
  • The Google Drive API must be enabled in your Google Cloud Platform (GCP) project.
  • You may need project owner or specific IAM role permissions to create and manage OAuth 2.0 Client ID credentials for GoInsight.

3. Credentials

For a detailed guide on how to obtain and configure credentials, please refer to our official documentation: Credential Configuration Guide.

4. Supported Operations

Summary

This node primarily operates on files, folders, and item permissions within Google Drive. The table below summarizes all supported operations:

Resource Operation Description
File Create From Text Creates a new file in Google Drive with the provided text content.
File Read File Reads the content of an online file in Google Drive using the provided file ID.
File Update From Text Updates an existing file on Google Drive with the provided text content.
Folder Create Folder Creates a folder in Google Drive.
Item Delete Item Deletes one or more items (files, folders, etc.) from Google Drive.
Item Permission Share Item Shares a Google Drive item (file, folder, etc.).
Item Permission Remove Share Removes sharing permissions for a specified Google Drive item.

Operation Details

Create Folder

Creates a folder in Google Drive.

Input Parameters:

  • FolderName: The name of the folder to be created.

Options:

  • ParentFolderId: The parent folder in which the new folder will be created. If omitted or null, it will be created in the root directory.

Output:

  • FolderCreated (bool): Indicates whether the folder was successfully created.
  • FolderId (string): The ID of the created folder if successful; otherwise, an empty string.
  • StatusCode (number): The HTTP status code of the API response, -1 for parameter errors, 500 for exceptions.
  • ErrorMessage (string): An error message if an error occurred; an empty string on success.

Create From Text

Creates a new file in Google Drive with the provided text content.

Input Parameters:

  • Text: The text content to be written to the file.
  • FileName: The name of the new file to be created.

Options:

  • FolderId: The identifier of the target folder, can be an ID or a URL containing the folder ID. Defaults to "root".
  • MimeType: The MIME type of the file, e.g., "plain/html". If not provided, defaults to "plain/text".

Output:

  • Created (bool): Indicates whether the file was successfully created.
  • FileId (string): The ID of the created file (empty if creation failed).
  • StatusCode (number): The HTTP status code of the API response, -1 for parameter errors, 500 for exceptions.
  • ErrorMessage (string): An error message if an error occurred; an empty string on success.

Delete Item

Deletes one or more items (files, folders, documents, etc.) from Google Drive using the provided item ID, which can be a direct ID or a URL containing the ID.

Input Parameters:

  • ItemId: The ID of the Google Drive item, can be a direct ID or a URL containing the ID.

Output:

  • AllDeleted (bool): Indicates whether all items were successfully deleted.
  • FailedItems (object-array): A JSON list of items that failed to delete; each record includes itemId, statusCode, and errorMessage.
  • StatusCode (number): The overall operation status: 200 (all successful), 207 (partially successful), 500 (all failed), -1 (parameter error).
  • ErrorMessage (string): An overall error message if parameter validation fails; otherwise, an empty string.

Remove Share

Removes sharing permissions for a specified Google Drive item (file, folder, etc.).

Input Parameters:

  • ItemId: The ID of the Google Drive item, can be a direct ID or a URL containing the ID.
  • Email: The target email address from which sharing permissions will be removed.

Output:

  • Removed (bool): Indicates whether the sharing permission was successfully removed.
  • StatusCode (number): The HTTP status code of the API response, -1 for parameter errors, 500 for exceptions.
  • ErrorMessage (string): An error message if an error occurred; an empty string on success.

Read File

Reads the content of an online file in Google Drive using the provided file ID.

Input Parameters:

  • FileId: The Google Drive identifier of the file to be read, can be an ID or a URL containing the file ID.

Output:

  • ReadSuccess (bool): Indicates whether the file was successfully read.
  • FileContent (string): The content of the file; empty if the read operation fails.
  • StatusCode (number): The HTTP status code of the API response, -1 for parameter errors, 500 for exceptions.
  • ErrorMessage (string): An error message if an error occurred; an empty string on success.

Share Item

Shares a Google Drive item (file, folder, etc.).

Input Parameters:

  • ItemId: The ID of the Google Drive item, can be a direct ID or a URL containing the ID.
  • Email: The target email address with which the folder will be shared.

Options:

  • Role: The permission role to grant. Allowed values: 'reader', 'writer', 'commenter'. Defaults to 'reader'.

Output:

  • Shared (bool): Indicates whether the item was successfully shared.
  • PermissionId (string): The ID of the created permission (empty if sharing failed).
  • StatusCode (number): The HTTP status code of the API response, -1 for parameter errors, 500 for exceptions.
  • ErrorMessage (string): An error message if an error occurred; an empty string on success.

Update From Text

Updates an existing file on Google Drive with the provided text content.

Input Parameters:

  • FileId: The ID of the target file to be updated, can be an ID or a URL containing the file ID.
  • Text: The text content to be written to the file.

Options:

  • FileName: The new file name (optional; if empty, the file name remains unchanged).
  • MimeType: The MIME type of the file, e.g., "plain/html". If not provided, defaults to "plain/text".

Output:

  • Updated (bool): Indicates whether the file was successfully updated.
  • FileId (string): The ID of the updated file (empty if the update failed).
  • StatusCode (number): The HTTP status code of the API response, -1 for parameter errors, 500 for exceptions.
  • ErrorMessage (string): An error message if an error occurred; an empty string on success.

5. Example Usage

This section will guide you through creating a simple workflow to create a new folder in the root directory of your Google Drive.

Workflow Overview

A basic workflow consists of three nodes: Start -> Google Drive: Create Folder -> Answer.

Step-by-Step Guide

  1. Add Tool Node:
    • On the workflow canvas, click the “+” sign to add a new node.
    • In the pop-up panel, select the “Tools” tab.
    • In the tool list, find and select Google Drive.
    • In the list of supported operations for Google Drive, click to select Create Folder, which will add a corresponding node to the canvas.
  2. Configure Node:
    • Click on the newly added Create Folder node, and its configuration panel will expand on the right.
    • Credential Configuration: At the top of the panel, find the credential field. Click the dropdown menu and select your pre-configured Google Drive credential.
    • Parameter Entry:
    • FolderName: This is a required field. Enter a name for your new folder, for example, 2024 Annual Reports.
    • ParentFolderId: This is an optional field. Since we want to create the folder in the root directory, leave this field empty. If you want to create it inside a specific folder, you can enter the parent folder's ID here.
  3. Run and Validate:
    • Once all required parameters are correctly filled in, the error prompt in the top right corner of the workflow canvas will disappear.
    • Click the “Run” button in the top right corner of the canvas to execute the workflow.
    • After successful execution, you can click the log icon in the top right corner to view the detailed input and output of the node. In the output, you should see FolderCreated as true, and the FolderId field will contain the unique ID of the newly created folder. You can also log into your Google Drive account to confirm that the new folder has been successfully created.

Final Workflow Display

After completing the steps above, your entire workflow is configured. Clicking “Run” will successfully create a new folder named “2024 Annual Reports” in the root directory of your Google Drive.

6. FAQs

Q: Why did I receive a "403 Forbidden" or permission-related error?

A: This is usually related to your Google Cloud Platform (GCP) configuration or account permissions. Please check the following:

  • API Enabled: Ensure that you have enabled the "Google Drive API" in your GCP project.
  • OAuth Consent Screen: Check if your OAuth consent screen is configured correctly, especially if your application is in "Testing" mode. Make sure your Google account has been added as a test user.
  • Scopes: Ensure that you have granted sufficient permission scopes (e.g., https://www.googleapis.com/auth/drive) when creating your credentials.
  • File/Folder Permissions: Confirm that the user account associated with the credentials has the necessary permissions to access or modify the target file or folder.

Q: How do I get the ID of a file or folder?

A: You can easily find the ID from the Google Drive web URL.

  • Open the file or folder for which you want to get the ID.
  • Look at the address bar in your browser. The URL structure is typically https://drive.google.com/drive/folders/[FOLDER_ID] or https://drive.google.com/file/d/[FILE_ID]/view.
  • The long string of letters and numbers in the URL is the ID you need.

Q: What happens if I try to delete an item that doesn't exist?

A: The Delete Item operation will not cause the workflow to crash. It will return a status code indicating failure (e.g., 404 Not Found) and will log the item's ID and the specific error message in the FailedItems output. you can use this output to build more robust error-handling logic.

7. Official Documentation

For more detailed information about the API, please refer to the Google Drive Official API Documentation.

Was This Page Helpful?
Discussion

Leave a Reply.

Your email address will not be published. Required fields are marked*

loading...
No Results