Skip to main content

gsheets.googlesheets

Home > @runlightyear/gsheets > GoogleSheets

GoogleSheets class

This API is in beta and may contain contain bugs. Can be used in production with caution.

Google Sheets Connector

Signature:
declare class GoogleSheets extends RestConnector 

Extends:

RestConnector

Example 1

Create a spreadsheet

import { defineAction } from "@runlightyear/lightyear";
import { GoogleSheets } from "@runlightyear/gsheets";

defineAction({
name: "createSpreadsheet",
title: "Create Spreadsheet",
apps: ["gsheets"],
variables: ["title"],
run: async ({ auths, variables }) => {
const gsheets = new GoogleSheets({
auth: auths.gsheets,
});

const response = await gsheets.createSpreadsheet({
title: variables.title!,
});

console.log("Response: ", response.data);
},
});

Example 2

Get a row

import { defineAction } from "@runlightyear/lightyear";
import { GoogleSheets } from "@runlightyear/gsheets";

defineAction({
name: "getRow",
title: "Get Row",
apps: ["gsheets"],
variables: ["spreadsheetId"],
run: async ({ auths, variables }) => {
const gsheets = new GoogleSheets({
auth: auths.gsheets,
});

const response = await gsheets.getValues({
spreadsheetId: variables.spreadsheetId!,
range: "1:1",
});

console.log("Response: ", response.data);
},
});

Example 3

Get a column

import { defineAction } from "@runlightyear/lightyear";
import { GoogleSheets } from "@runlightyear/gsheets";

defineAction({
name: "getColumn",
title: "Get Column",
apps: ["gsheets"],
variables: ["spreadsheetId"],
run: async ({ auths, variables }) => {
const gsheets = new GoogleSheets({
auth: auths.gsheets,
});

const response = await gsheets.getValues({
spreadsheetId: variables.spreadsheetId!,
range: "A:A",
majorDimension: "COLUMNS",
});

console.log("Response: ", response.data);
},
});

Example 4

Get all rows and columns

import { defineAction } from "@runlightyear/lightyear";
import { GoogleSheets } from "@runlightyear/gsheets";

defineAction({
name: "getAllRowsAndColumns",
title: "Get All Rows And Columns",
apps: ["gsheets"],
variables: ["spreadsheetId", "worksheetName"],
run: async ({ auths, variables }) => {
const gsheets = new GoogleSheets({
auth: auths.gsheets,
});

const response = await gsheets.getValues({
spreadsheetId: variables.spreadsheetId!,
range: `${variables.worksheetName!}`,
});

console.log("Response: ", response.data);
},
});

Example 5

Append a row

import { defineAction } from "@runlightyear/lightyear";
import { GoogleSheets } from "@runlightyear/gsheets";

defineAction({
name: "appendRow",
title: "Append Row",
apps: ["gsheets"],
variables: ["spreadsheetId"],
run: async ({ auths, variables }) => {
const gsheets = new GoogleSheets({
auth: auths.gsheets,
});
const response = await gsheets.appendValues({
spreadsheetId: variables.spreadsheetId!,
range: "1:1",
valueInputOption: "RAW",
valueRange: {
range: "1:1",
values: [[1, 2, 3]],
},
});
console.log("Response: ", response.data);
},
});

Example 6

Append multiple rows

import { defineAction } from "@runlightyear/lightyear";
import { GoogleSheets } from "@runlightyear/gsheets";

defineAction({
name: "appendRow",
title: "Append Row",
apps: ["gsheets"],
variables: ["spreadsheetId"],
run: async ({ auths, variables }) => {
const gsheets = new GoogleSheets({
auth: auths.gsheets,
});
const response = await gsheets.appendValues({
spreadsheetId: variables.spreadsheetId!,
range: "1:1",
valueInputOption: "RAW",
valueRange: {
range: "1:1",
values: [[1, 2, 3]],
},
});
console.log("Response: ", response.data);
},
});

Example 7

Update a row

import { defineAction } from "@runlightyear/lightyear";
import { GoogleSheets } from "@runlightyear/gsheets";

function randomNumber() {
return Math.floor(Math.random() * 10);
}

defineAction({
name: "updateRow",
title: "Update Row",
apps: ["gsheets"],
variables: ["spreadsheetId"],
run: async ({ auths, variables }) => {
const gsheets = new GoogleSheets({
auth: auths.gsheets,
});

const response = await gsheets.updateValues({
spreadsheetId: variables.spreadsheetId!,
range: "1:1",
valueInputOption: "RAW",
valueRange: {
range: "1:1",
majorDimension: "ROWS",
values: [[randomNumber(), randomNumber(), randomNumber()]],
},
});

console.log("Response: ", response.data);
},
});

Example 8

Update a column

import { defineAction } from "@runlightyear/lightyear";
import { GoogleSheets } from "@runlightyear/gsheets";

function randomNumber() {
return Math.floor(Math.random() * 10);
}

defineAction({
name: "updateColumn",
title: "Update Column",
apps: ["gsheets"],
variables: ["spreadsheetId"],
run: async ({ auths, variables }) => {
const gsheets = new GoogleSheets({
auth: auths.gsheets,
});

const response = await gsheets.updateValues({
spreadsheetId: variables.spreadsheetId!,
range: "A:A",
valueInputOption: "RAW",
valueRange: {
range: "A:A",
majorDimension: "COLUMNS",
values: [[randomNumber(), randomNumber(), randomNumber()]],
},
});

console.log("Response: ", response.data);
},
});

Example 9

Update rows and columns

import { defineAction } from "@runlightyear/lightyear";
import { GoogleSheets } from "@runlightyear/gsheets";

defineAction({
name: "updateRowsAndColumns",
title: "Update Rows and Columns",
apps: ["gsheets"],
variables: ["spreadsheetId"],
run: async ({ auths, variables }) => {
const gsheets = new GoogleSheets({
auth: auths.gsheets,
});

const response = await gsheets.updateValues({
spreadsheetId: variables.spreadsheetId!,
range: "A1:C3",
valueInputOption: "RAW",
valueRange: {
range: "A1:C3",
majorDimension: "ROWS",
values: [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9],
],
},
});

console.log("Response: ", response.data);
},
});

Example 10

Clear a row

import { defineAction } from "@runlightyear/lightyear";
import { GoogleSheets } from "@runlightyear/gsheets";

defineAction({
name: "clearRow",
title: "Clear Row",
apps: ["gsheets"],
variables: ["spreadsheetId"],
run: async ({ auths, variables }) => {
const gsheets = new GoogleSheets({
auth: auths.gsheets,
});

const response = await gsheets.clearValues({
spreadsheetId: variables.spreadsheetId!,
range: "1:1",
});

console.log("Response: ", response.data);
},
});

Example 11

Clear a column

import { defineAction } from "@runlightyear/lightyear";
import { GoogleSheets } from "@runlightyear/gsheets";

defineAction({
name: "clearColumn",
title: "Clear Column",
apps: ["gsheets"],
variables: ["spreadsheetId"],
run: async ({ auths, variables }) => {
const gsheets = new GoogleSheets({
auth: auths.gsheets,
});

const response = await gsheets.clearValues({
spreadsheetId: variables.spreadsheetId!,
range: "A:A",
});

console.log("Response: ", response.data);
},
});

Example 12

On new rows

import { GoogleSheets } from "@runlightyear/gsheets";

GoogleSheets.onNewRows({
name: "onNewRows",
title: "On New Rows",
apps: ["gsheets"],
pollingFrequency: 1,
run: async ({ data }) => {
console.log("Data: ", data);
},
});

Constructors

ConstructorModifiersDescription
(constructor)(props)(BETA) Constructs a new instance of the GoogleSheets class

Properties

PropertyModifiersTypeDescription
authTypestaticAuthType(BETA)
OAuthstatictypeof GoogleSheetsOAuth(BETA)

Listener Methods

MethodModifiersDescription
onNewRows(props)static(BETA) On new rows in a spreadsheet.

Spreadsheet Methods

MethodModifiersDescription
createSpreadsheet(props)(BETA) Creates a spreadsheet, returning the newly created spreadsheet.

Value Methods

MethodModifiersDescription
appendValues(props)(BETA) Appends values to a spreadsheet.
clearValues(props)(BETA) Clear values from a spreadsheet.
getValues(props)(BETA) Returns a range of values from a spreadsheet.
updateValues(props)(BETA) Sets values in a range of a spreadsheet.

Other Methods

MethodModifiersDescription
getBaseUrl()(BETA)