Back to Top

libraries > Googlesheets.js

new GoogleSheets(request)

Methods to interact with the GoogleSheets API.

Parameters

Name Type Description
request Oauth

Authenticated request.

Properties

Name Type Description
basePath string

Google Sheets API base path.

request Oauth

Authenticated request.

headers array

Sheets headers.

Returns

class

GoogleSheets.read()

Google Sheets basic reading

Examples

const Google = require('vendor/Google.js');
let secretsKeys = {
   refresh_token: "example_secret_refresh_token",
   access_token: "example_secret_access_token",
   expires_at: "example_secret_expires_at",
   client_id: "example_secret_client_id",
   client_secret: "example_secret_client_secret",
};
const google = new Google('refresh_token', secretsKeys);
const basicReading = google.sheets.basicReading('3p9f4pf-gS2jA_HpC1Yt-3MhQSOMNluRrmBlPcUC2Ugts', "Sheet1", "A1","D5");
Mesa.log.info('Basic Reading: ', basicReading);

Returns

Void

GoogleSheets.write()

Google Sheets writing

Examples

const Google = require('vendor/Google.js');
let secretsKeys = {
   refresh_token: "example_secret_refresh_token",
   access_token: "example_secret_access_token",
   expires_at: "example_secret_expires_at",
   client_id: "example_secret_client_id",
   client_secret: "example_secret_client_secret",
};
const google = new Google('refresh_token', secretsKeys);
const values = [[ "customer_id", "customer_name"], [ "1234", "Joe doe"]];
const payload = {range: "Sheet1!A1:D5",majorDimension: "ROWS",values: values};
const basicWriting = google.sheets.basicWriting('3p9f4pf-gS2jA_HpC1Yt-3MhQSOMNluRrmBlPcUC2Ugts', "Sheet1", "A1","D5", payload);
Mesa.log.info('Basic Writing: ', basicWriting);

Returns

Void

GoogleSheets.addOrUpdate(rowPayload, sheetPayload[, headerId=null, columnKey=null, id=null])

Adds or updates a Google Sheets Payload.

To support updates to the payload, you need to pass the headerId, columnKey and Id.

Parameters

Name Type Description
rowPayload array

Array with row payload.

sheetPayload array

Google Sheets payload.

headerId=null number

Location of the header.

Optional
columnKey=null string

Column name of the forgein key.

Optional
id=null string

Payload ID, in the case of a duplicated ID we will update the payload.

Optional

Examples

const Google = require('vendor/Google.js');
let secretsKeys = {
   refresh_token: "example_secret_refresh_token",
   access_token: "example_secret_access_token",
   expires_at: "example_secret_expires_at",
   client_id: "example_secret_client_id",
   client_secret: "example_secret_client_secret",
};
const google = new Google('refresh_token', secretsKeys);
const rowPayload = ['12345', 'Mary Jane'];
const sheetPayload = [[ "customer_id", "customer_name"], [ "1234", "Joe doe"]];
const updatedSheetsPayload = google.sheets.addOrUpdate(rowPayload, sheetPayload, 0, 'customer_id', '12345');
Mesa.log.info('Sheets Payload', updatedSheetsPayload);
// [[ "customer_id", "customer_name"], [ "1234", "Joe doe"], [ "12345", "Mary Jane"]]

Returns

Void