Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the full file path of a Box File given file ID using the API

Tags:

box-api

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.

like image 400
Snehal Avatar asked Jan 11 '23 13:01

Snehal


1 Answers

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"
        }
    ]
},
like image 173
John Hoerr Avatar answered May 14 '23 18:05

John Hoerr