Search for content

get
https://api.box.com/2.0
/search/

Searches for files, folders, web links, and shared files across the users content or across the entire enterprise.

Request

Bearer [ACCESS_TOKEN]
application/json

Query Parameters

stringin queryoptional
file

Limits the search results to any items of this type. This parameter only takes one value. By default the API returns items that match any of these types.

  • file - Limits the search results to files
  • folder - Limits the search results to folders
  • web_link - Limits the search results to web links, also known as bookmarks

Value is one of file,folder,web_link

string arrayin queryoptional
4535234,234123235,2654345

Limits the search results to items within the given list of folders, defined as a comma separated lists of folder IDs.

Search results will also include items within any subfolders of those ancestor folders.

Please note that the folders still need to be owned or shared with the currently authenticated user. If the folder is not accessible by this user, or it does not exist, a HTTP 404 error code will be returned instead.

To search across an entire enterprise, we recommend using the enterprise_content scope parameter which can be requested with our support team.

string arrayin queryoptional
name,description

Limits the search results to any items that match the search query for a specific part of the file, for example the file description.

Content types are defined as a comma separated lists of Box recognized content types. The allowed content types are as follows.

  • name - The name of the item, as defined by its name field.
  • description - The description of the item, as defined by its description field.
  • file_content - The actual content of the file.
  • comments - The content of any of the comments on a file or folder.
  • tag - Any tags that are applied to an item, as defined by its tag field.
string arrayin queryoptional
2014-05-15T13:35:01-07:00,2014-05-17T13:35:01-07:00

Limits the search results to any items created within a given date range.

Date ranges are defined as comma separated RFC3339 timestamps.

If the the start date is omitted (,2014-05-17T13:35:01-07:00) anything created before the end date will be returned.

If the end date is omitted (2014-05-15T13:35:01-07:00,) the current date will be used as the end date instead.

stringin queryoptional
ASC"DESC"

Defines the direction in which search results are ordered. This API defaults to returning items in descending (DESC) order unless this parameter is explicitly specified.

When results are sorted by relevance the ordering is locked to returning items in descending order of relevance, and this parameter is ignored.

Value is one of DESC,ASC

string arrayin queryoptional
id,type,name

A comma-separated list of attributes to include in the response. This can be used to request fields that are not normally returned in a standard response.

Be aware that specifying this parameter will have the effect that none of the standard fields are returned in the response unless explicitly specified, instead only fields for the mini representation are returned, additional to the fields requested.

string arrayin queryoptional
pdf,png,gif

Limits the search results to any files that match any of the provided file extensions. This list is a comma-separated list of file extensions without the dots.

integer / int64in queryoptional
10030200

Defines the maximum number of items to return as part of a page of results.

Metadata filter arrayin queryoptional
[{"scope":"enterprise","templateKey":"contract","filters":{"category":"online"}}]

A list of metadata templates to filter the search results by.

Required unless query parameter is defined.

integer / int64in queryoptional
10000

The offset of the item at which to begin the response.

string arrayin queryoptional
123422,23532,3241212

Limits the search results to any items that are owned by the given list of owners, defined as a list of comma separated user IDs.

Please note that the items still need to be owned or shared with the currently authenticated user for them to show up in the search results. If the user does not have access to any files owned by any of the users an empty result set will be returned.

To search across an entire enterprise, we recommend using the enterprise_content scope parameter which can be requested with our support team.

stringin queryoptional
sales

The string to search for. This query is matched against item names, descriptions, text content of files, and various other fields of the different item types.

This parameter supports a variety of operators to further refine the results returns.

  • "" - by wrapping a query in double quotes only exact matches are returned by the API. Exact searches do not return search matches based on specific character sequences. Instead, they return matches based on phrases, that is, word sequences. For example: A search for "Blue-Box" may return search results including the sequence "blue.box", "Blue Box", and "Blue-Box"; any item containing the words Blue and Box consecutively, in the order specified.
  • AND - returns items that contain both the search terms. For example, a search for marketing AND BoxWorks returns items that have both marketing and BoxWorks within its text in any order. It does not return a result that only has BoxWorks in its text.
  • OR - returns items that contain either of the search terms. For example, a search for marketing OR BoxWorks returns a result that has either marketing or BoxWorks within its text. Using this operator is not necessary as we implicitly interpret multi-word queries as OR unless another supported boolean term is used.
  • NOT - returns items that do not contain the search term provided. For example, a search for marketing AND NOT BoxWorks returns a result that has only marketing within its text. Results containing BoxWorks are omitted.

Please note that we do not support lower case (that is, and, or, and not) or mixed case (that is, And, Or, and Not) operators.

This field is required unless the mdfilters parameter is defined.

stringin queryoptional
user_content"user_content"

Limits the search results to either the files that the user has access to, or to files available to the entire enterprise.

The scope defaults to user_content, which limits the search results to content that is available to the currently authenticated user.

The enterprise_content can be requested by an admin through our support channels. Once this scope has been enabled for a user, it will allow that use to query for content across the entire enterprise and not only the content that they have access to.

Value is one of user_content,enterprise_content

integer arrayin queryoptional
1000000,5000000

Limits the search results to any items with a size within a given file size range. This applied to files and folders.

Size ranges are defined as comma separated list of a lower and upper byte size limit (inclusive).

The upper and lower bound can be omitted to create open ranges.

stringin queryoptional
modified_at"relevance"

Defines the order in which search results are returned. This API defaults to returning items by relevance unless this parameter is explicitly specified.

  • relevance (default) returns the results sorted by relevance to the query search term. The relevance is based on the occurrence of the search term in the items name, description, content, and additional properties.
  • modified_at returns the results ordered in descending order by date at which the item was last modified.

Value is one of modified_at,relevance

stringin queryoptional
non_trashed_only"non_trashed_only"

Determines if the search should look in the trash for items.

By default, this API only returns search results for items not currently in the trash (non_trashed_only).

  • trashed_only - Only searches for items currently in the trash
  • non_trashed_only - Only searches for items currently not in the trash

Value is one of non_trashed_only,trashed_only

string arrayin queryoptional
2014-05-15T13:35:01-07:00,2014-05-17T13:35:01-07:00

Limits the search results to any items updated within a given date range.

Date ranges are defined as comma separated RFC3339 timestamps.

If the start date is omitted (,2014-05-17T13:35:01-07:00) anything updated before the end date will be returned.

If the end date is omitted (2014-05-15T13:35:01-07:00,) the current date will be used as the end date instead.

Response

Returns a collection of search results. If there are no matching search results, the entries array will be empty.

application/jsonClient error

Returns an error when the request was not valid. This can have multiple reasons and the context_info object will provide you with more details.

  • missing_parameter - Please provide at least the query or mdfilters query parameter in a search.
  • invalid_parameter - Any of the fields might not be in the right format. This could for example mean that one of the RFC3339 dates is incorrect, or a string is provided where an integer is expected.
application/jsonClient error

Returns an error when the user does not have the permission to make this API call.

  • The developer provided a scope of enterprise_content but did not request this scope to be enabled for the user through our support channels.
application/jsonClient error

Returns an error when the user does not have access to an item mentioned in the request.

  • The developer provided a folder ID in ancestor_folder_ids that either does not exist or the user does not have access to.
application/jsonClient error

An unexpected client error.

get
Search for content
You can now try out some of our APIs live, right here in the documentation.
Log in

Request Example

cURL
curl -i -X GET "https://api.box.com/2.0/search?query=sales" \
     -H "Authorization: Bearer <ACCESS_TOKEN>"
.NET
// Search for PDF or Word documents matching "Meeting Notes"
BoxCollection<BoxItem> results = await client.SearchManager
    .QueryAsync("Meeting Notes", fileExtensions: new { "pdf", "docx" });
Java
// Find the first 10 files matching "taxes"
long offsetValue = 0;
long limitValue = 10;
BoxSearch boxSearch = new BoxSearch(api);
BoxSearchParameters searchParams = new BoxSearchParameters();
searchParams.setQuery("taxes");
searchParams.setType("file");
PartialCollection<BoxItem.Info> searchResults = boxSearch.searchRange(offsetValue, limitValue, searchParams);
Python
items = client.search().query(query='TEST QUERY', limit=100, file_extensions=['pdf', 'doc'])
for item in items:
    print('The item ID is {0} and the item name is {1}'.format(item.id, item.name))
Node
// Search for PDF or Word documents matching "Mobile"
client.search.query(
	'Mobile',
	{
		fields: 'name,modified_at,size,extension,permissions,sync_state',
		file_extensions: 'pdf,doc',
		limit: 200,
		offset: 0
	})
	.then(results => {
		/* results -> {
			total_count: 1,
			entries: 
			[ { type: 'file',
				id: '11111',
				sequence_id: '1',
				etag: '1',
				sha1: 'f89d97c5eea0a68e2cec911s932eca34a52355d2',
				name: 'Box for Sales - Empowering Your Mobile Worker White paper 2pg (External).pdf',
				description: '',
				size: 408979,
				path_collection: 
					{ total_count: 2,
					entries: 
					[ { type: 'folder',
						id: '0',
						sequence_id: null,
						etag: null,
						name: 'All Files' },
						{ type: 'folder',
						id: '22222',
						sequence_id: '1',
						etag: '1',
						name: 'Marketing Active Work' } ] },
				created_at: '2014-05-17T12:59:45-07:00',
				modified_at: '2014-05-17T13:00:20-07:00',
				trashed_at: null,
				purged_at: null,
				content_created_at: '2014-05-17T12:58:58-07:00',
				content_modified_at: '2014-05-17T12:58:58-07:00',
				created_by: 
					{ type: 'user',
					id: '33333',
					name: 'Example User',
					login: 'user@example.com' },
				modified_by: 
					{ type: 'user',
					id: '33333',
					name: 'Example User',
					login: 'user@example.com' },
				owned_by: 
					{ type: 'user',
					id: '33333',
					name: 'Example User',
					login: 'user@example.com' },
				shared_link: null,
				parent: 
					{ type: 'folder',
					id: '22222',
					sequence_id: '1',
					etag: '1',
					name: 'Marketing Active Work' },
				item_status: 'active' } ],
			limit: 200,
			offset: 0 }
		*/
	});
iOS
client.search.query(query: "Quarterly Business Review") { results in
    switch results {
    case let .success(iterator):
        for i in 1 ... 10 {
            iterator.next { result in
                switch result {
                case let .success(item):
                    switch item {
                    case let .file(file):
                        print("- File \(file.name) (ID: \(file.id))")
                    case let .folder(folder):
                        print("- Folder \(file.name) (ID: \(file.id))")
                    case let .webLink(webLink):
                        print("- Web Link \(file.name) (ID: \(file.id))")
                    }
                case let .failure(error):
                    print(error)
                }
            }
        }
    case let .failure(error):
        print(error)
    }
}

Response Example

{
  "entries": [
    {
      "id": 12345,
      "etag": 1,
      "type": "file",
      "sequence_id": 3,
      "name": "Contract.pdf",
      "sha1": "85136C79CBF9FE36BB9D05D0639C70C265C18D37",
      "file_version": {
        "id": 12345,
        "type": "file_version",
        "sha1": "134b65991ed521fcfe4724b7d814ab8ded5185dc"
      },
      "description": "Contract for Q1 renewal",
      "size": 629644,
      "path_collection": {
        "total_count": 1,
        "entries": [
          {
            "id": 12345,
            "etag": 1,
            "type": "folder",
            "sequence_id": 3,
            "name": "Contracts"
          }
        ]
      },
      "created_at": "2012-12-12T10:53:43-08:00",
      "modified_at": "2012-12-12T10:53:43-08:00",
      "trashed_at": "2012-12-12T10:53:43-08:00",
      "purged_at": "2012-12-12T10:53:43-08:00",
      "content_created_at": "2012-12-12T10:53:43-08:00",
      "content_modified_at": "2012-12-12T10:53:43-08:00",
      "created_by": {
        "id": 11446498,
        "type": "user",
        "name": "Aaron Levie",
        "login": "ceo@example.com"
      },
      "modified_by": {
        "id": 11446498,
        "type": "user",
        "name": "Aaron Levie",
        "login": "ceo@example.com"
      },
      "owned_by": {
        "id": 11446498,
        "type": "user",
        "name": "Aaron Levie",
        "login": "ceo@example.com"
      },
      "shared_link": {
        "url": "https://www.box.com/s/vspke7y05sb214wjokpk",
        "download_url": "https://www.box.com/shared/static/rh935iit6ewrmw0unyul.jpeg",
        "vanity_url": "https://acme.app.box.com/v/my_url/",
        "vanity_name": "my_url",
        "access": "open",
        "effective_access": "company",
        "effective_permission": "can_download",
        "unshared_at": "2018-04-13T13:53:23-07:00",
        "is_password_enabled": true,
        "permissions": {
          "can_download": true,
          "can_preview": true
        },
        "download_count": 3,
        "preview_count": 3
      },
      "parent": {
        "id": 12345,
        "etag": 1,
        "type": "folder",
        "sequence_id": 3,
        "name": "Contracts"
      },
      "item_status": "active"
    }
  ],
  "limit": 1000,
  "offset": 2000,
  "total_count": 5000
}