2

I am trying to use the Smartsheet API to download a sheet as an excel file. I am really struggling to put together the correct code to do this.

Can you provide a basic code example that will download an excel file using the Smartsheet API?

Kim Brandl
  • 13,125
  • 2
  • 16
  • 21
user3191778
  • 23
  • 1
  • 3
  • Not sure why this was closed. I certainly would have found a continuing conversation about this helpful. It does not lack sufficient information to diagnose the problem at all! – Danrex Dec 04 '14 at 21:38

1 Answers1

4

The documentation for creating an excel file from a sheet is here. It gives an example that uses curl. After curl is installed the following command can be used with the bold fields replaced with the appropriate values:

curl https://api.smartsheet.com/1.1/sheet/SHEET_ID -H "Authorization: Bearer ACCESS_TOKEN" -H "Accept: application/vnd.ms-excel" -o OUTPUT.XLS

SHEET_ID: this is the id of the sheet. It can be retrieved inside the smartsheet interface (screenshot below) by right clicking on a sheet tab and selecting properties. It can also be retrieved via the API by hitting the sheets endpoint (https://api.smartsheet.com/1.1/sheets). More info on the endpoint is here.

enter image description here

ACCESS_TOKEN: Is a token that can be retrieved via the smartsheet interface by clicking on "Account" selecting "Personal Settings" and then clicking "API Access". Then click the "Generate new access token" button to create a new token.

enter image description here

OUTPUT.XLS: is the name of the excel file that will be created in the current directory.


I also want to point out that the same steps can be accomplished using Smartsheet's Java SDK. After installing the SDK the following code can be used to download a sheet as an Excel file.

public static void main(String[] args) throws SmartsheetException, IOException {
    // Setup the File object
    File file = new File("OUTPUT.XLS");

    // Create the file if it does not exist
    if(!file.exists()){
        file.createNewFile();
    }

    // Create the output stream from the File object
    FileOutputStream outputStream = new FileOutputStream(file, false);

    // Setup a Smartsheet object with the necessary access token
    Smartsheet smartsheet = new SmartsheetBuilder().setAccessToken("ACCESS_TOKEN").build();

    // Request the sheet as an excel file from smartsheet
    long sheetId = 8263950702798724L;// SHEET_ID
    smartsheet.sheets().getSheetAsExcel(sheetId, outputStream);

    // Flush and Close the output stream
    outputStream.flush();
    outputStream.close();
}

Again, replace SHEET_ID, ACCESS_TOKEN and OUTPUT.XLS with the appropriate values.

Brett
  • 2,502
  • 19
  • 30
  • 1
    Also see the [Smartsheet Github repo](https://github.com/smartsheet-platform) for examples on how to connect to [Smartsheet API](http://smartsheet.com/developers) in other languages. There aren't specific instructions how to export data in Excel, but you can extrapolate from @Brett's answer and the API documentation. – avioing Feb 21 '14 at 23:20
  • The thing is they don't contain information on that which is why this topic was valid and should not have been closed. – Danrex Dec 04 '14 at 21:39