Add Rows

Script gsheets Verified

by rossmccrann ยท 7/26/2022

The script

Submitted by rossmccrann Deno
Verified 372 days ago
1
type Gsheets = {
2
  token: string;
3
};
4
export async function main(
5
  gsheets_auth: Gsheets,
6
  sheet_id: string,
7
  values: Array<Array<any>>,
8
  range: string = "Sheet1",
9
) {
10
  const body = {
11
    values: values,
12
  };
13

14
  const valueInputOption = "USER_ENTERED";
15
  const insertDataOption = "INSERT_ROWS";
16
  const includeValuesInResponse = true;
17
  const APPEND_URL = `https://sheets.googleapis.com/v4/spreadsheets/${sheet_id}/values/${range}:append/?valueInputOption=${valueInputOption}&insertDataOption=${insertDataOption}&includeValuesInResponse=${includeValuesInResponse}`;
18

19
  const token = gsheets_auth["token"];
20

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

30
  const result = await response.json();
31

32
  return { result: result };
33
}
34

Other submissions
  • Submitted by thanghm104 Python3
    Created 1065 days ago
    1
    import * as wmill from "https://deno.land/x/[email protected]/mod.ts";
    2
    
    
    3
    export async function main(
    4
      gsheets_auth: wmill.Resource<"gsheets">,
    5
      sheet_id: string,
    6
      values: Array<Array<any>>,
    7
      range: string = 'Sheet1'
    8
    ) {
    9
      const body = {
    10
        "values": values,
    11
      };
    12
    
    
    13
      const valueInputOption = "USER_ENTERED";
    14
      const insertDataOption = "INSERT_ROWS";
    15
      const includeValuesInResponse = true;
    16
      const APPEND_URL =
    17
        `https://sheets.googleapis.com/v4/spreadsheets/${sheet_id}/values/${range}:append/?valueInputOption=${valueInputOption}&insertDataOption=${insertDataOption}&includeValuesInResponse=${includeValuesInResponse}`;
    18
    
    
    19
      const token = gsheets_auth["token"];
    20
    
    
    21
      const response = await fetch(APPEND_URL, {
    22
        method: "POST",
    23
        body: JSON.stringify(body),
    24
        headers: {
    25
          Authorization: "Bearer " + token,
    26
          "Content-Type": "application/json",
    27
        },
    28
      });
    29
    
    
    30
      const result = await response.json();
    31
    
    
    32
      return { result: result };
    33
    }