You can search or filter files using the
These methods accept the
q parameter which supports most of the same
advanced search syntax as
the Gmail web-interface. For a list of search and filter differences between
the Gmail UI and Gmail API, see
Search filter differences: Gmail UI versus Gmail API.
This advanced syntax allows you to use search queries to filter messages by properties such as the sender, date, or label to name a few possibilities. For example, the following query retrieves all messages sent by the user in January of 2014:
GET https://www.googleapis.com/gmail/v1/users/me/messages?q=in:sent after:2014/01/01 before:2014/02/01
In addition to search queries, you can also filter messages and threads by label
labelIds parameter. This allows you to search for messages and
threads with the specified system or user labels applied. For more information,
threads.list method reference.
Search and filter differences: Gmail UI versus Gmail API
The Gmail UI performs alias expansion which allows it to infer an account alias from a Google Workspace account. For example, suppose you have an account of
email@example.com your admin sets up an alias for that account of
firstname.lastname@example.org an email, but you search for "
from: email@example.com)" the email sent by
firstname.lastname@example.org up as a search result the Gmail UI, but not in the API response.
The Gmail UI allows users to perform thread-wide searches, but the API doesn't.