Code | npm | Code sample
npm install reshuffle-smartsheet-connector
This package contains a Reshuffle connector to access to online spreadsheets at smartsheet.com.
The following example tracks changes to an online spreadtsheet. Changes are reported at the sheet level, row level and cell level:
const { Reshuffle } = require('reshuffle')
const { SmartsheetConnector } = require('reshuffle-smartsheet-connector')
const app = new Reshuffle()
const ssh = new SmartsheetConnector(app, {
apiKey: process.env.SMARTSHEET_API_KEY,
baseURL: process.env.RESHUFFLE_RUNTIME_BASE_URL,
})
ssh.on({ sheetId: sheet.sheetId }, async (event) => {
console.log('Smartsheet event:', event)
})
async function main() {
const sheet = await ssh.findOrCreateSheet('Reshuffle Events Example', [
{ title: 'Name', type: 'TEXT_NUMBER', primary: true },
{ title: 'Quest', type: 'TEXT_NUMBER' },
{ title: 'Color', type: 'TEXT_NUMBER' },
])
if (sheet.created) {
await ssh.addRowToBottom(sheet.sheetId, [
{ columnId: sheet.columns[0].id, value: 'Arthur' },
{ columnId: sheet.columns[1].id, value: 'Find the Holy Grail' },
{ columnId: sheet.columns[2].id, value: 'Blue' },
])
}
console.log(`Please visit ${sheet.permalink} and make some changes`)
}
app.start()
main().catch(console.error)Configuration Configuration options
sheetChanged Sheet changed
addRows Add rows to a sheet
addRowToBottom Add one row at the bottom of a sheet
addRowToTop Add one row at the top of a sheet
createSheet Create a new sheet
deleteRow Delete one row
findOrCreateSheet Find or create a sheet
getImage Get image from a sheet cell
getSheetById Get sheet data by sheet id
getSheetIdByName Find sheet id by its name
getSheetByName Get sheet data by sheet name
getSimpleSheetById Get a simple sheet object by ID
getSimpleSheetByName Get a simple sheet object by name
getRow Get row information
listSheets List all sheets
listRows List rows in a sheet
update Update a sheet
sdk Get direct SDK access
const app = new Reshuffle()
const smartsheetConnector = new SmaetsheetConnector(app, {
apiKey: process.env.SMARTSHEET_API_KEY,
baseURL: process.env.RESHUFFLE_RUNTIME_BASE_URL, // optional but required
// for events
})Example:
async (event) => {
console.log('Smartsheet event:', event)
})This event is fired when a Smartsheet webhook is triggered. Triggers include sheet update, row update, cell update and more.
See event.js for an example of defining and handling sheet events.
Add rows to a sheet.
Definition:
(
sheetId: number | string,
rows: object,
) => voidUsage:
await smartsheetConnector.addRows(4583173393803140, [
{
toTop: true,
cells: [
{
columnId: 7960873114331012,
value: true,
},
{
columnId: 642523719853956,
value: 'New status',
strict: false,
},
],
},
{
toBottom: true,
cells: [
{
columnId: 7960873114331012,
value: true,
},
{
columnId: 642523719853956,
value: 'New status',
strict: false,
},
],
},
])Add one row after the last row of a sheet.
Definition:
(
sheetId: number | string,
cells: object[],
) => voidUsage:
await smartsheetConnector.addRowToBottom(4583173393803140, {
{ columnId: 7960873114331012, value: true },
{ columnId: 642523719853956, value: 'New status' }
})Add one row before the first row of a sheet.
Definition:
(
sheetId: number | string,
cells: object[],
) => voidUsage:
await smartsheetConnector.addRowToTop(4583173393803140, {
{ columnId: 7960873114331012, value: true },
{ columnId: 642523719853956, value: 'New status' }
})Create a new sheet.
Definition:
(
name: string,
columns: object[]
) => objectUsage:
await smartsheetConnector.createSheet('My Sheet', [
{ title: 'Name', type: 'TEXT_NUMBER', primary: true },
{ title: 'City', type: 'TEXT_NUMBER' },
])Delete a single row from the specified sheet.
Definition:
(
sheetId: number | string,
rowId: number | string,
) => voidUsage:
await smartsheetConnector.deleteRow(4583173393803140, 1234567890123456)This action offers the same interface as createSheet above,
but checks first whether a sheet with the specified name exists. If so,
that sheet is returned. Otherwise, a new one is created.
The action returns an object with the following fields:
accessLevel: string
columns: object[]
created: boolean
name: string
permalink: string
sheetId: numberDefinition:
(
sheetId: number | string,
rowId: number | string,
) => objectUsage:
await smartsheetConnector.findOrCreateSheet('My Sheet', [
{ title: 'Name', type: 'TEXT_NUMBER', primary: true },
{ title: 'City', type: 'TEXT_NUMBER' },
])Get an image stored in a sheet cell. sheetId and rowId specify the
specific row to query. columnIdOrIndex is treated as an index if it is
a number smaller than 1024, otherwise it is treated as a column id.
The returned image data includes a unique ID, the alternative text (usually the original file name) and a download URL. The URL is valid for half an hour.
Use the optional width and height arguments to get a link to a resized
image.
Definition:
(
sheetId: number | string,
rowId: number | string,
columnIdOrIndex: number | string,
width?: number,
height?: number,
) => objectUsage:
const img = await smartsheetConnector.getImage(
4583173393803140,
000000000000000,
3,
)
console.log(img.id, img.text, img.url)Get full sheet data
for the sheet with the specified id.
Definition:
(
sheetId: number | string,
) => objectUsage:
const sheetData = await smartsheetConnector.getSheetById(4583173393803140)Lookup the sheet ID for the sheet with the specified name. If a sheet with that name is not found then an Error is thrown.
Definition:
(
name: string,
) => numberUsage:
const sheetId = await smartsheetConnector.getSheetIdByName('My Sheet')Get full sheet data
for the sheet with the specified name. If a sheet with that name is not
found then an Error is thrown.
Definition:
(
name: string,
) => objectUsage:
const sheetData = await smartsheetConnector.getSheetByName('My Sheet')Get a SimpleSheet object representing the sheet with the specified
id. This object provides the following methods:
getColumnIdByTitle(
columnTitle: string,
): number // Get column ID by column title
getUpdater(): object // Create an updater object
pivot(
pivotColumn: string,
property: string,
matchColumns: string[],
includeRowIDs?: boolean,
): object // Build a pivot table
toSCV(): string // Create a CSV representationAn updater object provides the following methods:
addUpdate(
columnTitle: string,
rowId: number | string,
value: string,
) // Add a cell value to be updated
getSheetId(): number // Get the sheet ID
getUpdates(): object // Get the updates for using with the update actionDefinition:
(
sheetId: number | string,
) => objectUsage:
const sheet = await smartsheetConnector.getSimpleSheetById(4583173393803140)
const updater = sheet.getUpdater()
updater.addUpdate('My Column', 000000000000000, 'New Value')
await smartsheetConnector.update(updater.getSheetId(), updater.getUpdates())Get a SimpleSheet object representing the sheet with the specified
name. See getSimpleSheetById for details.
Definition:
(
name: string,
) => objectGet information about the specified row in the specified sheet. Row information is detailed here.
Definition:
(
sheetId: number | string,
rowId: number | string,
) => objectUsage:
const row = await smartsheetConnector.getRow(
4583173393803140,
1234567890123456,
)Get a list of row Ids in the specified sheet.
Definition:
(
sheetId: number | string,
) => number[]Usage:
const rowIds = await smartsheetConnector.listRows(4583173393803140)Get a list of all sheets in the connected Smartsheet account. For each sheet, the following information is returned:
- id - Sheet ID
- name - Sheet name
- accessLevel - Usually 'OWNER'
- permalink - Link to the sheet's online page
- createdAt - Creation time stamp
- modifiedAt - Modification time stamp
Definition:
() => object[]Usage:
const sheets = await smartsheetConnector.listSheets()Update the data in a sheet. The update object uses the format defined here. You can use the Simple Sheet object to create an updater object that will construct the rows array.
Definition:
(
sheetId: number | string,
rows: object[],
) => voidUsage:
await smartsheetConnector.update(
4583173393803140,
[
{
id: '0000000000000000',
cells: [
{
columnId: '0000000000000000',
value: 'My Value',
},
],
},
],
)Get the underlying SDK object.
Definition:
() => objectUsage:
const client = await smartsheetConnector.sdk()