1 | |
2 |
|
3 | type Gsheets = { |
4 | token: string; |
5 | }; |
6 | export async function main( |
7 | gsheets_auth: Gsheets, |
8 | spreadsheetId: string, |
9 | title: string, |
10 | ) { |
11 | const token = gsheets_auth["token"]; |
12 |
|
13 | const ADD_WORKSHEET_URL = `https://sheets.googleapis.com/v4/spreadsheets/${spreadsheetId}:batchUpdate`; |
14 |
|
15 | const body = { |
16 | requests: [ |
17 | { |
18 | addSheet: { |
19 | properties: { |
20 | title: title, |
21 | gridProperties: { |
22 | rowCount: 20, |
23 | columnCount: 12, |
24 | }, |
25 | tabColor: { |
26 | red: 1.0, |
27 | green: 0.3, |
28 | blue: 0.4, |
29 | }, |
30 | }, |
31 | }, |
32 | }, |
33 | ], |
34 | }; |
35 |
|
36 | const response = await fetch(ADD_WORKSHEET_URL, { |
37 | method: "POST", |
38 | body: JSON.stringify(body), |
39 | headers: { |
40 | Authorization: "Bearer " + token, |
41 | "Content-Type": "application/json", |
42 | }, |
43 | }); |
44 |
|
45 | return await response.text(); |
46 | } |
47 |
|