# Download a received attachment

GET /v1/messages/{message_id}/attachments/{attachment_id}

Source: https://cherami.to/docs/api/messages/download-attachment



{/* Generated from apps/web/openapi. Edit the contract, not this file. */}

`GET /v1/messages/{message_id}/attachments/{attachment_id}`

Requires an [API key](https://cherami.to/docs/api#authentication): `Authorization: Bearer YOUR_CREDENTIAL`.

Returns one received attachment's bytes, always as `application/octet-stream`; the type the sender declared is `mime_type` in the message's attachment metadata. Take `attachment_id` from `content.attachments` of a `ready` message.

The bytes are the sender's file: save them or pass them to a file tool.

## Parameters [#parameters]

| Parameter       | Location | Required | Type   | Meaning                                                    |
| --------------- | -------- | -------- | ------ | ---------------------------------------------------------- |
| `message_id`    | path     | Yes      | string | Cherami resource ID returned by the API.                   |
| `attachment_id` | path     | Yes      | string | id from the message's content.attachments, not a filename. |

## curl example [#curl-example]

Supply `CHERAMI_API_KEY` privately.

```sh
curl --silent --show-error --dump-header response-headers.txt --request GET \
  "https://cherami.to/v1/messages/MESSAGE_ID/attachments/ATTACHMENT_ID" \
  --header "Authorization: Bearer $CHERAMI_API_KEY" \
  --output download.bin
```

## Responses [#responses]

### HTTP 200 [#http-200]

The original bytes, as a download.

* `X-Request-ID`: Identifies this request; include it when reporting a problem.
* `Content-Disposition`: Attachment disposition with a safely encoded suggested filename.
* `Content-Length`: Original byte count.
* `Cache-Control`: Includes no-store.
* `X-Content-Type-Options`: `"nosniff"`
* `Content-Security-Policy`: Sandbox with default-src 'none'.

Content type: `application/octet-stream`.

Binary response body, not a JSON string. Save the original bytes.

### HTTP 401 [#http-401]

`unauthorized`: Send a valid API key as `Authorization: Bearer <key>`. If the key stopped working, get a new one through [recovery](https://cherami.to/docs/guides/recovery).

* `X-Request-ID`: Identifies this request; include it when reporting a problem.
* `WWW-Authenticate`: `"Bearer"`

Content type: `application/json`.

[Error](#schema-error)

### HTTP 404 [#http-404]

`not_found`: The resource does not exist or does not belong to this account. A reply or forward source must also be in the sending inbox.

* `X-Request-ID`: Identifies this request; include it when reporting a problem.

Content type: `application/json`.

[Error](#schema-error)

### HTTP 500 [#http-500]

`internal_error`: The operation failed. Retry a read; after a write the change may have happened, so recover as [retry by operation](https://cherami.to/docs/api/errors#retry-by-operation) describes.

* `X-Request-ID`: Identifies this request; include it when reporting a problem.

Content type: `application/json`.

[Error](#schema-error)

### HTTP 503 [#http-503]

`content_unavailable`: Stored content could not be read. Retry later.

* `X-Request-ID`: Identifies this request; include it when reporting a problem.

Content type: `application/json`.

[Error](#schema-error)

## Schema: Error [#schema-error]

| Field   | Required | Type   | Meaning and constraints |
| ------- | -------- | ------ | ----------------------- |
| `error` | Yes      | object |                         |

### `error` fields [#error-fields]

| Field     | Required | Type   | Meaning and constraints                                               |
| --------- | -------- | ------ | --------------------------------------------------------------------- |
| `code`    | Yes      | string | Code to handle. Handle a code you don't recognize by its HTTP status. |
| `message` | Yes      | string | Explanation of this case; its wording can change.                     |

[Errors, limits and pagination](https://cherami.to/docs/api/errors) · [Download OpenAPI 3.1](https://cherami.to/openapi.json)
