I would like to get all the folder that are in a specific folder in smartsheet
I wanted to use os.listdir but I am not sure on how to use it on smartsheet any idea ?
any idea on how to implement that without os.listdir ?
I would like to get all the folder that are in a specific folder in smartsheet
I wanted to use os.listdir but I am not sure on how to use it on smartsheet any idea ?
any idea on how to implement that without os.listdir ?
To get a list of objects within a specified Smartsheet folder, you'll need to use the Smartsheet API -- specifically the Get Folder operation.
To issue a GET Folder request, you'll need to know the ID of the folder that you want to get. The easiest way to determine a folder's ID is by (manually) logging into Smartsheet, navigating to the location where the folder resides, then right click on the folder name and choose Properties. The following screenshot shows where you'll find the folder's ID in the Properties dialog window.
To retrieve the contents of this folder, the GET Folder API request would be:
GET https://api.smartsheet.com/2.0/folders/1589169626605444
The response will specify the folder properties, including collections of objects that the folder contains such as sheets
, folders
, reports
, sights
, etc. Note that the response will only contain the items that exist at the top-level of the specified folder -- i.e., it won't contain any items that exist within subfolders of that folder.
For example, let's say the folder I want to get the contents of contains the following items (2 folders, 2 dashboards (sights), 2 reports, and 2 sheets).
The GET Folder response for the parent folder shown in the screenshot above is:
{
"id": 1589169626605444,
"name": "Parent Folder",
"permalink": "https://app.smartsheet.com/folders/XvFv8qxCG5R3VqmCX5CG5PxC6PRp9C336Hj2mwv1",
"sheets": [
{
"id": 8573752976926596,
"name": "Sheet 1",
"accessLevel": "OWNER",
"permalink": "https://app.smartsheet.com/sheets/6CcCwJhJPRCGGR536F7wQ8QR8G5Rwwp2v69wP831",
"createdAt": "2022-09-07T21:09:26Z",
"modifiedAt": "2022-09-07T21:09:26Z"
},
{
"id": 3942867698771844,
"name": "Sheet 2",
"accessLevel": "OWNER",
"permalink": "https://app.smartsheet.com/sheets/r8j3PRx33gfH2rvmw77QWQ4GH64Vx73cjH794xw1",
"createdAt": "2022-09-07T21:09:31Z",
"modifiedAt": "2022-09-07T21:09:31Z"
}
],
"folders": [
{
"id": 304940045363076,
"name": "Subfolder 1",
"permalink": "https://app.smartsheet.com/folders/HQhfCrwwrcj858qxCjf8j3gV43R97gp2CQjqv6q1"
},
{
"id": 797521254606724,
"name": "Subfolder 2",
"permalink": "https://app.smartsheet.com/folders/M8fpH7wcJmHrWr7RQV7pqr5xWfcqCcjjRvjfMX81"
}
],
"reports": [
{
"id": 3321248492087172,
"name": "Report 1",
"accessLevel": "OWNER",
"permalink": "https://app.smartsheet.com/reports/7v96G7r9Q7GJXq8R7Xg9pFCRM83MvmhHVW7RqXV1",
"createdAt": "2022-09-07T21:09:12Z",
"modifiedAt": "2022-09-07T21:09:12Z"
},
{
"id": 7235389627885444,
"name": "Report 2",
"accessLevel": "OWNER",
"permalink": "https://app.smartsheet.com/reports/hGP5pFVhW65QC3whQW9p8HQ75HmWRXFrHm9F4MW1",
"createdAt": "2022-09-07T21:09:20Z",
"modifiedAt": "2022-09-07T21:09:20Z"
}
],
"sights": [
{
"id": 8871794707851140,
"name": "Dashboard 1",
"accessLevel": "OWNER",
"permalink": "https://app.smartsheet.com/dashboards/fccJ8V54x3jhPr2gxxC96C2rVjV72fH9wCJWvp81",
"createdAt": "2022-09-07T21:09:48Z",
"modifiedAt": "2022-09-07T21:09:48Z"
},
{
"id": 2327501499328388,
"name": "Dashboard 2",
"accessLevel": "OWNER",
"permalink": "https://app.smartsheet.com/dashboards/X8VmpVvWPhHHfPPFWhGMcJpPXJvPPMg6FWwpwhX1",
"createdAt": "2022-09-07T21:09:58Z",
"modifiedAt": "2022-09-07T21:09:58Z"
}
]
}
(This is just an example. See the API docs I've listed to above for full details about the GET Folder response.)
If you're using the Smartsheet Python SDK to issue the GET Folder request, then the following code may be helpful. It issues a GET Folder request and then iterates through objects in the response to print info about the contents of the folder.
folderId = 1589169626605444
# get the parent folder
parent_folder = smartsheet_client.Folders.get_folder(folderId)
# print sheet info
print('----')
print('Number of sheets: ' + str(len(parent_folder.sheets)))
for sheet in parent_folder.sheets:
print('Sheet: ' + sheet.name)
# print folder info
print('----')
print('Number of folders: ' + str(len(parent_folder.folders)))
for folder in parent_folder.folders:
print('Folder: ' + folder.name)
# print report info
print('----')
print('Number of reports: ' + str(len(parent_folder.reports)))
for report in parent_folder.reports:
print('Report: ' + report.name)
# print dashboard info
print('----')
print('Number of dashboards: ' + str(len(parent_folder.sights)))
for sight in parent_folder.sights:
print('Dashboard: ' + sight.name)
print('----')
For the parent folder described above, this code prints the following output to the console:
----
Number of sheets: 2
Sheet: Sheet 1
Sheet: Sheet 2
----
Number of folders: 2
Folder: Subfolder 1
Folder: Subfolder 2
----
Number of reports: 2
Report: Report 1
Report: Report 2
----
Number of dashboards: 2
Dashboard: Dashboard 1
Dashboard: Dashboard 2