1

List Worksheets

by
Published Jul 27, 2022
Script gsheets Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 15 days ago
1
//native
2

3
type Gsheets = {
4
  token: string;
5
};
6
export async function main(gsheets_auth: Gsheets, spreadsheetId: string) {
7
  const token = gsheets_auth["token"];
8

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

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

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

28
  return list;
29
}
30

Other submissions
  • Submitted by rossmccrann Deno
    Created 407 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