1

Append Text

by
Published Jul 27, 2022
Script gdocs Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 6 days ago
1
//native
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

Other submissions
  • Submitted by rossmccrann Deno
    Created 398 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