Google Sheets API v4 - Method: spreadsheets.values.append

Din picture Din · Sep 16, 2017 · Viewed 12.9k times · Source

What is the correct syntax for Google Sheets API v4 method spreadsheets.values.append for Google Apps Script?

Tried the following code but it is giving an error: Invalid JSON payload received.

function appendRow() {
  Sheets.Spreadsheets.Values.append("SpreadsheetID", "Sheet1!A:A", "USER_ENTERED", { "values": [[new Date()]] } );
}

Thank you.

Answer

Tanaike picture Tanaike · Sep 17, 2017

How about this sample? Sheets.Spreadsheets.Values.append() of Advanced Google services is used like Sheets.Spreadsheets.Values.append(resource, spreadsheetId, range, optionalArgs). So the sample used your parameters is as follows.

Sample :

var resource = {
  "majorDimension": "ROWS",
  "values": [[new Date()]]
}
var spreadsheetId = "### SpreadsheetID ###";
var range = "Sheet1!A:A";
var optionalArgs = {valueInputOption: "USER_ENTERED"};
Sheets.Spreadsheets.Values.append(resource, spreadsheetId, range, optionalArgs);