1
List Worksheets
One script reply has been approved by the moderators Verified
Created by rossmccrann 631 days ago Viewed 4387 times
0
Submitted by rossmccrann Deno
Verified 631 days ago
1
type Gsheets = {
2
  token: string;
3
};
4
export async function main(gsheets_auth: Gsheets, spreadsheetId: string) {
5
  const token = gsheets_auth["token"];
6

7
  const GET_WORKSHEET_URL = `https://sheets.googleapis.com/v4/spreadsheets/${spreadsheetId}?&fields=sheets.properties`;
8

9
  const response = await fetch(GET_WORKSHEET_URL, {
10
    method: "GET",
11
    headers: {
12
      Authorization: "Bearer " + token,
13
      "Content-Type": "application/json",
14
    },
15
  });
16
  const text = await response.json();
17

18
  let list = [];
19
  for (let i in text["sheets"]) {
20
    list.push({
21
      sheetId: text["sheets"][i]["properties"]["sheetId"],
22
      title: text["sheets"][i]["properties"]["title"],
23
    });
24
  }
25

26
  return list;
27
}
28