1 | import * as wmill from "https://deno.land/x/windmill@v1.46.2/mod.ts"; |
2 |
|
3 |
|
4 | export async function main(gsheets_auth: wmill.Resource<"gsheets">, |
5 | spreadsheetId: string, |
6 | range: string |
7 | ) { |
8 |
|
9 | const token = gsheets_auth["token"]; |
10 |
|
11 | const CLEAR_CELLS_URL = |
12 | `https://sheets.googleapis.com/v4/spreadsheets/${spreadsheetId}/values/${range}:clear`; |
13 |
|
14 | const response = await fetch(CLEAR_CELLS_URL, { |
15 | method: "POST", |
16 | headers: { |
17 | Authorization: "Bearer " + token, |
18 | "Content-Type": "application/json", |
19 | }, |
20 | }); |
21 |
|
22 | const json = await response.json() |
23 | if(json.error) { |
24 | const { code, status, message} = json.error |
25 | throw Error(`\n${code} ${status} - "${message}"`) |
26 | } |
27 | return `Cells cleared in the range of '${json.clearedRange}'`; |
28 | } |