# Return Attachment metadata

> **GET** `https://api.us.nylas.com/v3/grants/{grant_id}/attachments/{attachment_id}`

Source: https://developer.nylas.com/docs/reference/api/attachments/get-attachments-id/

Returns the metadata of the specified attachment.

**Authentication:** NYLAS_API_KEY, ACCESS_TOKEN

## Parameters

### 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. |
| `attachment_id` | string | Yes | ID of the attachment 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, `#`). |

### Query parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `message_id` | string | Yes | ID of the message the specified attachment belongs to. |
| `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. |
| `query_imap` | boolean | No | (IMAP, iCloud, and Yahoo only) When `true`, Nylas queries from the IMAP server directly instead of the Nylas database. |

## Responses

### 200 - Attachment metadata

- `request_id` (string) - The request ID.
- `data` (object) - Metadata for a file attached to an email message.
  - `id` (string) - A globally unique object identifier for Microsoft accounts. An email address for Google accounts.
  - `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.
  - `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) - Whether the attachment is inline (embedded in the message body, such as an image).
  - `size` (integer) - The size of the attachment, in bytes.

### 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 GET \
  --url 'https://api.us.nylas.com/v3/grants/<NYLAS_GRANT_ID>/attachments/<ATTACHMENT_ID>?message_id=<MESSAGE_ID>' \
  --header 'Accept: application/json' \
  --header 'Authorization: Bearer <NYLAS_API_KEY>'

```

### Node.js SDK

```javascript
import Nylas from "nylas";

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

async function fetchAttachmentById() {
  try {
    const attachment = await nylas.attachments.find({
      identifier: "<NYLAS_GRANT_ID>",
      attachmentId: "<ATTACHMENT_ID>",
      queryParams: {
        messageId: "<MESSAGE_ID>",
      },
    });

    console.log("Attachment:", attachment);
  } catch (error) {
    console.error("Error fetching attachment:", error);
  }
}

fetchAttachmentById();

```

### Python SDK

```python
from nylas import Client

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

grant_id = "<NYLAS_GRANT_ID>"
folder_id = "<FOLDER_ID>"
attachment_id = "<ATTACHMENT_ID>"

attachment = nylas.attachments.find(
  grant_id,
  attachment_id,
  query_params= {
    "message_id": "<MESSAGE_ID>",
  }
)

print(attachment)
```

### Ruby SDK

```ruby
require 'nylas'

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

query_params = {
  message_id: "<MESSAGE_ID>"
}

attachment = nylas.attachments.find(identifier: "<NYLAS_GRANT_ID>",  
attachment_id: "<ATTACHMENT_ID>", query_params: query_params)

puts attachment
```

### Java SDK

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

public class attachment {
  public static void main(String[] args) throws NylasSdkTimeoutError, NylasApiError, NylasOAuthError {
    NylasClient nylas = new NylasClient.Builder("NYLAS_API_KEY").build();
    FindAttachmentQueryParams queryParams = new FindAttachmentQueryParams("<MESSAGE_ID>");
    Attachment attachment = nylas.attachments().find("<NYLAS_GRANT_ID>", "<ATTACHMENT_ID>", queryParams).getData();

    System.out.println(attachment);
  }
}

```

### Kotlin SDK

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

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

  val queryParams = FindAttachmentQueryParams("<MESSAGE_ID>")
  val attachment = nylas.attachments().find("<NYLAS_GRANT_ID>", "<ATTACHMENT_ID>", queryParams)
  
  print(attachment)
}
```
