Is there a SpreadsheetApp.flush() option for the Google Sheets API?

Viewed 84

I have a spreadsheet that I send data to it, I generate a 1-minute sleep (import time → time.sleep(60)) in the code to make sure that the calculations have all been done and then I copy the result of these calculations to another page of that same spreadsheet.

In Google Apps Script there is the SpreadsheetApp.flush() option to make sure that everything in the spreadsheet is perfect to continue the code.

But what about when we use the Google Sheets API, is there a way to do this instead of putting a sleep with a random value like I do?

1 Answers

I was curious about that too, so I reviewed the documentation, and it seems that there is no flush() method for Sheets API.

However, I found a workaround that might help so you can make sure that you are working on the latest version of the sheet. I took inspiration from the Writecontrol parameter in Google Docs API.

"Determines the revision of the document to write to and how the request should behave if that revision is not the current revision of the document."

So what I was thinking is to use the Drive API Revisions by using the Revisions: list method and get the latest version of the Sheet. After that, use Revision: get to retrieve the latest version of the sheet to work on it.

You can also submit a missing feature, Google might add this method to the Sheets API later on.

Reference:

Related