Is there a way to fetch the complete folder path of a file given the file Id using the Box API?
From the API documentation it is clear that we can use the Parent Folder ID to recursively fetch folder names until the root is reached, however this would result in a lot of REST API calls depending on the number of parent folders.
The path_collection
property of the file
object contains "the path of folders to this item, starting at the root." This information can be fetched in a single API request using only the file ID. See the documentation for a detailed example, a portion of which is shown below. The total_count
field indicates the depth of the tree for that file, and the entries
field contains information about each folder in the tree. It's my understanding that the entries
are returned in order.
"path_collection": {
"total_count": 2,
"entries": [
{
"type": "folder",
"id": "0",
"sequence_id": null,
"etag": null,
"name": "All Files"
},
{
"type": "folder",
"id": "11446498",
"sequence_id": "1",
"etag": "1",
"name": "Pictures"
}
]
},
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With