Error writing to google spreadsheet using Google API

Code used

  var values = [
    [
      'value1','value2','value3'
    ]
  ];
   var body = {
    values: values
  };
  gapi.client.sheets.spreadsheets.values.update({
    spreadsheetId: '1Lofhq9R7X5wzGvO7fMViN8D8q1W3fiNxO5jjP7XL_s0',
    range: 'Sheet1!A1:A4',
    valueInputOption:'RAW',
    resource: body
  }).then((response) => {
    var result = response.result;
    console.log(`${result.updatedCells} cells updated.`);
  });

Error shown

    {
      "error": {
        "code": 400,
        "message": "Invalid JSON payload received. Unknown name \"valueInputOption\": Cannot bind query parameter. Field 'valueInputOption' could not be found in request message.",
        "status": "INVALID_ARGUMENT",
        "details": [
          {
            "@type": "type.googleapis.com/google.rpc.BadRequest",
            "fieldViolations": [
              {
                "description": "Invalid JSON payload received. Unknown name \"valueInputOption\": Cannot bind query parameter. Field 'valueInputOption' could not be found in request message."
              }
            ]
          }
        ]
      }
    }

I changed the access settings in google spreadsheet to allow everyone who has the link to view and edit it. This error occurs only when I try to write to a spreadsheet, I can read the spreadsheet using other functions.

+3
source share
2 answers

Nobody knows which domains you specified in the white list, so no one can reproduce your code. And your spreadsheet does not have a worksheet Class Data, and you mistakenly tried to write in A1:C1not A1:A4.

, values API-. 200 OK. , 'RAW' "RAW" / values: values resource: body.

enter image description here

+1

, API ( ). ​​ https://www.googleapis.com/auth/spreadsheets https://www.googleapis.com/auth/spreadsheets.readonly

0

Source: https://habr.com/ru/post/1695099/


All Articles