Skip to content

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

Closed

Description

@marcoBros

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

Activity

  1. ehgoodenough commented on Jun 8, 2016

    @ehgoodenough

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

  2. jmdobry commented on Jun 9, 2016

    @jmdobry
    Contributor

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

  3. dannongruver commented on Aug 27, 2016

    @dannongruver

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

  4. jmdobry commented on Aug 30, 2016

    @jmdobry
    Contributor

    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);
    });
  5. grant commented on Apr 13, 2018

    @grant
    Contributor

    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.

  6. strarsis commented on Jul 7, 2019

    @strarsis

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

  7. dandv commented on Jun 12, 2023

    @dandv

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

  8. removed their assignment
    on Jun 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions