# Download a retained attachment

`GET /api/messages/{id}/attachments/{attachmentId}`

Streams a retained attachment while the account's current retention policy permits access. Requires the account's messages:read scope or a signed-in session. The response uses a safe Content-Disposition filename and private, no-store caching.

Send API requests to your Wildmail application origin. The documentation host does not serve API requests.

## Authentication

- apiKey: Send `Authorization: Bearer <token>` in the request headers. Wildmail scoped kmx_ API token.

- session: Send the credential in the cookie named `better-auth.session_token`. Browser session cookie used by the hosted app. It may use the __Secure- cookie prefix. Use the auth client to manage cookies.

Each bullet above is an alternative authentication method.

Required API key scope: `messages:read`.

Audience: management.

## Parameters

### id

path parameter; required.

Opaque message ID returned as receiptId by the message API.

```json
{
  "name": "id",
  "in": "path",
  "required": true,
  "schema": {
    "type": "string",
    "pattern": "^[a-f0-9]{24}$"
  },
  "description": "Opaque message ID returned as receiptId by the message API."
}
```

### attachmentId

path parameter; required.

Attachment ID from the message details.

```json
{
  "name": "attachmentId",
  "in": "path",
  "required": true,
  "schema": {
    "type": "string"
  },
  "description": "Attachment ID from the message details."
}
```

## Responses

### 200

Attachment bytes.

Content type: `application/octet-stream`.

Schema:

```json
{
  "type": "string",
  "format": "binary"
}
```

### 401

Missing, invalid or revoked credentials.

Content type: `application/json`.

Schema:

```json
{
  "$ref": "#/components/schemas/Error"
}
```

### 403

Required API key scope is missing.

Content type: `application/json`.

Schema:

```json
{
  "$ref": "#/components/schemas/Error"
}
```

### 404

Message or attachment not found.

Content type: `application/json`.

Schema:

```json
{
  "$ref": "#/components/schemas/Error"
}
```

### 410

Attachment content is no longer available under the current retention policy.

Content type: `application/json`.

Schema:

```json
{
  "$ref": "#/components/schemas/Error"
}
```

### 429



### 503



## Referenced schemas

References resolve against the [OpenAPI specification](/openapi.json).

### #/components/schemas/Error

```json
{
  "type": "object",
  "properties": {
    "error": {
      "type": "string"
    },
    "code": {
      "type": "string"
    },
    "limit": {
      "type": "integer"
    }
  },
  "required": [
    "error"
  ]
}
```
