Tuesday, January 22nd, 2013

Search and Thumbnails

By

We recently released two huge features in API V2 that you’ll definitely want to use in your Box app.

Thumbnails

For image files stored on Box, you can now generate thumbnails. Thumbnails are available in various sizes from 32x32px to 256x256px. They’re great for tablet applications and other applications that emphasize images heavily. To retrieve a thumbnail, just make a call to the file’s thumbnail subresource. For example,

curl https://api.box.com/2.0/files/FILE_ID/thumbnail.png?min_height=128&min_width=128 \
-H "Authorization: Bearer ACCESS_TOKEN"

will return a 128×128 thumbnail, like this:

However, if you request a thumbnail for a file that Box currently is incapable of creating a thumbnail for, we’ll send back a placeholder graphic specific to that filetype in the same dimensions you requested. For example, for a CSV file you’d receive:

There are a few cases with thumbnails that you’ll have to prepare your app for, so be sure to read the documentation!

Search

Search in the Box web application includes file/folder names, descriptions, and the text content of files. We’ve created an easy-to-use endpoint for the API that provides this same functionality. All you need to do is make a GET request to the search endpoint with your query, and a paginated list of API objects that match your criteria will be returned. For example:

curl https://api.box.com/2.0/search?query=football&limit=1&offset=0 \
-H "Authorization: Bearer ACCESS_TOKEN"

will return:

{
    "total_count": 4,
    "entries": [
        {
            "type": "file",
            "id": "1874102965",
            "sequence_id": "0",
            "etag": "0",
            "sha1": "63a112a4567fb556f5269735102a2f24f2cbea56",
            "name": "football.jpg",
            "description": "",
            "size": 260271,
            "path_collection": {
                "total_count": 1,
                "entries": [
                    {
                        "type": "folder",
                        "id": "0",
                        "sequence_id": null,
                        "etag": null,
                        "name": "All Files"
                    }
                ]
            },
            "created_at": "2012-03-22T18:25:07-07:00",
            "modified_at": "2012-10-25T14:40:05-07:00",
            "created_by": {
                "type": "user",
                "id": "175065494",
                "name": "Andrew Luck",
                "login": "aluck@colts.com"
            },
            "modified_by": {
                "type": "user",
                "id": "175065494",
                "name": "Andrew Luck",
                "login": "aluck@colts.com"
            },
            "owned_by": {
                "type": "user",
                "id": "175065494",
                "name": "Andrew Luck",
                "login": "aluck@colts.com"
            },
            "shared_link": null,
            "parent": {
                "type": "folder",
                "id": "0",
                "sequence_id": null,
                "etag": null,
                "name": "All Files"
            },
            "item_status": "active"
        }
    ],
    "offset": 0,
    "limit": 1
}

Please let us know if you have any feedback about these specific endpoints or any other parts of the API.

By

See all of Sean's articles.