Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

smartsheet-platform/smartsheet-csharp-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Smartsheet SDK for C# Build Status Coverage Status NuGet

This is a C# SDK to simplify connecting to the Smartsheet API from .NET applications.

Notice

This repo has moved to the Smartsheet Organization on GitHub and can be accessed here.

NOTE ON 2.93.0 RELEASE

While investigating issue #113, the API/SDK team discovered that Newtonsoft Json.NET, by default, deserializes JSON strings that "look like" dates into C# DateTime objects. You can read the discussion here. Smartsheet believes this to be undesirable behavior (since JSON doesn't have a date construct, all JSON strings should be handled as C# strings), therefore, this release changes the global behavior to disable this feature of Json.NET. If you have implementations that rely on the previous behavior, there is an opt-out feature that you can use. An example of the opt-out code is here:

SmartsheetClient smartsheet = new SmartsheetBuilder()
    .SetAccessToken("JKlMNOpQ12RStUVwxYZAbcde3F5g6hijklM789")       // TODO: Set your API access in environment variable SMARTSHEET_ACCESS_TOKEN or else here
    .SetHttpClient(new RetryHttpClient())
    .SetDateTimeFixOptOut(true)
    .Build();

System Requirements

The SDK supports C# version 4.0 or later and targets .NET Framework version 4.5.2 or later or .NET Standard 2.0 or later. In addition, we support any .NET language compatible with those platform versions.

Installation

The SDK can be installed by using NuGet or by compiling from source. These two alternatives are outlined below.

Install with NuGet

If unfamiliar with NuGet, please take a look at the NuGet documentation.

To install the SDK in Visual Studio, right click the References for the project and select Manage NuGet Packages.

Select the Browse or Online tab (depending upon the version of Visual Studio) then type smartsheet in the search box. Select smartsheet-csharp-sdk in the search results and click the Install button.

After clicking Install, you will be asked to accept the License (Apache). Then it will install the Smartsheet SDK and the dependencies (RestSharp, Newtonsoft.Json, and NLog) by adding these libraries to the References section of the project.

You can also use the following command in the Package Manager Console to install the SDK:

Install-Package smartsheet-csharp-sdk

Compile From Source

You can download and compile the source code for the SDK from Github. Use git to fetch it and use Visual Studio 2017 or later to build it.

git clone https://github.com/smartsheet-platform/smartsheet-csharp-sdk.git

In Visual Studio 2017 you can open the entire solution with the file smartsheet-csharp-sdk-v2.sln, or open the specific project smartsheet-csharp-sdk-v2.csproj.

Example Usage

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
using Smartsheet.Api;
using Smartsheet.Api.Models;

static void Sample()
{
    // Initialize client
    SmartsheetClient smartsheet = new SmartsheetBuilder()
        // TODO: Set your API access in environment variable SMARTSHEET_ACCESS_TOKEN or else here
        // .SetAccessToken("JKlMNOpQ12RStUVwxYZAbcde3F5g6hijklM789")
        .Build();

    // List all sheets
    PaginatedResult<Sheet> sheets = smartsheet.SheetResources.ListSheets(
        null,               // IEnumerable<SheetInclusion> includes
        null,               // PaginationParameters
        null                // Nullable<DateTime> modifiedSince = null
    );
    Console.WriteLine("Found " + sheets.TotalCount + " sheets");

    long sheetId = (long) sheets.Data[0].Id;                // Default to first sheet

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

    Console.WriteLine("Loading sheet id: " + sheetId);

    // Load the entire sheet
    var sheet = smartsheet.SheetResources.GetSheet(
        5670346721388420,           // long sheetId
        null,                       // IEnumerable<SheetLevelInclusion> includes
        null,                       // IEnumerable<SheetLevelExclusion> excludes
        null,                       // IEnumerable<long> rowIds
        null,                       // IEnumerable<int> rowNumbers
        null,                       // IEnumerable<long> columnIds
        null,                       // Nullable<long> pageSize
        null                        // Nullable<long> page
    );
    Console.WriteLine("Loaded " + sheet.Rows.Count + " rows from sheet: " + sheet.Name);
}

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

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 class documentation is here: http://smartsheet-platform.github.io/smartsheet-csharp-sdk/.

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 the v2.68.0 release, Smartsheet SDKs will use a new versioning strategy. Since all users are on the Smartsheet API 2.0, the SDK version numbers will start with 2. The 2nd number will be an internal reference number. The 3rd number is for incremental changes.

For example, v2.68.0 means that you are using our 2.0 version of the API, the API is synced internally to a tag of 68, and then if there are numbers after the last decimal, that will indicate a minor change.

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 devrel@smartsheet.com.

Release Notes

All releases and release notes are available on Github or the NuGet repository.