Directory / File Tree List

Hello,

I'd like to get a file tree list of work spaces with folder names and the sheet names under the folders.

I believe this can be accomplished using the API and Python but I am completely inexperienced with any of this. Can anyone help me?

Answers

  • Lee Joramo
    Lee Joramo ✭✭✭✭✭✭
    edited 10/25/24

    I have done this in both Python and Javascript

    import smartsheet
    smartSheetClient = smartsheet.Smartsheet(YOUR_API_TOKEN)
    workspaces = smartSheetClient.Workspaces.get_workspace( workspace_id=YOUR_WORKSPACE_ID, load_all=True )
    workspaces_dict = workspaces.to_dict()
    print(json.dumps(workspaces_dict, indent=4))

    This provides you a Python Dict of the Workspace's content. This includes the Sheets, Reports, Dashboards nested in Folders. This Dict may provide what you need, or you may need to recurse it to build a tree that meets your needs.

    Side Note: I often want to get an individual Sheet by its ID and know what it's Workspace/Folder path is. Unfortunately, none of the API's for individual sheets provide this information. Sheets only know what Workspace they are in, nothing about the folder structure. So you have to take the approach used above to recurse the entire Workspace to find the path of the individual sheet.