If I understand you correctly, you want to programmatically:
- Retrieve a document from Drive.
- Edit this document while keeping the original one unmodified.
- Save this new document.
You have to follow these steps:
- Use Files.copy from Drive API to copy the file you want to edit. To achieve this, you have to provide the id of the original file as a request parameter. As a response you will get a File resource corresponding to the copy you created. Retrieve the file id from this response.
- Update this new file using batchUpdate from Docs API. For that you will need to (1) provide the file id you retrieved in the previous step as a parameter and (2) provide the changes you want to make using the
requests parameter (an array of all the changes you want to make) in the request body (check the links I attach to know exactly how should your requests parameter be like - I would like to be more specific here, but I don't know how exactly do you want to modify the document).
Obviously, there is no need to save the modified document, this is done automatically when the file is modified.
I hope this is of any help to you.