1 | |
2 |
|
3 | type Gdocs = { |
4 | token: string; |
5 | }; |
6 | export async function main( |
7 | gdocs_auth: Gdocs, |
8 | documentId: string, |
9 | text: string, |
10 | ) { |
11 | const token = gdocs_auth["token"]; |
12 |
|
13 | const APPEND_TEXT_URL = `https://docs.googleapis.com/v1/documents/${documentId}:batchUpdate`; |
14 |
|
15 | const body = { |
16 | requests: [ |
17 | { |
18 | insertText: { text }, |
19 | }, |
20 | ], |
21 | }; |
22 | const response = await fetch(APPEND_TEXT_URL, { |
23 | method: "POST", |
24 | body: JSON.stringify(body), |
25 | headers: { |
26 | Authorization: "Bearer " + token, |
27 | "Content-Type": "application/json", |
28 | }, |
29 | }); |
30 |
|
31 | return await response.text(); |
32 | } |
33 |
|