1
Append Text
One script reply has been approved by the moderators Verified
Created by rossmccrann 633 days ago Viewed 4511 times
0
Submitted by rossmccrann Deno
Verified 633 days ago
1
type Gdocs = {
2
  token: string;
3
};
4
export async function main(
5
  gdocs_auth: Gdocs,
6
  documentId: string,
7
  text: string,
8
) {
9
  const token = gdocs_auth["token"];
10

11
  const APPEND_TEXT_URL = `https://docs.googleapis.com/v1/documents/${documentId}:batchUpdate`;
12

13
  const body = {
14
    requests: [
15
      {
16
        insertText: { text },
17
      },
18
    ],
19
  };
20
  const response = await fetch(APPEND_TEXT_URL, {
21
    method: "POST",
22
    body: JSON.stringify(body),
23
    headers: {
24
      Authorization: "Bearer " + token,
25
      "Content-Type": "application/json",
26
    },
27
  });
28

29
  return await response.text();
30
}
31