Gmail capability
How to search Gmail messages
Use Gmail search operators in the inbox or pass a query as q to users.messages.list. The API returns message IDs that you can use to fetch individual messages.
Documentation reviewed
Ways to do it
API
users.messages.list with q
Pass a Gmail search expression in q and paginate through the matching message IDs.
- Requirements
- An authorized Gmail OAuth token with a scope such as gmail.readonly.
- Limitations
- The gmail.metadata scope does not allow q. Read the returned message IDs separately to retrieve the bodies.
Example
GET https://gmail.googleapis.com/gmail/v1/users/me/messages?q=has%3Aattachment%20filename%3ApdfInterface
Gmail search operators
Enter search operators in the Gmail search box to narrow results by sender, date, attachment or label.
- Requirements
- Access to Gmail for the account you want to search.
- Limitations
- Regular search leaves out Spam and Trash. Use in:anywhere to include them.
Example
from:billing@example.com has:attachment filename:pdf