Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google sheet API v4 - batchUpdate provide error : Invalid JSON. Unknown name "data". #588

Closed
marcoBros opened this issue May 30, 2016 · 7 comments

Comments

@marcoBros
Copy link

marcoBros commented May 30, 2016

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

@ehgoodenough
Copy link

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

@jmdobry
Copy link
Contributor

jmdobry commented Jun 9, 2016

@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.

@dannongruver
Copy link

dannongruver commented Aug 27, 2016

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

@jmdobry
Copy link
Contributor

jmdobry commented Aug 30, 2016

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);
});

@grant
Copy link
Contributor

grant commented Apr 13, 2018

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.

@grant grant closed this as completed Apr 13, 2018
@strarsis
Copy link

strarsis commented Jul 7, 2019

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

@dandv
Copy link

dandv commented Jun 12, 2023

I got this error by using UrlFetchApp (i.e. the REST API). Turns out I had forgotten to JSON.stringify() the payload.

@grant grant removed their assignment Jun 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants