I’m trying to get the following in a Box folder with ID=1234567:
- All subfolders and files (including files in the subfolders) of a particular folder
- The name, URL and full folder path of each subfolder and file (ex. My folderFamilyPicture.jpeg where “My folder” is the one with ID=1234567)
I came upon this blog that provided a great starting point. Upon modifying the script, I was able to extract the item names and subfolders within “My folder”, but I’m not able to extract their URL, full folder path, and files within the different subfolders.
Here is part of the code where I’ve been having a headache:
function getFilesAndFolders() {
var response = UrlFetchApp.fetch('https://api.box.com/2.0/folders/1234567/items?fields=name,type', {
headers: {
Authorization: 'Bearer ' + getBoxService_().getAccessToken(),
},
});
var result = JSON.parse(response.getContentText());
var items = result.entries;
var filesAndFolders = [];
for (var i = 0; i < items.length; i++) {
filesAndFolders.push({ name: items[i].name, type:items[i].type, url:items[i].shared_link.url});
}
Logger.log(filesAndFolders);
}
In this resource, I saw this shared_link
object that has the url
field, but the script throws an error when I do items[i].shared_link.url
. Also, I have no idea where to start with the full folder path. I saw this path_collection
object but it doesn’t seem to have the field I need.
Any help is appreciated. Thanks!