Query string to filter file results. Accepts both simple text searches and full Google Drive query syntax.
**Simple Text Search:** Bare text (e.g., "SAM RFP") is auto-converted to fullText search. Bare email addresses are auto-converted to owner search.
**Full Query Syntax:** 'field operator value' combined with 'and', 'or', 'not'
**Operators:** =, !=, <, >, <=, >=, contains, in
**Common Fields:**
- `name` - File name (exact match with = or partial match with contains)
- `fullText` - File content search
- `mimeType` - File type (e.g., 'application/pdf', 'application/vnd.google-apps.folder')
- `modifiedTime`, `createdTime` - Dates (RFC 3339: '2024-01-01T00:00:00')
- `parents` - Folder IDs containing the file
- `owners`, `writers` - User email addresses (MUST use 'in' operator, NOT colon syntax)
- `properties`, `appProperties` - Custom metadata
**Boolean Filter Fields (sharedWithMe, trashed, starred):**
These fields require explicit `= true` or `= false` syntax:
- `sharedWithMe = true` - Find files shared with you by others
- `sharedWithMe = false` - Find files NOT shared with you (your own files)
- `trashed = true` - Find files in trash
- `trashed = false` - Exclude trashed files from results
- `starred = true` - Find starred/favorited files
- `starred = false` - Find non-starred files
Combine with other conditions using 'and':
- "sharedWithMe = true and name contains 'report'" - Find shared files with 'report' in name
- "sharedWithMe = true and mimeType = 'application/pdf'" - Find shared PDF files
- "starred = true and modifiedTime > '2024-01-01T00:00:00'" - Find recently modified starred files
**Query Complexity Limits:**
Queries with many OR clauses (typically >5-10) may fail with 'The query is too complex' error.
**Name Field Usage:**
Wildcards (*) are NOT supported. Use 'contains' operator for partial matching.
**User Email Searches:**
- CORRECT: "'user@example.com' in owners" or "'user@example.com' in writers" or "'user@example.com' in readers"
- INCORRECT: "owner:user@example.com" (colon syntax is NOT supported and will cause errors)
- Always use the 'in' operator with quoted email addresses for user-based searches
**Special Syntax:**
- Dates: RFC 3339 format (time zone defaults to UTC)
- Apostrophes/quotes in values: Automatically escaped. You can write "name = 'Jan'26'" or "name = 'Valentine's Day'" without manual escaping.
- Grouping: Use parentheses for OR: "(mimeType contains 'image/' or mimeType contains 'video/')"
- Custom properties: "properties has { key='department' and value='sales' }"
**IMPORTANT - Root Folder ('My Drive'):**
'My Drive' is NOT a searchable folder name. To work with the root folder, use the 'root' alias: folder_id='root' or "'root' in parents" in your query.
Selector specifying which fields to include in a partial response. Use '*' for all fields.
**Default Behavior (Recommended for Discovery):**
When omitted, returns essential file discovery fields: id, name, mimeType, size, modifiedTime, createdTime, parents, webViewLink, trashed, starred. This lightweight default is optimized for file search/discovery use cases without verbose permission or capability metadata.
**Format:** For file fields, use 'files(field1,field2,...)' format. For example: 'files(id,name,mimeType)'.
Top-level response fields (kind, nextPageToken, incompleteSearch) can be used directly.
**Note:** Bare field names like 'id,name,mimeType' will be automatically wrapped in 'files()' for convenience.
The 'editors' field is not valid in Drive API v3; use 'permissions' instead for access control information.
A comma-separated list of spaces to query. Supported values are 'drive', 'appDataFolder' and 'photos'.
Default: "drive"
Specifies which collections of files to search. Defaults to 'allDrives' (searches My Drive + all accessible shared drives).
**Values:**
- `user` - Search only user's personal My Drive
- `domain` - Search all files shared within Google Workspace domain
- `drive` - Search specific shared drive (requires 'driveId' parameter and 'includeItemsFromAllDrives' must be true)
- `allDrives` - Search My Drive + all accessible shared drives (DEFAULT, requires 'includeItemsFromAllDrives' to be true)
**When to Use:**
- Personal files only: Use 'user'
- Organization-wide: Use 'domain'
- Specific shared drive: Use 'drive' with 'driveId'
- Maximum coverage: Use 'allDrives' (auto-enables supportsAllDrives and includeItemsFromAllDrives)
Options: user, drive, domain, allDrives
Default: "allDrives"
ID of the shared drive to search. When provided, 'corpora' will automatically be set to 'drive' (mutually exclusive with corpora='allDrives'). Required if 'corpora' is 'drive'.
Comma-separated sort keys. Ascending by default; add 'desc' for descending. Cannot be used when query (q) contains fullText search terms.
**Valid Keys:**
- `createdTime`, `modifiedTime`, `modifiedByMeTime` - Dates
- `viewedByMeTime`, `sharedWithMeTime` - Activity dates
- `name`, `name_natural` - File name (natural: file1, file2, file10)
- `folder` - Folder hierarchy
- `quotaBytesUsed` - Storage size (NOTE: 'size' is NOT valid, use 'quotaBytesUsed')
- `starred` - Starred status
- `recency` - Recent activity (combines view time and modification time for relevance-based sorting)
**Important:** 'size' is NOT a valid sort key. Use 'quotaBytesUsed' to sort by file size.
**Restriction:** Sorting is not supported when the query contains fullText searches (e.g., "fullText contains 'keyword'"). Omit orderBy when using fullText queries.
The maximum number of files to return per page.
Default: 100
ID of a specific folder to search within. This automatically adds "'folder_id' in parents" to the query. Can be combined with the 'q' parameter to further filter results within the folder. Use 'root' to search within the user's root folder (My Drive). Note: 'My Drive' is not a searchable folder name - use 'root' alias instead.
The token for continuing a previous list request on the next page. IMPORTANT: This must be the exact opaque string from a previous response's 'nextPageToken' field - do not modify, truncate, URL-encode, or construct tokens manually. Invalid or corrupted tokens will result in API errors.
A comma-separated list of label IDs to include in the `labelInfo` part of the response for each file. Empty strings are automatically treated as omitted.
Indicates whether the page token was dropped from the request.
Default: false
Whether the requesting application supports both My Drives and shared drives. If 'includeItemsFromAllDrives' is true, this must also be true.
Default: true
original_email_query
STRINGThe original email query before transformation.
editors_field_removed
BOOLEANIndicates whether the editors field was removed from the request.
Default: false
email_query_transformed
BOOLEANIndicates whether an email query was transformed into a search filter.
Default: false
orderby_size_transformed
BOOLEANIndicates whether the orderBy size value was transformed.
Default: false
original_bare_text_query
STRINGThe original bare text query before transformation.
includeItemsFromAllDrives
BOOLEANWhether both My Drive and shared drive items should be included in results. Must be true when corpora is 'drive' or 'allDrives'. If true, 'supportsAllDrives' should also be true.
Default: true
emailaddress_field_removed
BOOLEANIndicates whether the email address field was removed from the request.
Default: false
original_invalid_pagetoken
STRINGThe original invalid page token that was dropped.
bare_text_query_transformed
BOOLEANIndicates whether a bare text query was transformed into a search filter.
Default: false
include_permissions_for_view
STRINGSpecifies which additional view's permissions to include in the response. Must be either omitted entirely or set to 'published'. Empty strings are automatically treated as omitted.