1 | import * as wmill from "https://deno.land/x/windmill@v1.85.0/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 | } |