Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to read a single google sheets cell value in javascript

I am trying to pull just one cell value from a google sheet using javascript and the google sheets API, and I am using the below code, but I keep getting the below error which I can’t understand because I am using the spreadsheet id and range.

throw new Error(‘Missing required parameters: ‘ + missingParams.join(‘, ‘));
Error: Missing required parameters: spreadsheetId, range

const auth = new google.auth.GoogleAuth({
            keyFile: "sheets-credentials.json",
            scopes: "https://www.googleapis.com/auth/spreadsheets",
        });
const client = await auth.getClient();
const googleSheets = google.sheets({ version: "v4", auth: client });
const spreadsheetId = "asheetid";
googleSheets.spreadsheets.values.get(spreadsheetId, `Sheet1!D1`)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

In your script, please modify as follows.

From:

googleSheets.spreadsheets.values.get(spreadsheetId, `Sheet1!D1`)

To:

googleSheets.spreadsheets.values.get({spreadsheetId, range: `Sheet1!D1`});

Reference:

Added:

From your following replying,

Now there’s no error but it just returns "[object Promise]"

From this situation, I could confirm that your script worked. If you want to retrieve the values from googleSheets.spreadsheets.values.get({spreadsheetId, range: Sheet1!D1});, how about the following sample script?

Sample script1:

const res = await googleSheets.spreadsheets.values.get({spreadsheetId, range: `Sheet1!D1`});
console.log(res.data);

Sample script2:

googleSheets.spreadsheets.values.get(
  {
    spreadsheetId,
    range: `Sheet1!D1`,
  },
  (err, res) => {
    if (err) {
      console.log(err);
      return;
    }
    console.log(res.data);
  }
);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading