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
with the labelIds parameter. This allows you to search for messages and
threads with the specified system or user labels applied. For more information,
see the messages.list or
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 myprimary@mycompany.net and your admin sets up an alias for that account of
myalias@mycompany.net. If myalias@mycompany.net sends an email, but you
search for "from: myprimary@mycompany.net)" the email sent by
myalias@mycompany.net shows 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.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-12-19 UTC."],[[["The Gmail API provides methods (`messages.list` and `threads.list`) to search and filter emails using the `q` parameter, supporting advanced search syntax similar to the Gmail web interface."],["You can construct search queries to filter emails by attributes like sender, date, or label, with a caveat that dates are interpreted as PST midnight unless specified in seconds."],["Filtering can also be done by label using the `labelIds` parameter, allowing searches for messages with specific system or user labels."],["While the Gmail UI automatically expands aliases in searches, the API does not, meaning searches must use the exact email address."],["Thread-wide searches are supported in the Gmail UI but are not available through the API."]]],[]]