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. |
| Service account key or OAuth token | The JSON key of a Google service account, a bearer token, or a client ID, client secret, and refresh token. The service account or 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 create a service account key, see service account key. 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
Choose a reusable credential, or enter the authentication details in the task.
| Property | Type | Required | Description | Example |
|---|---|---|---|---|
| Google credential | Configuration | No | A reusable Google credential. Available from Camunda 8.11. If you select a credential, its authentication details take precedence and the Type property and the properties that depend on it are hidden. See using credentials. | |
| Type | Dropdown | Conditional | The authentication method: Service account key, Bearer token, or Refresh token (default). Required if you do not select a Google credential. | Refresh token |
| Service account key (JSON) | String | Conditional | The full JSON key of a Google service account. Shown when Type is Service account key. Available from Camunda 8.11.0-alpha2. Use a secret to avoid exposing the value. | {{secrets.GDRIVE_SERVICE_ACCOUNT_KEY}} |
| Bearer token | String | Conditional | 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 | Conditional | The Google API client ID. Shown when Type is Refresh token. | |
| Client secret | String | Conditional | 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 | Conditional | 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. |
If you authenticate with a service account key, the new file belongs to the service account, which has no Google Drive storage of its own. Creating the file in a folder owned by a user fails with 403 Service Accounts do not have storage quota, and leaving Parent folder ID empty does not create the file in a user's root folder.
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.
If you authenticate with a service account key, the new file belongs to the service account, which has no Google Drive storage of its own. Creating the file in a folder owned by a user fails with 403 Service Accounts do not have storage quota, and leaving Parent folder ID empty does not create the file in a user's root folder.
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.
Google API errors
When a Google API request fails, the connector throws an error with the HTTP status code returned by Google as the error code. The message has the form Google API request failed: <status code> <reason>, where the reason comes from Google. Use the error expression to handle specific status codes.
Appendix and FAQ
Service account key
Starting from version 8.11.0-alpha2, you can authenticate with the JSON key of a Google service account. The connector requests the access scope it needs and renews its access token automatically, so the credentials do not expire after an hour and no manual token step is needed.
- In the Google Cloud Console, create a service account and a JSON key for it. Refer to the Google documentation to find out more.
- Store the full content of the JSON key as a secret in your cluster. For example,
GDRIVE_SERVICE_ACCOUNT_KEY. - Share each folder or file the connector must access with the email address of the service account (the
client_emailvalue in the key file). Use the Editor role for a folder in which the connector creates folders. - In the Authentication section, set Type to Service account key, and set Service account key (JSON) to the secret. For example,
{{secrets.GDRIVE_SERVICE_ACCOUNT_KEY}}.
You can also select Service account key in a reusable Google credential.
A service account behaves differently from a user:
- A service account has no Google Drive storage of its own. It can read and download files and create folders, but creating a file with content in a folder owned by a user fails with
403 Service Accounts do not have storage quota. This affects the Upload file and Create file from template operations. - A folder shared with the service account is not a Google Workspace shared drive. For where a service account can create files, see the Google shared drives overview.
- When you create a folder, set the Parent folder ID to a folder that is shared with the service account.
- Domain-wide delegation, which lets a service account act as a user, is not supported.
Obtain an OAuth token
The connector supports two methods for authentication and authorization with a token: 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
Use this approach only if you need a bearer token. To authenticate with a service account directly, use the service account key instead.
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)
A folder shared with a service account is not the same as a Google Workspace shared drive. For how service accounts work with shared drives, see the Google shared drives overview.
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.