Delete Worksheet

Script gsheets Verified

by rossmccrann ยท 7/27/2022

The script

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

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

13
  const DELETE_WORKSHEET_URL = `https://sheets.googleapis.com/v4/spreadsheets/${spreadsheetId}:batchUpdate`;
14

15
  const body = {
16
    requests: [
17
      {
18
        deleteSheet: {
19
          sheetId: sheetId,
20
        },
21
      },
22
    ],
23
  };
24

25
  const response = await fetch(DELETE_WORKSHEET_URL, {
26
    method: "POST",
27
    body: JSON.stringify(body),
28
    headers: {
29
      Authorization: "Bearer " + token,
30
      "Content-Type": "application/json",
31
    },
32
  });
33

34
  return await response.text();
35
}
36

Other submissions
  • Submitted by rossmccrann Deno
    Created 395 days ago
    1
    type Gsheets = {
    2
      token: string;
    3
    };
    4
    export async function main(
    5
      gsheets_auth: Gsheets,
    6
      spreadsheetId: string,
    7
      sheetId: number,
    8
    ) {
    9
      const token = gsheets_auth["token"];
    10
    
    
    11
      const DELETE_WORKSHEET_URL = `https://sheets.googleapis.com/v4/spreadsheets/${spreadsheetId}:batchUpdate`;
    12
    
    
    13
      const body = {
    14
        requests: [
    15
          {
    16
            deleteSheet: {
    17
              sheetId: sheetId,
    18
            },
    19
          },
    20
        ],
    21
      };
    22
    
    
    23
      const response = await fetch(DELETE_WORKSHEET_URL, {
    24
        method: "POST",
    25
        body: JSON.stringify(body),
    26
        headers: {
    27
          Authorization: "Bearer " + token,
    28
          "Content-Type": "application/json",
    29
        },
    30
      });
    31
    
    
    32
      return await response.text();
    33
    }
    34