Delete google docs content and replace it

I am trying to delete the whole content from a google document and then replace it with new content. In my scenario I check if the document exists (Get content of a document), when the document exists I then want to delete all of the content and replace it with new content. The content of the document could be images, paragraphs, tables, pretty much anything HTML allows. Therefore trying to use the replace pre built modules is pretty much impossible as I dont know what parts of the document could have changed. Therefore it would be easier to just delete all content of the document and then upload all new content. Is this possible, I cant seem to find anything that would do this. I have to keep the Id of the document the same but if there is a way of creating new versions or anything like that it would work.

My issue seems similar to this one. Update Google Docs through Make API Call Module

1 Like

Welcome to the Make community!

Absolutely, it can be done as shown here Can a Google Docs content be deleted/cleared?

To do this, you can try using the Google Docs “Make an API Call” module —

Performs an arbitrary authorized API call.

For more information, see https://www.make.com/en/integrations/google-docs, and https://www.make.com/en/help/app/google-docs in the help centre.

Hope this helps! Let me know if there are any further questions or issues.

@samliew

P.S.: Investing some effort into the Make Academy will save you lots of time and frustration using Make.

Hi, I have tried using these methods. In other words using the GET to get the content of the article. Then use the returned ‘Body’ variable as the old text to replace and put the HTML body in the new text. This doesn’t seem to work though.

My suspicion is that the replace text module only works for text and as my document can contain images, tables and pretty much anything that can be done in HTML the module doesnt work as expected. To make this work I think it would require a series of complex processing and modules to work out what has been changed. At which point I think I have decided its probably easier to just do what the solution was in your link above, ie create a new document and move the old document into an archive folder.

No, it is literally possible to achieve this with just that one module I mentioned.

You don’t even need a Get Document Content module.

All you need is a deleteContentRange request.

Okay, so if I used the generic google doc api call with the endpoint.
/v1/documents/{documentId}:batchUpdate

Then in my request body I did
{
“requests”: [
{
“range”: {
“startIndex”: 0,
“endIndex”: 10
}
}
]
}

where I have put 10 for end index that would actually be the length of the document.
That should work? I am fairly sure I tried this and it didn’t work.

What’s the error message?

No error message, it just doesnt do anything to the sheet.