Skip to main content

Hi All,

I want to know anybody used Box Search API (https://api.box.com/2.0/search?) for fetching metadata information of all files. As per my understanding, currently we are getting only file id , name..etc details.  For my application need to search files with metadata information , now i need to make two api calls for getting this information. Also metadata api call need to execute for individual files. Its making performance issue with my search functionality. If anybody know the exact solution for this, please share.

 

Thanks,

Vijeesh

 


 You can use the `fields` query parameter to specify that you want metadata returned with your search results, like this:


 


curl -H"Authorization: Bearer ACCESS_TOKEN" https://api.box.com/2.0/search?query=Test&fields=name,metadata.enterprise.mymetadata


Thanks for your information. I have tried with same format for field. But i am getting metadata with null values. Is there any other information need to add for this 



 Did you replace the template name in the field parameter to match the actual metadata template key you want to retrieve?  The format should be `metadata..` where scope is either "global" or "enterprise", and templateKey is the key of the metadata template you want.



 Thank you for your post, this was the exact information I needed as I was facing the same issue with needing the files metadata to be returned when i performed a search.

My concern is I only found this solution in a forum post. I first came across the setFields(List fields) method in the Java SDK and it seemed like it would be helpful so i started searching the box search api documentation (https://developer.box.com/reference#searching-for-content) and it described the 'fields' parameter but i could not find any list of available fields that were allowed to be used. Are all available fields documented somewhere? 

 

UPDATE : looking a little harder i found the file object definition (https://developer.box.com/reference#file-object) that specifies some parameter names, would be helpful to show a full example for the metadata one like you posted here though 🙂

metadata..

object

Specific metadata on the file, identified by scope and templateKey. The limit of metadata instances to be requested this way is 3.

 

 /**
* Set the existing fields that are used for the search criteria.
* @param fields specify what fields to be returned.
*/
public void setFields(List fields) {
this.fields = fields;
}

 

Fields

Each object has "standard" and "mini" formats, which include a certain set of fields:

The standard format is returned when you request a specific object (e.g. GET /files/{id}).
The mini format is returned when the object is part of a set of items (e.g. GET /files/{id}/comments).
Less-frequently used fields are not included in either the standard or mini format. These are listed in italics in the object definitions.
In addition to the standard and mini formats, you can have the API return a specific set of fields using the fields query parameter. Specify a comma-separated list of the field names (with no spaces after the commas). Only the fields you request are returned, as well as the type and id fields (which are always returned). For example, if you call GET /files/{id}?fields=modified_at,path_collection,name, it will return the type, id, modified_at, path_collection, and name fields.



 



 I will ensure this feedback is relayed to our developer documentation team! Thank you for all the input! 



Reply