Skip to content

Using the Threads API

The Nylas Threads API gives you more control over how you detect collections of messages, and how you respond to them. This page explains how to work with the Threads API.

How threads work

Most providers organize email messages both as individual messages, and as threads. Threads represent collections of email messages that are related to each other and result from participants replying to an email conversation.

Every email message is associated with a thread, whether that thread contains only one message or many.

When you look at threads from a code perspective, you can detect a thread and group email messages using several criteria (the message subject, recipients, senders, and so on). Grouping several email messages into a thread provides a coherent view of an email conversation. In long or fast-moving conversations, threads help the reader follow the discussion.

For Google and Microsoft accounts, Nylas threads email messages together so they’re as similar as possible to the behavior that end users have come to expect from email clients.

Threads are non-linear

Threads are organized non-linearly, as collections of related email messages. Email service providers use criteria such as the message subject, its recipients, and so on to collect email messages into threads. They also keep track of the message_ids for each email message in the thread.

Because all of a thread’s message_ids are logged, you can reply to a specific email message by referencing its ID. This creates a new branch of the thread — similar to a tree structure — and the email messages in the new branch continue to be associated with the thread.

Build a fully-fledged inbox with the Threads API

You can use the /threads endpoint to emulate popular inbox UIs, like Gmail or Outlook, which group email messages into threads. This gives users a simple, centralized view of their latest email conversation. By combining this view with calls to the /messages endpoint, you can build a fully-fledged inbox in your application.

Before you begin

Before you can use the Threads API, you need the following prerequisites:

  • A v3 Nylas application.
  • A working authentication configuration. Either…
    • A Nylas Dashboard v3 Sandbox application which includes a demonstration auth config, OR
    • A v3 provider auth app (Google or Azure), and a connector for that auth app.
  • A Google or Microsoft grant with at least the following scopes:
    • Google: gmail.readonly
    • Microsoft: Mail.Read

Get a list of threads

The following examples show how to return the five most recent threads from an authenticated account. For more information on filtering requests, see Avoiding rate limits in Nylas.

Return a thread

The following request returns a specific thread.

Because threads are non-linear, you can use one of the message_ids listed in the response to reply to a specific email message in the thread. This creates a new branch of the thread, and depending on who responds to it, the structure of the thread can resemble the example below.

A hierarchy diagram showing a thread with several branches.

Search an inbox for threads

You can add query parameters to a Get all Threads request to search for threads using specific criteria.

You can also use the v3 Nylas SDKs to search for threads, as in the following examples.