Hi FYI,
I managed it using the following: ( using Gemini ChatGPT failed )
Using n8n to Delete Google Doc Contents via HTTP Request
Understanding the Task:
- We’re aiming to delete the contents of a Google Doc using n8n.
- n8n is a low-code automation tool that can interact with various APIs, including the Google Drive API.
Steps Involved:
- Set up n8n:
- Install n8n and create a new workflow.
- Add a ‘Basic Auth’ Node:
- This node will handle the authentication with the Google Drive API.
- Use your Google Cloud Platform project’s credentials (client ID and client secret) to configure the node.
- Add a ‘HTTP Request’ Node:
- This node will send the HTTP request to the Google Drive API.
- Configure the node as follows:
- Method:
PATCH
(to update the file) - URL:
https://www.googleapis.com/upload/drive/v3/files/{file_id}
(replace{file_id}
with the actual ID of your Google Doc) - Headers:
Authorization
:Bearer {access_token}
(replace{access_token}
with the access token obtained from the ‘Basic Auth’ node)Content-Type
:application/json
- Body:
- An empty JSON object:
{}
(this indicates that we want to clear the file’s contents)
- An empty JSON object:
- Method:
Example n8n Workflow:
Opens in a new window
community.n8n.io
n8n workflow diagram showing a ‘Basic Auth’ node connected to a ‘HTTP Request’ node
Additional Considerations:
- Error Handling: Implement error handling in n8n to catch potential issues like authentication failures or API rate limits.
- Access Token Refresh: If your access token expires, you’ll need to implement a mechanism to refresh it using the ‘Basic Auth’ node.
- File ID Retrieval: If you don’t have the file ID, you can use another n8n node (like ‘List Files’) to retrieve it based on the file name or other criteria.
Note: To use the Google Drive API with n8n, you’ll need to enable the Drive API in your Google Cloud Platform project and have the necessary credentials configured.
By following these steps and customizing the workflow to your specific needs, you can effectively use n8n to delete the contents of a Google Doc via an HTTP request.
I used
Authentication
Predefined Credential Type
Credential Type
Google Docs OAuth2 API
I use this first then update the document later in the chain to ensure the document is emptied first ( not sure if a large document takes time to empty )
Hope this helps.