0
votes

I am trying to find a solution to search/list all locked files in BOX (BOX.com). As this seems not to be possible through the user-interface, I investigated the Rest API.

I cannot find a way to search for all locked files using the API. I cannot iterate through the API. I cannot have a wildcard search using the "fields=lock" as parameter.

Currently I can query if a single file is locked by:

https://api.box.com/2.0/files/26802142333?fields=lock

which returns

{
    "type": "file",
    "id": "26802142333",
    "etag": "462",
    "lock": {
        "type": "lock",
        "id": "22148533",
        "created_by": {
            "type": "user",
            "id": "201274112",
            "name": "Robert Wunsch",
            "login": "[email protected]"
        },
        "created_at": "2015-05-11T11:36:08-07:00",
        "expires_at": null,
        "is_download_prevented": false
    }
}

And I can create a search using the "fields=lock" parameter, with a query to search e.g. everything containing "xls":

https://api.box.com/2.0/search?query=xls&fields=lock

which returns

...,
{
            "type": "file",
            "id": "29299819893",
            "etag": "0",
            "lock": null
        },
        {
            "type": "file",
            "id": "26004664251",
            "etag": "0",
            "lock": null
        },
        {
            "type": "file",
            "id": "26004640461",
            "etag": "0",
            "lock": null
        },
        {
            "type": "file",
            "id": "29618844701",
            "etag": "3",
            "lock": {
                "type": "lock",
                "id": "22002195",
                "created_by": {
                    "type": "user",
                    "id": "202820453",
                    "name": "Robert Wunsch",
                    "login": "[email protected]"
                },
                "created_at": "2015-05-06T05:33:28-07:00",
                "expires_at": null,
                "is_download_prevented": false
            }
        },
        {
            "type": "file",
            "id": "26004659155",
            "etag": "0",
            "lock": null
        },
        {
            "type": "file",
            "id": "29063166840",
            "etag": "0",
            "lock": null
        },
...

How do I can I search for the locked files?

Thanks for the Help!

1

1 Answers

0
votes

I don't believe the API has a way of efficiently retrieving all locked files.

The only reliable solution would be to walk the entire folder tree and check each file to see if it's locked. However, this will be slow if you have a lot of files or a very deep hierarchy, as you'll need to make at least one API request per folder.