Google Drive connector
Create folders, create files from a Google Docs template, and upload or download files on Google Drive from your BPMN process.
About this connector
The Google Drive connector is an outbound connector that lets your process work with Google Drive. Use it to create a folder, create a file from a Google Docs template and fill in the template variables, upload a file from process data, or download a file from Google Drive.
For example, use this connector to generate a personalized letter from a template when an application is approved, and store it in a customer folder.
Prerequisites
The following prerequisites are required to use this connector:
| Prerequisite | Description |
|---|---|
| Google Drive API and Google Docs API | Enable both APIs for every client that uses the connector. You can do this on the Google Cloud API Library page. |
| OAuth token | A bearer token, or a client ID, client secret, and refresh token. The token must have permission to read and create folders and files in the Google Drive you want to use. Store it as a secret in your cluster, not in the diagram. |
For instructions to obtain a token, see obtain an OAuth token.
Use this connector
New to using an outbound connector? Learn how to add and use this type of connector, apply element templates, use connector secrets, handle results and errors, and more.
Configuration
Authentication
Select an authentication method in the Type dropdown, then complete the fields it reveals.
| Property | Type | Required | Description | Example |
|---|---|---|---|---|
| Type | Dropdown | Yes | The authentication method: Bearer token or Refresh token (default). | Refresh token |
| Bearer token | String | Yes | A valid Google API bearer token, which is short-lived. Shown when Type is Bearer token. Use a secret to avoid exposing the token. | {{secrets.GOOGLE_BEARER_TOKEN}} |
| Client ID | String | Yes | The Google API client ID. Shown when Type is Refresh token. | |
| Client secret | String | Yes | The Google API client secret. Shown when Type is Refresh token. Use a secret to avoid exposing the value. | {{secrets.GOOGLE_CLIENT_SECRET}} |
| Refresh token | String | Yes | A valid Google API refresh token. Shown when Type is Refresh token. Use a secret to avoid exposing the value. | {{secrets.GOOGLE_REFRESH_TOKEN}} |
Operations
Select the operation in the Operation dropdown of the Select operation section. The input parameters depend on the operation you select.
Create folder
Create an empty folder on Google Drive. The connector uses the Google Drive Files:Create API endpoint.
Input parameters
| Property | Type | Required | Description | Example |
|---|---|---|---|---|
| New resource name | String | Yes | The name of the folder to create. Supports FEEL expressions. | MyNewFolder |
| Parent folder ID | String | No | The folder in which the new folder is created. If you leave it empty, the folder is created in the Google Drive root folder of the user who owns the token. See where do I get a parent folder ID? | 1whNL0a6WjZtYRHF2522FrCYUYxHve9ju-DHNkaTm9Sk |
| Additional properties or metadata | String | No | Google Drive properties to set on the folder, for example a description. Requires a FEEL expression. See additional properties and metadata for known values and limitations. | = {"description": "myDescription"} |
Output
The connector exposes the Google Drive API response as a local variable named response. The following fields are available:
googleDriveResourceId: The ID of the newly created resource.googleDriveResourceUrl: The human-readable URL of the newly created resource.
For example, use a Result expression to map the fields to process variables:
= {
"myNewReportFolderId": response.googleDriveResourceId,
"myNewReportFolderUrl": response.googleDriveResourceUrl
}
Create file from template
Create a file by copying a Google Docs template and replacing the placeholders in it. The connector copies the template with the Google Drive Files:Copy API endpoint. It then applies your template variables with the Google Docs Merge approach, using the Documents:BatchUpdate API method.
The connector supports only Google Docs files as templates (MIME type application/vnd.google-apps.document).
Input parameters
| Property | Type | Required | Description | Example |
|---|---|---|---|---|
| New resource name | String | Yes | The name of the file to create. Supports FEEL expressions. | |
| Parent folder ID | String | No | The folder in which the new file is created. If you leave it empty, the file is created in the Google Drive root folder of the user who owns the token. See where do I get a parent folder ID? | 1whNL0a6WjZtYRHF2522FrCYUYxHve9ju-DHNkaTm9Sk |
| Template ID | String | Yes | The ID of the Google Docs template to copy. See where do I get a template ID? | 1whNL0a6WjZtYRHF2522FrCYUYxHve9ju-DHNkaTm9Sk |
| Template variables | String | No | The requests that replace placeholders in the copied template. Must be compatible with the Google Docs Requests API. Requires a FEEL expression. See the template example. |
Output
The connector exposes the Google Drive API response as a local variable named response. The following fields are available:
googleDriveResourceId: The ID of the newly created resource.googleDriveResourceUrl: The human-readable URL of the newly created resource.
Upload file
Upload a file to Google Drive.
Input parameters
| Property | Type | Required | Description | Example |
|---|---|---|---|---|
| Parent folder ID | String | No | The folder in which the new file is created. If you leave it empty, the file is created in the Google Drive root folder of the user who owns the token. See where do I get a parent folder ID? | 1whNL0a6WjZtYRHF2522FrCYUYxHve9ju-DHNkaTm9Sk |
| Document source | Dropdown | Yes | Where the document to upload comes from. Defaults to Camunda Document. See document sources. | Camunda Document |
Select one of the following document sources, then complete the fields it reveals:
| Document source | Property | Type | Required | Description |
|---|---|---|---|---|
| Camunda Document | Camunda document | String | Yes | A reference to a document in the Camunda document store, as a FEEL expression. The document must exist first, for example created using the Orchestration Cluster REST API. Assign the result of the endpoint to a variable, then use that variable here. |
| Inline Content | Content | String | Yes | The content to upload, built from process data. See inline documents. |
| Inline Content | File name | String | No | The name of the file to create. |
| Inline Content | Content type | String | No | The content type of the file. |
| From URL | URL | String | Yes | The URL to fetch the document from. |
| From URL | File name | String | No | The name of the file to create. |
Use Inline Content to build a file directly from process variables without first storing it in the Camunda document store.
Output
The connector exposes the Google Drive API response as a local variable named response. The following fields are available:
googleDriveResourceId: The ID of the newly created resource.googleDriveResourceUrl: The human-readable URL of the newly created resource.
Download file
Download a file from Google Drive.
Input parameters
| Property | Type | Required | Description | Example |
|---|---|---|---|---|
| File ID | String | Yes | The ID of the Google Drive file to download. See where do I get a file ID? | 1y1td3iIKWOh88gK4hVevGM1WnX7tibCW |
| Response format | Dropdown | Yes | How the downloaded content is returned: Document reference (default), as text, or as JSON. See return formats. | Document reference |
| Encoding | String | No | The character set used to decode the content. Shown only when Response format is as text. Defaults to UTF-8. | UTF-8 |
Output
The response depends on the selected Response format:
-
Document reference (default) returns a document created in the Camunda document store, identical to the REST API. For example:
{
"camunda.document.type": "camunda",
"storeId": "in-memory",
"documentId": "c3c8e499-321d-421c-afa2-4632d2f5ce48",
"metadata": {
"contentType": "image/png",
"fileName": "file name",
"size": 66497,
"customProperties": {}
}
} -
as text returns the content decoded as a string, and as JSON returns it parsed as JSON. Both are subject to a size guard (approximately 1.5 MiB). Use Document reference for large files.
Troubleshooting
To learn about general error handling in Camunda, see BPMN errors and failing jobs.
Appendix and FAQ
Obtain an OAuth token
The connector supports two methods for authentication and authorization: a short-lived JWT bearer token, or a refresh token.
Google supports multiple ways to obtain both. Refer to the official Google OAuth documentation for up-to-date instructions, or use the following examples.
Example 1: Obtain a JWT bearer token with a service account
The following code snippet is for demonstration purposes only and must not be used for real production systems due to security concerns. For production usage, follow the official Google guidelines.
Assuming you have created a service account and downloaded a JSON file with keys, run the following Python 3 snippet that prints the JWT token in the terminal:
import google.auth
import google.auth.transport.requests
from google.oauth2 import service_account
# Scopes required to execute 'create' endpoint with Google Drive API
SCOPES = ['https://www.googleapis.com/auth/drive', 'https://www.googleapis.com/auth/drive.file', 'https://www.googleapis.com/auth/drive.appdata']
# File with keys
SERVICE_ACCOUNT_FILE = 'google-service-account-creds.json'
credentials = service_account.Credentials.from_service_account_file(SERVICE_ACCOUNT_FILE, scopes=SCOPES)
auth_req = google.auth.transport.requests.Request()
credentials.refresh(auth_req)
# Print token
print(credentials.token)
When using shared drives, you must use an OAuth client instead of a service account. The service account does not have access to shared drives.
Example 2: Obtain a refresh token with an OAuth client
The following code snippet is for demonstration purposes only and must not be used for real production systems due to security concerns. For production usage, follow the official Google guidelines.
Assuming you have created an OAuth client, you can download key files from the Google Console. Run the following Python 3 snippet that prints the refresh token in the terminal:
from google_auth_oauthlib.flow import InstalledAppFlow
import pprint
SCOPES = ['https://www.googleapis.com/auth/drive', 'https://www.googleapis.com/auth/documents']
OAUTH_KEYS = './oauth-keys.json' # path to your file with OAuth credentials
def main():
flow = InstalledAppFlow.from_client_secrets_file(OAUTH_KEYS, SCOPES)
creds = flow.run_local_server(port=54948)
pprint.pprint(vars(creds))
if __name__ == "__main__":
main()
Where do I get a parent folder ID?
To find the ID of a Google Drive folder:
- Open the Google Drive folder in your web browser.
- Look at the URL in the address bar, which looks similar to the following:
https://drive.google.com/drive/folders/1whNL0a6WjZtYRHF2522FrCYUYxHve9ju-DHNkaTm9Sk - The parent folder ID is the alphanumeric string after
/folders/, in this case1whNL0a6WjZtYRHF2522FrCYUYxHve9ju-DHNkaTm9Sk.
Additional properties and metadata
Create folder accepts additional properties and metadata. You can set any property from the Google Drive Create API. For example:
= {
"description":"myDescription"
}
Unknown or mistyped properties are ignored.
Some properties are applicable only for the token owners, like folderColorRgb and starred.
Where do I get a template ID?
To find the ID of a Google Docs template:
- Open the link to the Google Docs template in your web browser. The URL looks similar to the following:
https://docs.google.com/document/d/1whNL0a6WjZtYRHF2522FrCYUYxHve9ju-DHNkaTm9Sk - The template ID is the alphanumeric string after
/d/, in this case1whNL0a6WjZtYRHF2522FrCYUYxHve9ju-DHNkaTm9Sk.
Example of a valid template
The following is an example of a valid Google Docs template:
{{CompanyName}} confidential.
{{DocumentDate}}
{{RecipientFullName}}
{{RecipientAddress}}
Dear {{RecipientShortName}}!
We are pleased to inform you that your application {{ApplicationNumber}} has been approved.
Sincerely,
{{SigneeName}}, Executive Director
In the Template variables field, use the following FEEL expression. It must be compatible with the Google Docs Requests API:
= {
"requests":[
{
"replaceAllText":{
"containsText":{
"text":"{{DocumentDate}}",
"matchCase":"true"
},
"replaceText":today()
}
},
{
"replaceAllText":{
"containsText":{
"text":"{{RecipientFullName}}",
"matchCase":"true"
},
"replaceText":"John W. Doe"
}
},
{
"replaceAllText":{
"containsText":{
"text":"{{RecipientAddress}}",
"matchCase":"true"
},
"replaceText":"Zweibrückenstraße 1845, 80000 Munich"
}
},
{
"replaceAllText":{
"containsText":{
"text":"{{RecipientShortName}}",
"matchCase":"true"
},
"replaceText":"Mr. Doe"
}
},
{
"replaceAllText":{
"containsText":{
"text":"{{ApplicationNumber}}",
"matchCase":"true"
},
"replaceText":"0123456789"
}
},
{
"replaceAllText":{
"containsText":{
"text":"{{SigneeName}}",
"matchCase":"true"
},
"replaceText":"Jane T. Doe"
}
},
{
"replaceAllText":{
"containsText":{
"text":"{{CompanyName}}",
"matchCase":"true"
},
"replaceText":"Good Company Inc."
}
}
]
}
The result should be as follows:
Good Company Inc. confidential.
2022-08-10
John W. Doe
Zweibrückenstraße 1845, 80000 Munich
Dear Mr. Doe!
We are pleased to inform you that your application 0123456789 has been approved.
Sincerely,
Jane T. Doe, Executive Director
Where do I get a file ID?
To find the ID of a Google Drive file:
- Select the file on your Google Drive, and click the three horizontal dots to the right of the file name.
- Click Share.
- Click Copy link. The URL looks similar to the following:
https://drive.google.com/file/d/1y1td3iIKWOh88gK4hVevGM1WnX7tibCW/view
- The file ID is the alphanumeric string after
/d/, in this case1y1td3iIKWOh88gK4hVevGM1WnX7tibCW.