Return specific fields for a file

By default, the server sends back a default set of resource fields specific to the method used. For example, the files.get method might only return the id, name, and mimeType.

To return the exact fields you need, and improve performance, use the fields query parameter in your method call.

Formatting rules for the fields parameter

The format of the fields request parameter value is loosely based on XPath syntax. Following are formatting rules for the fields parameter. All of these rules use examples related to the files.get function call.

  • Use a comma-separated list to select multiple fields, such as 'title, mimeType'.

  • Use a/b to select a field b that is nested within field a, such as 'labels/starred'.

  • Use a sub-selector to request a set of specific sub-fields of arrays or objects by placing expressions in parentheses "()". For example, 'permissions(id)' returns only the permission ID for each element in the permissions array.

  • Use an asterisk as a wild card in field selections to return all fields in an object. For example, 'permissions/permissionDetails/*' selects all available permission details fields per permission. Note that the use of this wildcard can lead to negative performance impact on the request.

After a server processes a valid request that includes the fields query parameter, it sends back an HTTP 200 OK status code, along with the requested data. If the fields query parameter has an error or is otherwise invalid, the server returns an HTTP 400 Bad Request status code, along with an error message telling you what was wrong with your fields selection. For example, files.list(fields='files(id,capabilities/canAddChildre)'); yields an error of "Invalid field selection canAddChildre".