Skip to content

smartsheet/smartsheet-java-sdk

Repository files navigation

Smartsheet SDK for Java

Java CI Coverage Status Maven Central

This is a Java SDK to simplify connecting to Smartsheet API in Java applications.

System Requirements

The SDK supports Java 11 or later.

Installation

There are three different ways to install the SDK. Select the one that fits your environment best:

Install By Using Maven

Add the SDK as a dependency in your project.

<dependency>
  <groupId>com.smartsheet</groupId>
  <artifactId>smartsheet-sdk-java</artifactId>
  <version>[version]</version>
</dependency>

The current artifact version reference can be found here

Install By Downloading the Jar File

SDK packaged as a jar. This jar requires that all of the following dependencies are manually added to the path:

    Apache HttpComponents 4.5
    Simple Logging Facade for Java 1.7.12
    Jackson FasterXML 2.6.2
    Jackson Core 2.6.2

You can also navigate to the Sonatype Library Page instead of directly downloading the Jar file.

Install By Compiling Directly From Source

The source code for the jar can be downloaded from Github and then compiled. This can be accomplished using git and maven with the following 3 steps.

git clone https://github.com/smartsheet/smartsheet-java-sdk.git
cd smartsheet-java-sdk
./gradlew clean build

Example Usage

To call the API, you will need an access token, which looks something like this example: ll352u9jujauoqz4gstvsae05. You can generate the access token in the Smartsheet UI at Account > Personal Settings > API Access.

The following is a brief sample that shows you how to:

  • Initialize the client
  • List all sheets
  • Load one sheet

To initialize the client, you'll need to include the appropriate import directives in your code. For example, the code examples in this section require the following import directives:

import com.smartsheet.api.*;
import com.smartsheet.api.models.*;
import com.smartsheet.api.oauth.*;
import java.io.FileInputStream;
import java.util.*;
// Initialize client
String accessToken = "JKlMNOpQ12RStUVwxYZAbcde3F5g6hijklM789";

Smartsheet smartsheet = SmartsheetFactory.createDefaultClient(accessToken);

// List all sheets
PagedResult<Sheet> sheets = smartsheet.sheetResources().listSheets();

System.out.println("Found " + sheets.getTotalCount() + " sheets");

long sheetId = sheets.getData().get(0).getId();      // Default to first sheet

// sheetId = 567034672138842L;                       // TODO: Uncomment if you wish to read a specific sheet

System.out.println("Loading sheet id: " + sheetId);

// Load the entire sheet
Sheet sheet = smartsheet.sheetResources().getSheet(sheetId);
System.out.println("Loaded " + sheet.getTotalRowCount() + " rows from sheet: " + sheet.getName());

A simple, but complete sample application is here: https://github.com/smartsheet-samples/java-read-write-sheet

More Java examples available here.

Advanced Topics

For details about logging, testing, how to use a passthrough option, and how to override HTTP client behavior, see Advanced Topics.

Documentation

The full Smartsheet API documentation is here: https://smartsheet.redoc.ly

The generated SDK javadoc is here: https://smartsheet.github.io/smartsheet-java-sdk/apidocs/ (Download as a jar file here.)

Contributing

If you would like to contribute a change to the SDK, please fork a branch and then submit a pull request. More info here.

Version Numbers

Starting from v3.0.0 release, the Smartsheet Java SDK has been updated to Java 11.

Support

If you have any questions or issues with this SDK please post on StackOverflow using the tag "smartsheet-api" or contact us directly at [email protected].

Release Notes

Each specific release is available for download via Github or the Maven repository.

See https://github.com/smartsheet/smartsheet-java-sdk/releases

Developer Agreement

Review the Developer Program Agreement.

Acknowledgements

We would like to thank the following people for their contributions to this project: