1

Append Rows

by
Published Jul 27, 2022
Script gsheets
  • Submitted by rossmccrann Deno
    Created 1429 days ago
    1
    import * as wmill from "https://deno.land/x/[email protected]/mod.ts";
    2
    
    
    3
    export async function main(gsheets_auth: wmill.Resource<"gsheets">,
    4
        spreadsheetId: string,
    5
        range: string,
    6
        values: Array<any>,
    7
    ) {
    8
    
    
    9
        const token = gsheets_auth["token"];
    10
        const valueInputOption = 'USER_ENTERED';
    11
        const APPEND_ROWS_URL =
    12
            `https://sheets.googleapis.com/v4/spreadsheets/${spreadsheetId}/values/${range}:append?valueInputOption=${valueInputOption}`;
    13
    
    
    14
        const body = {
    15
            "range": range,
    16
            "majorDimension": "ROWS",
    17
            "values": [values],
    18
        };
    19
    
    
    20
        const response = await fetch(APPEND_ROWS_URL, {
    21
            method: "POST",
    22
            body: JSON.stringify(body),
    23
            headers: {
    24
                Authorization: "Bearer " + token,
    25
                "Content-Type": "application/json",
    26
            },
    27
        });
    28
    
    
    29
        const text = await response.text()
    30
    
    
    31
        return text;
    32
    }