Node Google Docs REST API Batch update invalid JSON payload/missing documentId

Node Google Docs REST API Batch update invalid JSON payload/missing documentId

When attempting to perform a batch update and I receive a Invalid JSON payload error; and trying to stringify JSON gives a 'missing documentId' error. The problem isn't with OAuth, the token or document scope as these are all correct and functioning (scope was changed from the example's read only to the full document scope).

When attempting to perform a batch update and I receive a Invalid JSON payload error; and trying to stringify JSON gives a 'missing documentId' error. The problem isn't with OAuth, the token or document scope as these are all correct and functioning (scope was changed from the example's read only to the full document scope).

Since there isn't an example for Google's new batch update API in node I have been having significant issues with batch update. After some troubleshooting with the batchUpdate constructor I have narrowed down my issue to (potentially) a larger issue with the API url constructor, or my syntax is wrong (or both.) Or I am missing steps to create the appropriate objects for the API call (no documentation is present for these tasks)

Inside a callback after successful get document as per google node quickstart guide (mostly)

    let offset = startIndex + 12
    let updateObject = {
      documentId:doc_id,
      requests:
        [{
          insertTextRequest : 
            {
              text : 'John Doe',
              location : {
                index : offset
              }
            }
        }]
      } 
    docs.documents.batchUpdate(updateObject,function(e,r){
      console.log(e)
      console.log(r)
    }

Google API response

'Invalid JSON payload received. Unknown name "requests[insertText][location][index]": Cannot bind query parameter. Field \'requests[insertText][location][index]\' could not be found in request message.\nInvalid JSON payload received. Unknown name "requests[insertText][text]": Cannot bind query parameter. Field \'requests[insertText][text]\' could not be found in request message.',
   domain: 'global',
   reason: 'badRequest' } ] }

Response after trying JSON.stringify(updateObject) - truncated

Error: Missing required parameters: documentId
at node_modules\googleapis-common\build\src\apirequest.js:114:19
at Generator.next (<anonymous>)

My best guess is some kind of google voodoo magic needs to occur for the API to properly encode the JSON object for the request to succeed.

  • Changing the array of a single request to an object had no effect on the above.
  • Using single/double quotes for the request object parameter names/string variable had no effect.
  • Document ID is a string, works, just not shown in the code example.
  • Adding documentId field to the request had no effect.


node-js json rest

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

How to Create a Fake REST API Server using Node.js

How to make a REST API Server using Node.js for testing your AJAX client side.

How to Hire Node.js Developers And How Much Does It Cost?

A Guide to Hire Node.js Developers who can help you create fast and efficient web applications. Also, know how much does it cost to hire Node.js Developers.

What is REST API? An Overview | Liquid Web

What is REST? The REST acronym is defined as a “REpresentational State Transfer” and is designed to take advantage of existing HTTP protocols when used

Building A REST API Using Node.JS | Node.js RESTful API Tutorial

Building A Rest API Using Node JS will help you understand the concept of RESTful APIs and also show you how to implement this in your real world web applications.

Hire Node.JS Developers | Skenix Infotech

We are providing robust Node.JS Development Services with expert Node.js Developers. Get affordable Node.JS Web Development services from Skenix Infotech.