I want to find a way of using the Google API to modify a specific row of data based on criteria I supply. Something like a SQL's :
UPDATE Customers
SET ContactName = 'Alfred Schmidt', City= 'Frankfurt'
WHERE CustomerID = 1
I have tried playing around with batchUpdateByDataFilter but cannot seems to get it to work. I just became aware of Googles Query language but this does not have an update.
I have a test spreadsheet below. I want to be able to update specific columns based on the ID.
https://docs.google.com/spreadsheets/d/1keCaROqv4ytDaf5AhcMV13Jj3N_eZCpLfRAGt2ycwA8/edit?usp=sharing
e.g. in SQL, something like the following
UPDATE SET Collected = 'Yes' WHERE ID = 1
If my understanding is correct, how about this answer?
Unfortunately, in the current stage, the values of Spreadsheet cannot updated using the query language. You can see the document of the query language at here. This has already been mentioned by TheMaster's comment.
So I would like to propose 2 workarounds.
In this workaround, I would like to propose to use Sheets API. From your latest question, I could confirm that you have already been able to put and get values using Sheets API. So how about the following flow?
In this workaround, I would like to propose to use Web Apps which was created by Google Apps Script. The values of Spreadsheet are modified by using the Web Apps like an API.
As a sample situation, I achieve the following query using Web Apps.
UPDATE SET Collected = 'Yes' WHERE ID = 1
Your shared Spreadsheet is used as the sample Spreadsheet. In this case, for the sheet of "Sheet1", when the value of column "A" (ID) is 1
, the value of column "L" (Collected) is modified to Yes
.
Please open the script editor of the Spreadsheet you want to use. And copy and paste the following script to the script editor.
function doGet(e) {
var p = e.parameter;
var sheetName = "Sheet1";
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName);
var range = sheet.getDataRange();
var values = range.getValues();
var headers = values.splice(0, 1)[0];
var checkCol = headers.indexOf(p.checkKey);
var modifyCol = headers.indexOf(p.modifyKey);
values.forEach(function(e, i) {
if (e[checkCol] == p.checkValue) {
values[i][modifyCol] = p.modifyValue;
}
});
values.unshift(headers);
range.setValues(values);
return ContentService.createTextOutput("Done");
}
Please deploy Web Apps.
Only myself
is used, only you can access to Web Apps. At that time, please use your access token.https://script.google.com/macros/s/#####/exec
.Please request to the Web Apps using the following curl sample. At that time, please use the copied URL of Web Apps. The each value is set as the query parameter.
curl -L "https://script.google.com/macros/s/###/exec?checkKey=ID&checkValue=1&modifyKey=Collected&modifyValue=Yes"
Or, if you want to use your access token, please use below.
curl -L "https://script.google.com/macros/s/###/exec?checkKey=ID&checkValue=1&modifyKey=Collected&modifyValue=Yes&access_token=###"
By above curl command, for the sheet of "Sheet1", when the value of column "A" (ID) is 1
, the value of column "L" (Collected) is modified to Yes
.
If I misunderstood your question and this wat not the direction you want, I apologize.