import * as wmill from "https://deno.land/x/windmill@v1.46.2/mod.ts";
/** @param range 'A1' notation or 'R1C1' notation (https://developers.google.com/sheets/api/guides/concepts#cell) */
export async function main(
gsheets_auth: wmill.Resource<"gsheets">,
spreadsheetId: string,
range: string,
dimension: 'DEFAULT' | 'ROWS' | 'COLUMNS' = 'DEFAULT'
) {
const token = gsheets_auth["token"];
let GET_CELLS_URL =
`https://sheets.googleapis.com/v4/spreadsheets/${spreadsheetId}/values/${range}`;
if(dimension !== 'DEFAULT') {
GET_CELLS_URL += `?majorDimension=${dimension}`
}
const response = await fetch(GET_CELLS_URL, {
method: "GET",
headers: {
Authorization: "Bearer " + token,
"Content-Type": "application/json",
},
});
const json = await response.json()
if (json.error) {
const { code, status, message } = json.error
throw Error(`\n${code} ${status} - "${message}"`)
}
return json;
}
Submitted by adam-kov 768 days ago