Canonical: https://weaveos.com/reference/gmail/search-messages

1. [Software capabilities](https://weaveos.com/reference)
2. /[Gmail](https://weaveos.com/reference/gmail)
3. /How to search Gmail messages

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 November 26, 2026

## 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%3Apdf
```

[Read source: Gmail message list reference ↗](https://developers.google.com/workspace/gmail/api/reference/rest/v1/users.messages/list)

Interface

### 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
```

[Read source: Gmail search operators ↗](https://support.google.com/mail/answer/7190)

## More from Gmail

[View all Gmail capabilities →](https://weaveos.com/reference/gmail)

- [How to download Gmail attachments↗](https://weaveos.com/reference/gmail/download-attachments)
- [How to retrieve the body of a Gmail message↗](https://weaveos.com/reference/gmail/read-message)
- [How to apply a Gmail label↗](https://weaveos.com/reference/gmail/apply-label)
