1

Copy Worksheet

by
Published Jul 27, 2022
Script gsheets Verified

The script

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

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

14
  const COPY_TO_URL = `https://sheets.googleapis.com/v4/spreadsheets/${spreadsheet_id_1}/sheets/${sheet_id}:copyTo`;
15

16
  const req = {
17
    destinationSpreadsheetId: spreadsheet_id_2,
18
  };
19

20
  const response = await fetch(COPY_TO_URL, {
21
    method: "POST",
22
    body: JSON.stringify(req),
23
    headers: {
24
      Authorization: "Bearer " + token,
25
      "Content-Type": "application/json",
26
    },
27
  });
28

29
  return await response.text();
30
}
31

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