Is there a SpreadsheetApp.flush() option for the Google Sheets API? - google-sheets-api

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?

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:
Flush() method.
Writecontrol Google Docs API.
Changes and revisions overview.
Revisions: list.
Revisions: get.

Related

Connect Google Sheets by C # using the KEY API (not OAuth2)

I want to do a search within a sheet.
I manage to get a list of entries (https://sheets.googleapis.com/v4/spreadsheets/{spreadsheetsID}/values/1?alt=json&key={API KEY})
but am unable to perform a search.
I use API KEY Is it possible to get an example?
Unfortunately, there is no method in Sheets API which lets you perform a search.
This has already been reported on Google's Issue Tracker here. I suggest you star the issue and eventually add a comment as well stating that you are interested in this feature.

PERMISSION_DENIED error while reading public spreadsheet with Google Sheets API

I am using Google Sheets API v4 to read a spreadsheet content in my project. It has worked just fine for a few months, but recently I started to get a PERMISSION_DENIED error while reading some, but not all of them.
All the sheets worked properly before, but now some of them can't be read (resulting in PERMISSION_DENIED error) while the other ones still work fine. Also when I create a new sheet it does NOT work.
All the sheets are available for viewing for anyone at the web, I did not change the API key I am using, the sheet owner did not change, some sheets have not even been modified for weeks. Long story short: I did not change anything (that I am aware of) that could impact reading the sheets but yet some of sheets suddenly stopped working.
Has anything changed recently in how Google Sheets API works? Or am I missing something else?
EDIT:
A few hours passed by and some sheets that previously did not work now work and some that did work now don't. The sheets have not been modified in meantime.
May this be caused by reaching any usage limit? I don't get RESOURCE_EXHAUSTED message though. It's PERMISSION_DENIED in each case.
Turns out it was a bug on Google side. Now everything works as intended.

How can I detect new row or updated row in Google Sheets through the api?

Can anyone help me figure out how to detect new row or updated row in a Google sheets through the api ? Something like a webhook ?
I think you can only do it with the help of Apps Script. You can use a trigger here to detect if something is change in your spreadsheet. The triggers let Apps Script run a function automatically when a certain event, like opening a document, occurs. Simple triggers are a set of reserved functions built into Apps Script, like the function onOpen(e), which executes when a user opens a Google Docs, Sheets, or Forms file. For more information, check this related SO question.

Append Row with PHP Library

I'm using the Google PHP Library https://github.com/google/google-api-php-client and am trying to append data. According to the docs, https://developers.google.com/sheets/samples/writing#append_values, it's possible. The issue is that the main Sheets Service, Google_Service_Sheets_Resource_SpreadsheetsValues(), does not have an append method, only update (and some others that won't help here).
See Google sheets API 4: How to append to the end of the row with PHP, asking the same question. The PHP client library is out of date and missing the append method. I'll report back on that other SO thread when it's fixed. Sorry about that!

Google Spreadsheet API v4, is it possible to get revision content?

I'm reading through the v4 API and can't satisfy my own question. I want to build an app that gathers a single spreadsheet's previous revision(s). (Specifically, I want to be able to get the entire content of a previous revision.) Is this possible in the v4 API? If it is can I get entire revision snapshots, or does the API only return difference information?
I cannot find any instruction in the Sheets API that can get the revision content of it's file. So the only way to get the revision file is by manually checking it in the Spreadsheet file itself under File -> See revison history. Or by using the Manage Revisions of Google Drive.
Google Drive keeps track of all changes made to a file by
automatically creating a "revision history." This allows users to see
who made edits and to revert to earlier versions of the same file.
Here are the steps that you need to do in order to get the revision file.
Get the File ID of the Spreadsheet that you want to get its revision.
By using the Revisions: list, you can get here the list of all revision that you do for that file.
Now, by using the Revisions: get, you can now get the specific revision of the file.
For more information, check this SO question.