1

Create a New Document

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(gdocs_auth: Gdocs, title: string) {
7
  const token = gdocs_auth["token"];
8

9
  const body = {
10
    title: title,
11
  };
12
  const CREATE_DOC_URL = `https://docs.googleapis.com/v1/documents`;
13

14
  const response = await fetch(CREATE_DOC_URL, {
15
    method: "POST",
16
    body: JSON.stringify(body),
17
    headers: {
18
      Authorization: "Bearer " + token,
19
      "Content-Type": "application/json",
20
    },
21
  });
22

23
  return await response.text();
24
}
25

Other submissions
  • Submitted by rossmccrann Deno
    Created 398 days ago
    1
    type Gdocs = {
    2
      token: string;
    3
    };
    4
    export async function main(gdocs_auth: Gdocs, title: string) {
    5
      const token = gdocs_auth["token"];
    6
    
    
    7
      const body = {
    8
        title: title,
    9
      };
    10
      const CREATE_DOC_URL = `https://docs.googleapis.com/v1/documents`;
    11
    
    
    12
      const response = await fetch(CREATE_DOC_URL, {
    13
        method: "POST",
    14
        body: JSON.stringify(body),
    15
        headers: {
    16
          Authorization: "Bearer " + token,
    17
          "Content-Type": "application/json",
    18
        },
    19
      });
    20
    
    
    21
      return await response.text();
    22
    }
    23