Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

This operation is not supported for this document at Gaxios - NodeJS - Spreadsheet Google

I'm trying to access the information in my spreadsheet according to the code below and I have this error that I don't quite understand the reason for.

I already gave permission for the credentials email on google ...

const { google } = require("googleapis");
const creds = require("./config/gCredentials.json");

const client = new google.auth.JWT(
  creds.client_email,
  null,
  creds.private_key,
  ["https://www.googleapis.com/auth/spreadsheets"]
);

client.authorize(function (err, tokens) {
  if (err) {
    console.log(err);
  } else {
    console.log("connected");
    gsrun(client);
  }
});

async function gsrun(cl) {
  const gsapi = google.sheets({ version: "v4", auth: cl });

  const opt = {
    spreadsheetId: "XYZ",
    range: "SheetA!A1:B14",
  };

  let data = await gsapi.spreadsheets.values.get(opt);
  console.log(data);
}

Any idea what it might be?

Error console

connected
(node:31301) UnhandledPromiseRejectionWarning: Error: This operation is not supported for this document
    at Gaxios.<anonymous> (****/node_modules/googleapis/node_modules/gaxios/build/src/gaxios.js:73:27)
    at Generator.next (<anonymous>)
    at fulfilled (****/node_modules/googleapis/node_modules/gaxios/build/src/gaxios.js:16:58)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:31301) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:31301) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
like image 472
lams Avatar asked Jun 17 '20 16:06

lams


1 Answers

I was able to identify the problem. The code is correct, however, the file on the google drive was saved as xlsx and not as a google spreadsheet ...

I converted the spreadsheet by going to File> Save as Google Sheet.

Thanks

like image 93
lams Avatar answered Nov 07 '22 12:11

lams