Is it possible to search Box items based on the metadata?

1.2k views Asked by At

API documentation below does not mention how to search based on the metadata. Is it really possible? Can someone point me to an example?

https://developers.box.com/docs/#search

thanks in advance! Milind

2

There are 2 answers

0
Dan Dautrich On

I had the same question and asked Box directly. This is the reply they sent me:

You can only use the mdfilters parameter if you have a custom "template" in your enterprise account: https://box-content.readme.io/#metadata-object. The properties template doesn't work with the mdfilters parameter; however, properties DO get indexed in general searches.

If you have an Enterprise account with Box they can set up custom metadata templates that can be searched via the mdfilters parameter, otherwise use the query parameter.

0
AudioBubble On

Yes, it is possible. Here's an example provided, in Java, that comes straight from a member of the java-sdk Box group on Github.

BoxSearch boxSearch = new BoxSearch(api);
BoxSearchParameters searchParams = new BoxSearchParameters();

BoxMetadataFilter metadataFilter = new BoxMetadataFilter();
metadataFilter.setScope("enterprise");
metadataFilter.setTemplateKey("myTemplate");
metadataFilter.addFilter("myField", "fieldValue");
searchParams.setMetadataFilter(metadataFilter);

PartialCollection<BoxItem.Info> searchResults = boxSearch.searchRange(0, 100, searchParams);

WARNING

A file cannot be searched for based on its metadata for at least 5-10 minutes after updating the file with the metadata that you're using to search for the file. Refer to the accepted solution on this forum question, that was posted to the Box community and answered by a "trusted contributor", for an explanation as to why this behavior occurs.