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.
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.
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.