googleapis / googleapis/google-api-nodejs-client

How do you properly use "batchUpdate" ?

Open
#3,120 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
12.2k
Forks
2k
Avg merge
1d 9h
Merged PRs (30d)
24

Description

I've been trying to find usable information for a few hours now but nothing. I want to use batchUpdate to update my cells. So far so good but it never really works the way I want it to. I can log in but nothing happens after (I should note that I'm working on AWS Lambda) :

`// import libraries and packagaes
const fs = require("fs");
const { google } = require("googleapis");
const pKey = require("./credentials.json");

exports.handler = (event) => {
updateCells(jwtClient);
};

// login with service account
let jwtClient = new google.auth.JWT(pKey.client_id, null, pKey.private_key, [
"https://www.googleapis.com/auth/spreadsheets",
]);
// authenticate request
jwtClient.authorize(function (err, tokens) {
if (err) {
console.log(err);
return;
} else {
console.log("Successfully connected!");
}
});

// batchUpdate (UpdateCellsRequest)
function updateCells(auth) {
// get payload
var payloadArray = fs.readFileSync("./test.csv").toString().split("\n");
const sheets = google.sheets({ version: "v4", auth: jwtClient });
sheets.spreadsheets.values.batchUpdate({
spreadsheetId: "ID",
resource: {
requests: [
{
updateCells: {
fields: "*",
rows: [
{
values: [
{
userEnteredValue: {
stringValue: "Some string",
},
},
],
},
],
range: {
sheetId: 0,
},
},
},
],
},
});
}
`
I used the request object from the documentation sites generator/ test box. Does anyone know how to make this work or point me to the right direction? Thank you in advance

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.