Edits history of script submission #22378 for ' Append Text (gdocs)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    type Gdocs = {
      token: string;
    };
    export async function main(
      gdocs_auth: Gdocs,
      documentId: string,
      text: string,
    ) {
      const token = gdocs_auth["token"];
    
      const APPEND_TEXT_URL = `https://docs.googleapis.com/v1/documents/${documentId}:batchUpdate`;
    
      const body = {
        requests: [
          {
            insertText: { text },
          },
        ],
      };
      const response = await fetch(APPEND_TEXT_URL, {
        method: "POST",
        body: JSON.stringify(body),
        headers: {
          Authorization: "Bearer " + token,
          "Content-Type": "application/json",
        },
      });
    
      return await response.text();
    }
    

    Submitted by hugo989 6 days ago