Google-api-nodejs-client: Google sheet API v4 - batchUpdate provide error : Invalid JSON. Unknown name "data".

Created on 30 May 2016  路  6Comments  路  Source: googleapis/google-api-nodejs-client

I got an error by executing the batchUpdate function :

var options = var options = {
    auth: auth,
    spreadsheetId: spreadSheetId,
    valueInputOption: "RAW",
    data: [
        {
            range: "MyRange",
            majorDimension: majorDimension,
            values: [0,0,0,1,2,3]
        }
    ]
};

spreadsheets.batchUpdate(options, function(err, res) {
    console.log(res);
    console.log(err);
})

The error is the following :

{ [Error: Invalid JSON payload received. Unknown name "data": Cannot bind query parameter. 'data' is a message type. Parameters can only be bound to primitive types.]
  code: 400,
  errors: 
   [ { message: 'Invalid JSON payload received. Unknown name "data": Cannot bind query parameter. \'data\' is a message type. Parameters can only be bound to primitive types.',
       domain: 'global',
       reason: 'badRequest' } ] }

Im using Google sheet API v4.

'data' should exist in request following the documentation :
https://developers.google.com/sheets/samples/writing#write_to_multiple_ranges

Most helpful comment

The payload of the request (not the parameters) need to be nested under a resource property:

var options = {
  auth: auth,
  spreadsheetId: spreadSheetId,
  resource: {
    valueInputOption: "RAW",
    data: [
      {
        range: "MyRange",
        majorDimension: majorDimension,
        values: [0,0,0,1,2,3]
      }
    ]
  }
};

spreadsheets.values, batchUpdate(options, function(err, res) {
    console.log(res);
    console.log(err);
});

All 6 comments

Yup, I had the same problem. Check what API call you're making; you're calling spreadsheets.batchUpdate instead of spreadsheets.values.batchUpdate.

@marcantoineTrehin Like @ehgoodenough said, you probably mean to be calling spreadsheets.values.batchUpdate, but in the code you posted you're actually calling spreadsheets.batchUpdate.

Getting the same error. Same code above but using spreadsheets.values.batchUpdate. Anyone have a working example of the options argument?

The payload of the request (not the parameters) need to be nested under a resource property:

var options = {
  auth: auth,
  spreadsheetId: spreadSheetId,
  resource: {
    valueInputOption: "RAW",
    data: [
      {
        range: "MyRange",
        majorDimension: majorDimension,
        values: [0,0,0,1,2,3]
      }
    ]
  }
};

spreadsheets.values, batchUpdate(options, function(err, res) {
    console.log(res);
    console.log(err);
});

Here are more examples of how to call batchUpdate:
https://github.com/gsuitedevs/node-samples/blob/master/sheets/snippets/snippets.js#L74

Feel free to file an issue on our Spreadsheets examples if you find problems there.

@jmdobry: Thank you!! I use the nodejs Google API library and using resources finally made the API call possible!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Chethandsagar picture Chethandsagar  路  4Comments

raapperez picture raapperez  路  3Comments

CyberT33N picture CyberT33N  路  3Comments

leecheve picture leecheve  路  3Comments

joseparoli picture joseparoli  路  3Comments