Smartsheet JavaScript SDK
The Smartsheet JavaScript SDK, currently at version 4.7.2, provides an official client library for interacting with the Smartsheet API from Node.js applications. It ships with comprehensive TypeScript types, facilitating development in type-safe environments. The SDK maintains an active and consistent release cadence, frequently introducing minor versions with new features, API endpoint support, and critical bug fixes, as evidenced by recent updates adding new sharing, workspace, and folder endpoints, alongside improvements to retry mechanisms and pagination. It differentiates itself as the directly supported client, offering extensive coverage of the Smartsheet API's functionalities. Developers can initialize the client using an access token obtained from the Smartsheet UI and leverage promise-based methods for operations such as listing and loading sheets, managing users, and handling attachments. The SDK requires actively supported Node.js versions 14.x or later for optimal compatibility and robust operation.
Common errors
-
Error: SMARTSHEET_ACCESS_TOKEN environment variable is not set.
cause The Smartsheet client was initialized without an access token, or the token was invalid.fixProvide a valid Smartsheet API access token, ideally through an environment variable like `SMARTSHEET_ACCESS_TOKEN`, or directly in the `createClient` call (not recommended for production). -
TypeError: smartsheet.sheets.getWorkspace is not a function
cause Attempting to call a deprecated method (`getWorkspace` or `getFolder`) that has been removed or replaced in newer SDK versions.fixUpdate your code to use the new methods introduced in v4.4.0: `getWorkspaceMetadata()` and `getWorkspaceChildren()` for workspaces, and `getFolderMetadata()` and `getFolderChildren()` for folders. -
ERR_MODULE_NOT_FOUND: Cannot find module 'smartsheet'
cause Incorrect module import path or attempting a CommonJS `require` in an ESM module without proper configuration (or vice versa).fixEnsure `npm install smartsheet` has been run. For ESM, use `import { createClient } from 'smartsheet';`. For CommonJS, use `const { createClient } = require('smartsheet');`. Check your `package.json` `type` field if encountering issues in mixed environments.
Warnings
- breaking Older sharing endpoints were deprecated in favor of new ones. Existing code using the deprecated endpoints may eventually break or behave unexpectedly.
- breaking The `getWorkspace()` and `getFolder()` methods were deprecated. Developers must now use `getWorkspaceMetadata()` paired with `getWorkspaceChildren()` (and similarly for folders) to retrieve equivalent data.
- gotcha Versions prior to 4.2.3 had a bug where the request body was not correctly resent during retries for POST/PUT methods, potentially leading to data loss or incorrect state on intermittent network failures.
- gotcha The Smartsheet SDK requires Node.js version 14.x or later. Using older, unsupported Node.js versions may lead to unexpected errors, security vulnerabilities, or installation failures.
Install
-
npm install smartsheet -
yarn add smartsheet -
pnpm add smartsheet
Imports
- createClient
import smartsheet from 'smartsheet'; const client = smartsheet.createClient(...);
import { createClient } from 'smartsheet'; - createClient (CommonJS)
const smartsheet = require('smartsheet'); const client = smartsheet.createClient(...);const { createClient } = require('smartsheet'); - SmartsheetClient (Type)
import { SmartsheetClient } from 'smartsheet';import type { SmartsheetClient } from 'smartsheet';
Quickstart
import { createClient } from 'smartsheet';
const accessToken = process.env.SMARTSHEET_ACCESS_TOKEN ?? ''; // Load from environment variable for security
if (!accessToken) {
console.error('Error: SMARTSHEET_ACCESS_TOKEN environment variable is not set.');
process.exit(1);
}
// Initialize the client
const smartsheet = createClient({
accessToken: accessToken,
logLevel: 'info' // Can be 'info', 'warn', 'error', 'debug'
});
// Set queryParameters for `include` and pagination
const options = {
queryParameters: {
include: 'attachments',
includeAll: true
}
};
async function listAndLoadSheets() {
try {
// List all sheets
const result = await smartsheet.sheets.listSheets(options);
if (result.data && result.data.length > 0) {
const sheetId = result.data[0].id; // Choose the first sheet
// Load one sheet
const sheetInfo = await smartsheet.sheets.getSheet({ sheetId: sheetId });
console.log('Successfully loaded sheet:', sheetInfo.name, 'with ID:', sheetInfo.id);
// console.log(JSON.stringify(sheetInfo, null, 2)); // Uncomment to see full sheet data
} else {
console.log('No sheets found in your Smartsheet account.');
}
} catch (error) {
console.error('An error occurred:', error);
}
}
listAndLoadSheets();