I want to dump output to a google doc, and if any content exists in that doc, replace it. I can’t seem to figure out how to define a start and end index for replacement. Start index is supported allowing me to insert, but not an end Index allowing me to replace all. What am I missing?
It looks like your topic is missing some important information. Could you provide the following if applicable.
- n8n version:
- Database (default: SQLite):
- n8n EXECUTIONS_PROCESS setting (default: own, main):
- Running n8n via (Docker, npm, n8n cloud, desktop app):
- Operating system:
Welcome to the community @chad_jones
here’s just an idea but instead of trying to define the start/end of the content, you could make a GET request for a specific doc to get the content and then if content exists, replace that content with an empty string. Would that work for your use-case?
The content could be a couple hundred pages of text. Which would likely break the search and replace. Seems like there should be a more obvious approach.
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.
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.