Add Rows ( gsheets)
One script reply has been approved by the moderators Verified

Created by rossmccrann 193 days ago Viewed 490 times 2 Points

No comments yet

Login to be able to comment
Points: 0
deno
One script reply has been approved by the moderators
Ap­pro­ved
import * as wmill from "https://deno.land/x/windmill@v1.23.0/mod.ts";

export async function main(
  gsheets_auth: wmill.Resource<"gsheets">,
  sheet_id: string,
  values: Array<Array<any>>,
  range: string = 'Sheet1'
) {
  const body = {
    "values": values,
  };

  const valueInputOption = "USER_ENTERED";
  const insertDataOption = "INSERT_ROWS";
  const includeValuesInResponse = true;
  const APPEND_URL =
    `https://sheets.googleapis.com/v4/spreadsheets/${sheet_id}/values/${range}:append/?valueInputOption=${valueInputOption}&insertDataOption=${insertDataOption}&includeValuesInResponse=${includeValuesInResponse}`;

  const token = gsheets_auth["token"];

  const response = await fetch(APPEND_URL, {
    method: "POST",
    body: JSON.stringify(body),
    headers: {
      Authorization: "Bearer " + token,
      "Content-Type": "application/json",
    },
  });

  const result = await response.json();

  return { result: result };
}

Submitted by rossmccrann 193 days ago

Edited 184 days ago

No comments yet

Login to be able to comment