2
Add Rows
One script reply has been approved by the moderators Verified
Created by rossmccrann 843 days ago Viewed 128452 times
0
Submitted by rossmccrann Deno
Verified 843 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