Skip to content

Using the Nylas Messages API

The Nylas Messages API lets you read, search, update, and delete email messages across Gmail, Microsoft 365, and IMAP providers through a single unified interface. A message is the core email object in Nylas, representing a single email with its subject, sender, recipients, body content, attachments, and folder assignments. Related messages are grouped into threads.

Use the Messages API to read messages from a user’s inbox, search for messages using provider-native queries, update message status (read/unread, starred, folder), and delete messages. The API works identically across all providers — your code doesn’t need provider-specific branches. To receive real-time notifications when messages arrive, use webhooks instead of polling.

Looking for the full API reference? See the Messages API reference for all endpoints, parameters, and response schemas.

You need a Nylas developer account and API key. See the Getting started guide to set up a Sandbox application and connect a provider account. You’ll also need a grant for the email account you want to access. The code examples on this page use the Nylas SDKs — see the SDK documentation for installation and setup.

To retrieve messages, make a List Messages request with the grant ID. The endpoint returns messages in reverse chronological order. By default, it returns the 50 most recent messages (configurable with limit, max 200).

Each message object contains the following fields:

FieldTypeDescription
idstringUnique identifier for the message. Format varies by provider (hex string for Google, base64 for Microsoft, numeric UID for IMAP).
objectstringAlways "message".
grant_idstringThe grant ID of the account this message belongs to.
thread_idstringThe ID of the thread this message belongs to. Use the Threads API to group related messages.
subjectstringThe message subject line.
fromarrayList of sender objects, each with name and email fields.
toarrayList of recipient objects, each with name and email fields.
ccarrayList of CC recipient objects.
bccarrayList of BCC recipient objects. Empty on received messages.
reply_toarrayList of reply-to addresses.
dateintegerUnix timestamp (seconds) when the message was sent or received.
unreadbooleanWhether the message is unread.
starredbooleanWhether the message is starred (flagged in Microsoft).
snippetstringA short plaintext preview of the message body (first ~200 characters).
bodystringThe full message body in HTML format. Only included when requesting a single message.
foldersarrayList of folder or label IDs the message belongs to. Google messages may have multiple labels.
attachmentsarrayList of attachment objects with id, filename, size, content_type, and is_inline fields.
created_atintegerUnix timestamp when Nylas first synced this message.

For the complete schema including all optional fields, see the Messages API reference.

The Messages endpoint returns up to 50 messages per request by default (configurable with limit, max 200). To retrieve additional pages, pass the next_cursor value from the response as the page_token query parameter in your next request.

# First request
curl --request GET \
--url 'https://api.us.nylas.com/v3/grants/<NYLAS_GRANT_ID>/messages?limit=50' \
--header 'Authorization: Bearer <NYLAS_API_KEY>'
# Next page -- use next_cursor from previous response
curl --request GET \
--url 'https://api.us.nylas.com/v3/grants/<NYLAS_GRANT_ID>/messages?limit=50&page_token=<NEXT_CURSOR>' \
--header 'Authorization: Bearer <NYLAS_API_KEY>'

When next_cursor is null or absent in the response, you’ve reached the last page.

Each message has a unique id field. Nylas uses the provider’s native ID format, so message IDs look different depending on the email provider:

ProviderID formatExample
GoogleShort hex string18d5a4b2c3e4f567
MicrosoftLong base64 stringAAMkAGI2TG93AAA=
IMAP/Yahoo/iCloudNumeric UID12345

You can add query parameters to a List Messages request to filter and search for messages.

Common query parameters:

ParameterTypeDescription
subjectstringFilter by subject line (partial match).
fromstringFilter by sender email address.
tostringFilter by recipient email address.
instringFilter by folder ID. For Google, use the label ID, not the display name.
unreadbooleanFilter by read/unread status.
has_attachmentbooleanFilter for messages with attachments.
received_beforeintegerUnix timestamp. Return messages received before this time.
received_afterintegerUnix timestamp. Return messages received after this time.
limitintegerMax results per page (default 50, max 200).

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

For advanced filtering, use the search_query_native parameter to pass provider-native search syntax directly to the underlying API.

ProviderSyntaxExampleDocs
GoogleGmail search operatorsfrom:[email protected] has:attachmentSearch best practices
MicrosoftKeyword Query Language (KQL)subject:invoiceMicrosoft Graph $search
IMAP/Yahoo/iCloudRFC 3501 SEARCHsubject:invoiceIMAP search guide

Google and Microsoft restrict which parameters you can combine with search_query_native. You can only use it with in, limit, and page_token. IMAP-based providers (Yahoo, iCloud, generic IMAP) allow combining it with any parameter.

For provider-specific search details, see the search best practices guide and the provider-specific guides for Google, Microsoft, and IMAP.

The Messages API supports updating message metadata and deleting messages. Here are the available operations:

ActionMethodAPI referenceWhat it does
Update a messagePUTUpdate MessageChange unread/starred status, move to a different folder
Delete a messageDELETEDelete MessageDelete a message (moves to Trash on most providers)
Create a folderPOSTCreate FolderCreate a new folder or label
Update a folderPUTUpdate FolderRename a folder or label
Delete a folderDELETEDelete FolderDelete a folder or label
Upload an attachmentPOSTAttachmentsUpload a file to use as an attachment

For detailed parameters and response schemas, see the Messages, Folders, and Attachments API references. To track email opens and link clicks, see Message tracking.

  • Rate limits apply at both the Nylas and provider level. Nylas enforces its own API rate limits, and each provider has additional per-user or per-project quotas. Use webhooks instead of polling to minimize API calls.
  • Messages are returned in reverse chronological order by default. Use received_before and received_after to narrow the time range.
  • Nylas maintains a 90-day rolling cache for all IMAP-based providers (Yahoo, iCloud, generic IMAP) to improve performance and API reliability. For queries outside that 90-day window, or to query the provider directly, set query_imap=true.
  • The body field is only included on single-message requests. List requests return snippet instead. Use the Get Message endpoint to get the full body.
  • Google uses labels instead of folders. A single Gmail message can have multiple labels. The folders array on Google messages contains label IDs like INBOX, UNREAD, and CATEGORY_PERSONAL.

One-click unsubscribe requirements for Google

Section titled “One-click unsubscribe requirements for Google”

As of February 2024, Google requires that users who send more than 5,000 messages per day to Gmail email addresses include one-click unsubscribe headers in their marketing and subscribed messages (see Google’s official Email sender guidelines). This is along with the visible unsubscribe links that must be in the body content of all marketing and subscribed messages.

To set up one-click unsubscribe headers using Nylas, include the custom_headers object in your Send Message or Create Draft request. This object accepts a set of key-value pairs, each of which represents the header’s name and its value. You must include the following headers:

  • List-Unsubscribe-Post: List-Unsubscribe=One-Click
  • List-Unsubscribe: The unsubscribe link (for example, a mailto link that uses the user’s email address, or a link to your list management software).
"custom_headers":[
{
"name": "List-Unsubscribe-Post",
"value": "List-Unsubscribe=One-Click"
},
{
"name": "List-Unsubscribe",
"value": "<mailto: [email protected]?subject=unsubscribe>, <https://mailinglist.example.com/unsubscribe.html>"
}
]