How to find folder id for existing smartsheet
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
-
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
Need more help? 👀 | Help and Learning Center
こんにちは (Konnichiwa), Hallo, Hola, Bonjour, Olá, Ciao! 👋 | Global Discussions
-
Hello
This may work when the sheet is in a workspace. But what about when the sheet is not in a workspace, in a subfolder of your "sheets" folder?
sheet.workspace returns None in this scenario
-
Can you provide a sample code of doing so? The link you posted is no longer valid and it redirect to general doc
Categories
- All Categories
- 14 Welcome to the Community
- Customer Resources
- 64.9K Get Help
- 439 Global Discussions
- 138 Industry Talk
- 471 Announcements
- 4.9K Ideas & Feature Requests
- 129 Brandfolder
- 148 Just for fun
- 67 Community Job Board
- 486 Show & Tell
- 33 Member Spotlight
- 2 SmartStories
- 300 Events
- 36 Webinars
- 7.3K Forum Archives