This is a Java SDK to simplify connecting to Smartsheet API in Java applications.
The SDK supports Java version 1.6 or later.
There are three different ways to install the SDK. Select the one that fits your environment best:
- Install By Using Maven
- Install By Downloading the Jar File
- Install By Compiling Directly From Source
Add the SDK as a dependency in your project.
<dependency>
<groupId>com.smartsheet</groupId>
<artifactId>smartsheet-sdk-java</artifactId>
<version>2.2.2</version>
</dependency>
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.
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-platform/smartsheet-java-sdk.git
cd smartsheet-java-sdk
mvn package
The full Smartsheet API documentation is here: http://smartsheet-platform.github.io/api-docs/?java
The generated SDK javadoc is here: http://smartsheet-platform.github.io/smartsheet-java-sdk (Download as a jar file here.)
To call the API, you will need an access token, which looks something like this example: ll352u9jujauoqz4gstvsae05. You can find the access token in the 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 = "ll352u9jujauoqz4gstvsae05";
Smartsheet smartsheet = new SmartsheetBuilder().setAccessToken(accessToken).build();
// List all sheets
PagedResult<Sheet> sheets = smartsheet.sheetResources().listSheets(
null, // EnumSet<SourceInclusion> includes
null, // PaginationParameters
null // Date modifiedSince
);
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, // long sheetId
null, // EnumSet<SheetInclusion> includes
null, // EnumSet<ObjectExclusion> excludes
null, // Set<Long> rowIds
null, // Set<Integer> rowNumbers
null, // Set<Long> columnIds
null, // Integer pageSize
null // Integer page
);
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.
If you would like to contribute a change to the SDK, please fork a branch and then submit a pull request. More info here.
Unit tests:
mvn test
Integration tests:
- Set up an api access token in
src/integration-test/resources/config.properties
mvn integration-test
Mock API tests:
- Clone the Smartsheet sdk tests repo and follow the instructions from the readme to start the mock server.
mvn test -Dtest=com.smartsheet.api.sdk_test.*
If you have any questions or issues with this SDK please post on StackOverflow using the tag "smartsheet-api" or contact us directly at api@smartsheet.com.
Each specific release is available for download via Github or the Maven repository.
See https://github.com/smartsheet-platform/smartsheet-java-sdk/releases