How to find folder id for existing smartsheet

11/23/20
Answered - Pending Review

All,

I am trying to create and maintain a bunch of smartsheets using the API. I would like to find an existing smartsheet to use as a template and create new smartsheets based on the source sheet and in the same folder as the source sheet.

I have code to locate the source smartsheet as shown below. I can find the sheet no problem, however, the folderID of the found sheet is null. How can I locate the folder the sheet that I found is located in?

Here is the code to find the existing smartsheet. Is there a way to find the folder of this sheet?

        // Get all the sheets this user can see...
        PaginatedResult<Sheet> sheets = smartsheetClient.SheetResources.ListSheets( 
          new List<SheetInclusion> { SheetInclusion.SHEET_VERSION }, 
          new PaginationParameters( true, null,null ), null );
        log.Debug( "Found " + sheets.TotalCount + " sheets" );

        // Loop through all the sheets and find the matching passed in sheet name
        int sheetIndex = 0;
        while( sheetIndex < sheets.TotalCount )
        {
          long aSheetID = (long)sheets.Data[sheetIndex].Id;
          aSheet = smartsheetClient.SheetResources.GetSheet( aSheetID, null, null, null, null, null, null, null );
          log.Debug( "Processing Sheet: " + aSheet.Name + " - " + aSheet.GetType() );
          if( aSheet.Name.Equals( aSheetNameToLocate, StringComparison.OrdinalIgnoreCase ) )
          {
            log.Debug( "Found Sheet: " + aSheet.Name + " - " + aSheet.GetType() );
            foundSheet = true;
            break;
          }
          sheetIndex++;
        }

Answers

  • Hi @Steve Rieger

    There isn't a direct way to find the folder from the information returned about a specific sheet: the only way to get the folder ID is to start by finding the workspace ID (which is present when the sheet object is returned).

    Then you can call the API to get the workspace, which gives a breakdown of folders and the sheets in each folder (see here). You'll need to cross-match against this to find your matching sheet ID by looping through.

    Note: if you use the loadAll flag when getting the workspace, then it will include all folders and subfolders as well.

    Cheers,

    Genevieve

Sign In or Register to comment.