# Delete a message

> **DELETE** `https://api.us.nylas.com/v3/grants/{grant_id}/messages/{message_id}`

Source: https://developer.nylas.com/docs/reference/api/messages/delete-message/

Deletes the specified message. If `hard_delete` is not defined or is `false`, Nylas moves the
message to the user's Trash folder.

**Authentication:** NYLAS_API_KEY, ACCESS_TOKEN

## Parameters

### Query parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `hard_delete` | boolean | No | When `true`, Nylas immediately deletes the specified message instead of sending it to the user's Trash folder. This operation is irreversible.  To use this query parameter, you need to turn on "Enable hard delete" in the [Nylas Dashboard](https://dashboard-v3.nylas.com/?utm_source=docs&utm_content=docs-hard-delete) under **Customizations > API**. |
| `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. You can also use the email address associated with the grant, or use `/me/` to refer to the grant associated with an access token. |
| `message_id` | string | Yes | ID of the message to access. We recommend 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, `#`). |

## Responses

### 200 - Delete Succeeded

- `request_id` (string) **(required)** - ID of the request.

### 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 DELETE \
  --url 'https://api.us.nylas.com/v3/grants/<NYLAS_GRANT_ID>/messages/<MESSAGE_ID>' \
  --header 'Accept: application/json' \
  --header 'Authorization: Bearer <NYLAS_API_KEY>' \
  --header 'Content-Type: application/json'
```

### Node.js SDK

```javascript
import Nylas from "nylas";

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

async function deleteMessage() {
  try {
    const result = await nylas.messages.destroy({
      identifier: "<NYLAS_GRANT_ID>",
      messageId: "<MESSAGE_ID>",
    });

    console.log("Result:", result);
  } catch (error) {
    console.error("Error deleting message:", error);
  }
}

deleteMessage();

```

### Python SDK

```python
from nylas import Client

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

grant_id = "<NYLAS_GRANT_ID>"
message_id = "<MESSAGE_ID>"

result = nylas.messages.destroy(
  grant_id,
  message_id,
)

print(result)
```

### Ruby SDK

```ruby
require 'nylas'	

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

status, _ = nylas.messages.destroy(identifier: "<NYLAS_GRANT_ID>", 
                                   message_id: "<MESSAGE_ID>")

puts status

```

### Kotlin SDK

```kotlin
import com.nylas.NylasClient

fun main(args: Array<String>) {

    val nylas: NylasClient = NylasClient(
        apiKey = "<NYLAS_API_KEY>"
    )

    val message =
        nylas.messages().destroy("<NYLAS_GRANT_ID>",
        "<MESSAGE_ID>")
    println(message)
}

```

### Java SDK

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

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

        DeleteResponse message = nylas.messages().destroy("<NYLAS_GRANT_ID>", 
        "<MESSAGE_ID>");
        System.out.println(message);
    }
}

```
