smartsheet-apismartsheet-java-sdk-v2

How to create a new sheet from an existing one in smartsheet API 2.0


I am trying to create a new sheet from an existing sheet using the Java API 2.0 for Smartsheet. The code I am using is as follows.

try{
Sheet sheet = smartsheet.sheetResources().getSheet(Id, null, null, null, null, null, null, null);
Sheet newSheet = smartsheet.sheetResources().createSheetInFolderFromTemplate(1441945445787524L, sheet, EnumSet.allOf(SheetTemplateInclusion.class));

When I run this I get an error saying "effectiveAttachmentOptions" was of unexpected type I had it working in API 1.1 but cannot figure it out in 2.0.


Solution

  • Creating a new sheet from a template requires a sheet object limited to the following attributes:

    When you get a sheet using the 'getSheet()' method, the sheet contains 'effectiveAttachmentOptions' and other attributes which should not be part of the request. Instead, please use the sample code provided below:

    Sheet sheet = new Sheet.CreateFromTemplateOrSheetBuilder().setFromId(sheetId).setName("New test sheet from template").build();
    
    Sheet newSheetFromTemplate = smartsheet.sheetResources().createSheetInFolderFromTemplate(1441945445787524L, sheet, null);
    

    For more information: http://smartsheet-platform.github.io/api-docs/#create-sheet-in-folder-from-template