# Update a thread

> **PUT** `https://api.us.nylas.com/v3/grants/{grant_id}/threads/{thread_id}`

Source: https://developer.nylas.com/docs/reference/api/threads/put-threads-id/

Updates the specified thread.

When you make a `PUT` request, Nylas replaces all data in the nested object with the information
included in your request. For more information, see
[Updating objects](/docs/reference/api/#updating-objects).

**Authentication:** NYLAS_API_KEY, ACCESS_TOKEN

## Parameters

### Query parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `select` | string | No | Specify fields that you want Nylas to return, as a comma-separated list (for example, `select=id,updated_at`). This allows you to receive only the portion of object data that you're interested in. You can use `select` to optimize response size and reduce latency by limiting queries to only the information that you need. |
| `shared_folder_id` | string | No | (Microsoft only) When provided, Nylas returns items from the specified shared folder ID. Required when using `shared_from`. This parameter only accepts a single folder ID. Check out the [Shared folders](/docs/provider-guides/microsoft/shared-folders) guide for more information. |
| `shared_from` | string | No | (Microsoft only) When provided, Nylas returns items that were shared from the specified email address. It also accepts grant ID. This parameter only accepts single email address or grant ID. Check out the [Shared folders](/docs/provider-guides/microsoft/shared-folders) guide for more information. |

### Path parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `grant_id` | string | Yes | ID of the grant to access. Use `/me/` to refer to the grant associated with an access token. |
| `thread_id` | string | Yes | ID of the thread to access. Nylas recommends you URL-encode this field, or you might receive a [`404` error](/docs/api/errors/400-response/) if the ID contains special characters (for example, `#`). |

## Request body

Content-Type: application/json

- `starred` (boolean) - When `true`, indicates that the thread is starred.
- `unread` (boolean) - When `false`, indicates that all messages in the thread have been read.
- `folders` (array) - The IDs of the folders to apply to the thread. This overwrites all previously assigned
folders for all messages in the thread.

## Responses

### 200 - Thread response

- `request_id` (string) - The request ID.
- `data` (object)
  - `grant_id` (string) - The ID of grant for the connected user.
  - `id` (string) - A globally unique object identifier for Microsoft accounts. An email address for Google accounts.
  - `object` (string) - The type of object (in this case, `thread`).
  - `latest_draft_or_message` (object) - The latest message or draft in the thread.
    - `attachments` (array) - An array of Attachment objects. For Google, linked Google Drive files are not included. For
Microsoft, linked OneDrive files are not included.
      - `id` (string) **(required)** - The ID of the attachment.
      - `content_type` (string) - The [MIME type](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types) of the attachment, used by the email client to determine how to display the attachment. If you don't provide a type, Nylas infers it from the file name.
The value of this field is exactly the same as the email attachment's `Content-Type` header.
The provider might set additional parameters, such as `name` and `charset`.

Nylas returns an empty `content_type` field if an attachment file name contains non-ASCII characters (for example, accented characters like `ü`). This is because Google can't detect its content type.
      - `filename` (string) - The file name of the attachment.
      - `grant_id` (string) - The ID of grant for the connected user.
      - `content_id` (string) - (Inline attachments only) The alphanumeric `cid` from the `<img>` tag in the message's HTML. For
example, you might see something like `<img src=\"cid:ce9b9547-9eeb-43b2-ac4e-58768bdf04e4\">` in
the message body.

Sometimes, the `content_id` value is contained in angle brackets (for example,
`<ce9b9547-9eeb-43b2-ac4e-58768bdf04e4>`).
      - `content_disposition` (string) - (Not supported for Microsoft and EWS) The content disposition of the attachment. Usually, this is `inline` or `attachment` followed by the file name (for example, `inline; filename="some-image.jpeg"`).
      - `is_inline` (boolean) - If `true`, indicates that the attachment is an inline file.
      - `size` (integer) - The size of the attachment, in bytes.
    - `bcc` (array) - An array of name/email address pairs that the message was BCC'd to. For received messages, this
is nearly always empty.
      - `name` (string)
      - `email` (string) **(required)**
    - `body` (string) - The body of the message as either plain-text or HTML content. If the message has both plain-text
and HTML, Nylas returns the HTML version.
    - `cc` (array) - An array of name/email address pairs that the message was CC'd to.
      - `name` (string)
      - `email` (string) **(required)**
    - `date` (integer) - Unix timestamp in seconds that represents when _the mail server_ received the message. This might be
different from the unified `Date` header in a raw Message object.
    - `folders` (array) - The IDs of the folders that the message appears in. Microsoft messages can be in a single folder
only. Google allows a single message to appear in multiple folders.
    - `from` (array) - A list of name/email address pairs that the message was sent from. This is usually one pair only,
but can be many.
      - `name` (string)
      - `email` (string)
    - `grant_id` (string) - The ID of grant for the connected user.
    - `headers` (array) - An array of key-value pairs that contain the message headers. Nylas returns this field when you
set the `fields` query parameter to either `include_headers` or `include_basic_headers`.

- `fields=include_headers`: Returns the full set of headers on the message.
- `fields=include_basic_headers`: Returns only the three RFC threading headers (`Message-ID`,
  `In-Reply-To`, `References`). Use this option when you only need to track message identity and
  thread relationships — payload size is significantly smaller than `include_headers`.

A single message can sometimes have multiple headers with the same key name. Nylas adds all of
the headers to the `headers` array without merging or de-duplicating the data. When the headers
contain encoded data, Nylas adds it to the `headers` array without decoding it. If you need the
decoded data, you need to build decoding logic into your project.

Some headers might contain raw MIME information (for example,
`=?Windows-1252?Q?Re:_Candidature_de_Mme_Leyah_Miller?=`).
      - `name` (string) **(required)**
      - `value` (string) **(required)**
    - `id` (string) - A globally unique object identifier for Microsoft accounts. An email address for Google accounts.
    - `in_reply_to` (string) - (EWS only) The ID of the message that this message replies to. This ID is the same as the
`In-Reply-To` header.
    - `metadata` (object) - The metadata associated with the object. For more information, see
[Metadata](/docs/reference/api/#metadata).
    - `object` (string) - The object type of the response (in this case, `message`).
    - `raw_mime` (string) - A Base64url-encoded string containing the message data (including the body content).

To get the raw MIME content for a message, set the `fields` query parameter to `raw_mime` in
your request. When you request raw MIME data, Nylas returns the `grant_id`, `object`, `id`,
and `raw_mime` fields only.
    - `reply_to` (array) - An array of name/email address pairs that should receive replies to the message.
      - `name` (string)
      - `email` (string) **(required)**
    - `snippet` (string) - A short snippet (the first 100 characters, with HTML tags removed) of the message body. This is
useful for displaying a preview of the message.
    - `starred` (boolean) - If `true`, shows that the message has been starred by the user. For EWS, this is only supported
on Microsoft Exchange 2010 or later.
    - `subject` (string) - The subject of the message.
    - `thread_id` (string) - A reference to the parent Thread object. Every message is associated with a thread, whether that
thread contains one message or many. If the message is new, Nylas assigns a `thread_id` to it.
    - `to` (array) - An array of name/email address pairs that the message was sent to.
      - `name` (string)
      - `email` (string) **(required)**
    - `tracking_options` (object) - Tracking options for the message.
      - `opens` (boolean) - When `true`, shows that message open tracking is enabled.
      - `thread_replies` (boolean) - When `true`, shows that thread replied tracking is enabled.
      - `links` (boolean) - When `true`, shows that link clicked tracking is enabled.
      - `label` (string) - A label describing the message tracking purpose.
    - `unread` (boolean) - If `true`, shows that the message has not been read by the user.
  - `has_attachments` (boolean) - When `true`, indicates that the message has attachments.
  - `has_drafts` (boolean) - When `true`, indicates that the message is a draft.
  - `earliest_message_date` (integer) - The date when the earliest or first message in the thread was sent or received, in seconds using the Unix timestamp
format.
  - `latest_message_received_date` (integer) - The date when the most recent incoming message in the thread was received, in seconds using the Unix timestamp
format.
  - `latest_message_sent_date` (integer) - The date when the most recent outgoing message in the thread was sent, in seconds using the Unix timestamp format.
  - `participants` (array) - A sub-object that contains the names and email addresses of all participants in the thread.
    - `email` (string)
    - `name` (string)
  - `snippet` (string) - A short snippet (the first 100 characters, with HTML tags removed) of the body of the last
received message. This is useful for displaying a preview of a message.
  - `starred` (boolean) - When `true`, indicates that the thread is starred. For EWS, this is only supported for Microsoft
Exchange 2010 or later.
  - `subject` (string) - The subject line of the thread.
  - `unread` (boolean) - When `false`, indicates that all messages in the thread have been read.
  - `message_ids` (array) - An array of IDs for all messages in the thread.
  - `draft_ids` (array) - An array of IDs for all drafts in the thread.
  - `folders` (array) - An array of folder IDs for all folders that the messages in the thread appear in.

Microsoft messages can only be in one folder at a time. Google messages can be in multiple
folders.

### 400 - Bad Request

- `request_id` (string) - The request ID.
- `error` (object) - The response error object.
  - `type` (string) - The error type.
  - `message` (string) - The error message.
  - `provider_error` (object) - The error from the provider.

### 401 - Unauthorized

- `request_id` (string) - The request ID.
- `error` (object) - The response error object.
  - `type` (string) - The error type.
  - `message` (string) - The error message.
  - `provider_error` (object) - The error from the provider.

### 404 - Not Found

- `request_id` (string) - The request ID.
- `error` (object) - The response error object.
  - `type` (string) - The error type.
  - `message` (string) - The error message.
  - `provider_error` (object) - The raw error from the provider, if available
    - `code` (string)
    - `message` (string)

### 429 - Rate Limit

- `request_id` (string) - The request ID.
- `error` (object) - The response error object.
  - `type` (string) - The error type.
  - `message` (string) - The error message.

### 504 - Provider Failure

- `request_id` (string) - The request ID.
- `error` (object) - The response error object.
  - `type` (string) - The error type.
  - `message` (string) - The error message.

## Code samples

### cURL

```bash
curl --compressed --request PUT \
  --url 'https://api.us.nylas.com/v3/grants/<NYLAS_GRANT_ID>/threads/<THREAD_ID>' \
  --header 'Accept: application/json' \
  --header 'Authorization: Bearer <NYLAS_API_KEY>' \
  --header 'Content-Type: application/json' \
  --data '{
    "unread": true,
    "starred": false,
    "folders": ["<FOLDER_ID>"]
  }'
```

### Node.js SDK

```javascript
import Nylas from "nylas";

const nylas = new Nylas({
  apiKey: "<NYLAS_API_KEY>",
  apiUri: "<NYLAS_API_URI>",
});

async function updateThread() {
  try {
    const calendar = await nylas.threads.update({
      identifier: "<NYLAS_GRANT_ID>",
      threadId: "<THREAD_ID>",
      requestBody: {
        starred: true,
      },
    });

    console.log("Updated Thread:", calendar);
  } catch (error) {
    console.error("Error to update thread:", error);
  }
}

updateThread();

```

### Python SDK

```python
from nylas import Client

nylas = Client(
    "<NYLAS_API_KEY>",
    "<NYLAS_API_URI>"
)

grant_id = "<NYLAS_GRANT_ID>"

thread = nylas.threads.update(
  grant_id,
  thread_id="<THREAD_ID>",
  request_body={
    "starred": True
  }
)

print(thread)
```

### Ruby SDK

```ruby
require 'nylas'	

nylas = Nylas::Client.new(
	api_key: "<NYLAS_API_KEY>"
)

request_body = {
  unread: true,
  starred: true
}

thread, _ = nylas.threads.update(identifier: "<NYLAS_GRANT_ID>", 
                                 thread_id: "<THREAD_ID>",
                                 request_body: request_body)

puts thread

```

### Java SDK

```java
import com.nylas.NylasClient;
import com.nylas.models.*;
import com.nylas.models.Thread;

public class UpdateThread {
	public static void main(String[] args) throws NylasSdkTimeoutError, NylasApiError {
		NylasClient nylas = new NylasClient.Builder("<NYLAS_API_KEY>").build();

		UpdateThreadRequest requestBody =
				new UpdateThreadRequest.
				Builder().
				unread(true).
				starred(true).
				build();

		Response<Thread> draft = nylas.threads().update("<NYLAS_GRANT_ID>", "<THREAD_ID>", requestBody);
		
		System.out.printf("%s%s%s%n",
			draft.getData().getId(),
			draft.getData().getUnread(),
			draft.getData().getStarred()
		);
	}
}
```

### Kotlin SDK

```kotlin
import com.nylas.NylasClient
import com.nylas.models.UpdateThreadRequest

fun main(args: Array<String>) {
  val nylas: NylasClient = NylasClient(
      apiKey = "<NYLAS_API_KEY>"
  )

  val requestBody: UpdateThreadRequest =
      UpdateThreadRequest.
      Builder().
      unread(true).
      starred(true).
      build()

  val thread = nylas.threads().update("<NYLAS_GRANT_ID>", "<THREAD_ID>", requestBody)
  
  print("${thread.data.id} ${thread.data.unread} ${thread.data.starred} ")
}
```
