I am working on a little project where I want to get a specific row from a specific Google sheet, by a specific value (last_name).
This is a Google sheet where I have a list of users.
I am using Express JS and the package googleapis for Node js.
Actually, this is the output I have with my API call.
[
[
"LASTNAME1",
"FIRSTNAME1",
"0100000000",
"email@email1.com"
],
[
"LASTNAME2",
"FIRSTNAME2",
"0100000000",
"email@email2.com"
],[
"LASTNAME3",
"FIRSTNAME3",
"0100000000",
"email@email3.com"
]
]
Actually I managed to sort the data like this but I don't know what to do next, can you help me?
[
'LASTNAME1, email@email1.com',
'LASTNAME2, email@email2.com',
'LASTNAME3, email@email3.com'
]
This is my method :
const auth = new google.auth.GoogleAuth({
keyFile: "keys.json",
scopes: "https://www.googleapis.com/auth/spreadsheets",
});
const authClientObject = await auth.getClient();
const googleSheetsInstance = google.sheets({ version: "v4", auth: authClientObject });
const spreadsheetId = "idofmygooglesheet";
const readData = await googleSheetsInstance.spreadsheets.values.get({
auth,
spreadsheetId,
range: "B10:M",
})
const rows = readData.data.values!;
let users: any[] = [];
if (rows.length) {
rows.map((row) => {
users.push(`${row[0]}, ${row[3]}`);
});
} else {
console.log('No user found with this name.');
}
console.log(users);
res.status(httpStatus.OK).json(readData.data.values);
Thank you very much for your help !