Can't get the Google Sheets API v4 code working from Google Apps Script for adding named/protected ranges to the Google Sheet, used the code sample from here [[link]][1]. It gives the error (what is the correct json form for this?):
Invalid JSON payload received. Unknown name "requests": Cannot find field. (line 5, file "Code")
Below is the code:
function protectSheet() {
var sheetId = "sheet id";
var spreadsheetId = "spreadsheet id";
Sheets.Spreadsheets.Values.batchUpdate(
{
"requests": [
{
"addNamedRange": {
"namedRange": {
"name": "Counts",
"range": {
"sheetId": sheetId,
"startRowIndex": 0,
"endRowIndex": 3,
"startColumnIndex": 0,
"endColumnIndex": 5,
},
}
}
},
{
"addProtectedRange": {
"protectedRange": {
"range": {
"sheetId": sheetId,
"startRowIndex": 3,
"endRowIndex": 4,
"startColumnIndex": 0,
"endColumnIndex": 5,
},
"description": "Protecting total row",
"warningOnly": true
}
}
}
]
}, spreadsheetId);
}
[1]: https://developers.google.com/sheets/api/samples/ranges