Skip to content

How to list Google email messages

Gmail and Google Workspace accounts are the most common provider type developers integrate with. If you’ve ever worked with the Gmail API directly, you know the OAuth verification process, scope restrictions, and label system add significant friction. Nylas abstracts all of that behind the same Messages API you’d use for Microsoft or IMAP.

This guide walks through listing messages from Google accounts and covers the Google-specific details you need to know: labels, search operators, OAuth scopes, and rate limits.

Why use Nylas instead of the Gmail API directly?

Section titled “Why use Nylas instead of the Gmail API directly?”

The Gmail API requires more setup overhead than most developers expect. You need to configure a GCP project, navigate Google’s three-tier OAuth scope system (non-sensitive, sensitive, restricted), and for any scope beyond basic metadata, go through Google’s OAuth verification or even a full third-party security assessment. On top of that, the Gmail data model uses labels instead of folders, message IDs are hex strings, and rate limits are enforced at both the per-user and per-project level.

Nylas normalizes all of this. Labels map to a unified folder model. Token refresh and scope management happen automatically. You don’t need a GCP project or a security assessment to get started. And your code works across Gmail, Outlook, Yahoo, and IMAP without any provider-specific branches.

If you only need Gmail and want full control over the integration, the Gmail API works. If you need multi-provider support or want to skip the verification process, Nylas is the faster path.

You’ll need:

New to Nylas? Start with the quickstart guide to set up your app and connect a test account before continuing here.

Google classifies OAuth scopes into three tiers, and each one comes with different verification requirements:

Scope tierExampleWhat’s required
Non-sensitivegmail.labelsNo verification needed
Sensitivegmail.readonly, gmail.composeOAuth consent screen verification
Restrictedgmail.modifyFull security assessment by a third-party auditor

If your app needs to read message content (not just metadata), you’ll need at least the gmail.readonly scope, which is classified as sensitive. For read-write access, gmail.modify is restricted and requires a security assessment.

Nylas handles the token management, but your GCP project still needs the right scopes configured. See the Google provider guide for the full setup.

Make a List Messages request with the grant ID. By default, Nylas returns the 50 most recent messages. These examples limit results to 5:

You can narrow results with query parameters. Here’s what works with Google accounts:

ParameterWhat it doesExample
subjectMatch on subject line?subject=Weekly standup
fromFilter by sender[email protected]
toFilter by recipient[email protected]
unreadUnread messages only?unread=true
inFilter by folder or label ID?in=INBOX
received_afterAfter a Unix timestamp?received_after=1706000000
received_beforeBefore a Unix timestamp?received_before=1706100000
has_attachmentOnly messages with attachments?has_attachment=true

When using the in parameter with Google accounts, you must use the folder (label) ID, not the display name. Nylas does not support filtering by label name on Google accounts. Use the List Folders endpoint to get the correct IDs.

Here’s how to combine filters. This pulls unread messages from a specific sender:

For more advanced filtering, you can use Gmail’s native search syntax through the search_query_native parameter. This supports the same search operators you’d use in the Gmail search bar:

Some useful Gmail search operators:

OperatorWhat it doesExample
from:Messages from a senderfrom:[email protected]
to:Messages to a recipientto:[email protected]
subject:Subject line containssubject:invoice
has:attachmentHas file attachmentshas:attachment
filename:Attachment filenamefilename:report.pdf
after:Messages after a dateafter:2025/01/01
before:Messages before a datebefore:2025/02/01
is:unreadUnread messagesis:unread
label:Messages with a labellabel:important
ORCombine conditionsfrom:alex OR from:priya

When using search_query_native, you can only combine it with the in, limit, and page_token parameters. Other query parameters will return an error. See the search best practices guide for more details.

A few provider-specific details that matter when you’re building against Gmail and Google Workspace accounts.

This is the biggest conceptual difference from Microsoft. Gmail uses labels instead of folders, so a single message can have multiple labels at once. When you list messages with ?in=INBOX, you’re filtering by the INBOX label, not a folder.

Nylas normalizes this into a folders array on each message object. A Gmail message might look like:

{
"folders": ["INBOX", "UNREAD", "CATEGORY_PERSONAL", "IMPORTANT"]
}

Common system labels you’ll see:

Gmail UI nameLabel ID
InboxINBOX
SentSENT
DraftsDRAFT
TrashTRASH
SpamSPAM
StarredSTARRED
ImportantIMPORTANT
Primary tabCATEGORY_PERSONAL
Social tabCATEGORY_SOCIAL
Promotions tabCATEGORY_PROMOTIONS
Updates tabCATEGORY_UPDATES

Custom labels created by the user will have auto-generated IDs. Use the List Folders endpoint to discover them. Google also supports custom label colors via text_color and background_color parameters when creating or updating folders.

Message IDs are shorter than Microsoft’s

Section titled “Message IDs are shorter than Microsoft’s”

Google message IDs are shorter hex-style strings (like 18d5a4b2c3e4f567), compared to Microsoft’s long base64-encoded IDs. They’re stable across syncs and safe to store in your database.

The thread_id field is a Google-native concept. Gmail groups related messages into threads automatically. If you’re building an inbox UI, you’ll probably want to use the Threads API instead of listing individual messages.

Google enforces quotas at two levels:

  • Per-user: Each authenticated user has a daily quota for API calls
  • Per-project: Your GCP project has an overall daily limit across all users

Nylas handles retries when you hit rate limits, but if your app polls aggressively for many users, you may exhaust your project quota. Two ways to avoid this:

  • Use webhooks instead of polling so Nylas notifies your server when new messages arrive
  • Set up Google Pub/Sub for real-time sync, which gives you faster notification delivery for Gmail accounts with gmail.readonly or gmail.labels scopes

If your app sends marketing or subscription email through Gmail accounts, be aware that Google requires one-click unsubscribe headers for senders who send more than 5,000 messages per day to Gmail addresses. You’ll need to include List-Unsubscribe-Post and List-Unsubscribe custom headers in your send requests.

This doesn’t affect listing messages, but it’s worth knowing if your app both reads and sends email. See the email documentation for implementation details.

Both work with Nylas, but there are differences:

  • Workspace admins can restrict which third-party apps have access. If a Workspace user can’t authenticate, their admin may need to allow your app in the Google Admin console.
  • Delegated mailboxes (shared mailboxes in Workspace) require special handling. See the shared accounts guide.
  • Service accounts are available for Google Workspace Calendar access (not email). See the service accounts guide.

The Messages API returns paginated responses. When there are more results, the response includes a next_cursor value. Pass it back as page_token to get the next page:

Keep paginating until the response comes back without a next_cursor.