Return specific fields for a file

Stay organized with collections Save and categorize content based on your preferences.

By default, the server sends back a default set of resource fields specific to the resource being queried. For example, the files.get method might only return the id, name, and mimeType for the files resource. The permissions.get method returns a different set of default fields for a permissions resource.

To return the exact fields you need, and improve performance, use the fields query parameter in your method call. To determine the fields you can return using the fields parameter, visit the documentation page of the resource you are querying. For example, to see what fields you can return for a file, refer to the files resource documentation.

Show an example

Request

In this example, we provide the file ID path parameter and multiple fields as a query parameter in the request. The response returns the field values for the file ID.

GET https://www.googleapis.com/drive/v3/files/FILE_ID?fields=name,starred,shared

Response

{
  "name": "File1",
  "starred": false,
  "shared": true
  }
}

Fetch the fields of a nested resource

When a field refers to another resource, you can specify which fields of the nested resource should be fetched.

For example, to retrieve the role field (nested resource) of the permissions resource, use any of the following options:

  • permissions.get with fields=role or fields=*.
  • files.get with fields=permissions(role) or fields=permissions/role.
  • files.get with fields=permissions to imply all fields of the nested resource.
  • changes.list with fields=changes(file(permissions(role))).

To retrieve multiple fields, use a comma-separated list. For example, files.list with fields=files(id,name,createdTime,modifiedTime,size).

Show an example

Request

In this example, we provide the file ID path parameter and multiple fields, including certain fields of the nested permissions resource, as a query parameter in the request. The response returns the field values for the file ID.

GET https://www.googleapis.com/drive/v3/files/FILE_ID?fields=name,starred,shared,permissions(kind,type,role)

Response

{
  "name": "File1",
  "starred": false,
  "shared": true,
  "permissions": [
    {
      "kind": "drive#permission",
      "type": "user",
      "role": "owner"
    }
  ]
}