Smartsheet Releases Full JavaScript SDK

Published on 04 December 2017

Node developers, rejoice! Smartsheet’s full JavaScript SDK is officially released. The beta SDK has been available for a while now, but it didn't cover all the endpoints in the Smartsheet API. Now it does!

New features of the Smartsheet JavaScript SDK include:

Working with the JavaScript SDK makes it easier and faster to develop apps that use the Smartsheet API. The declarative methods make the code easier to read and ensure best practices when interacting with the Smartsheet API.

Please be aware: there are node-specific examples in the Node.js tab of the Smartsheet API docs.

Using the Smartsheet JavaScript SDK

  1. Install the Smartsheet npm module: type ‘npm install smartsheet’ in your console.

  2. Require the Smartsheet module in your project:

    const smartsheet = require('smartsheet');
  3. Create a Smartsheet client:

    const smartsheetClient = smartsheet.createClient({
       accessToken: 'your_access_token',
    });

In order to access the Smartsheet SDK you need to provide your access token.

One of the newly supported features in the SDK is the ability to move sheets. In the past, you would work with the API directly, probably using a library like request. Your code might look something like this:

const request = require("request");

const options = { method: 'POST',
   url: 'https://api.smartsheet.com/2.0/
sheets/7778823866498948/move',
   headers: 
{ authorization: 'Bearer ll352u9jujauoqz4gstvsae05' },
   body:
       { destinationType: 'workspace',
         destinationId: 8548879372286276 },
 json: true };


request(options)
    .then(function (movedSheet) {
        console.log(movedSheet);
     })
    .catch(function (error) {
        console.log(error);
    });

Now, with the latest version of the SDK, the same request would look like this:

var body = {
   destinationType: "workspace",
     destinationId: 8548879372286276
};

var options = {
     sheetId: 7778823866498948,
     body: body
};

smartsheetClient.sheets.moveSheet(options)
   .then(function (movedSheet) {
       console.log(movedSheet);
   })
   .catch(function (error) {
       console.log(error);
   });

Authentication With the SDK

When a developer wants their third-party app to work with Smartsheet they must create an OAuth flow to authenticate users.

A very exciting addition to the SDK is the token management methods. These new methods are a major improvement in building an OAuth flow using Node.js. The token management methods can be accessed by initializing a Smartsheet client with an empty string instead of an access token.

const smartsheetClient = smartsheet.createClient
({ accessToken: '' });

The following methods are now available:

An upcoming article called ‘Creating a Smartsheet OAuth Flow in Node.js’ is a step-by-step guide to building an OAuth Flow in Smartsheet using the JavaScript SDK.

If you have any questions about working with the Smartsheet JavaScript SDK, then please send an email to DeveloperRelations@Smartsheet.com or post a question in StackOverflow using the smartsheet-api tag.

comment

Comments