# 获取所有消息 (GET)

获取你账户中的所有消息列表。

## 端点

```
GET https://api.pocketalert.app/v1/messages
```

## 身份验证

> **Info: 必填**
>
> 在请求中包含以下任一请求头：
> - `Token: <your-api-key>` — 从 [API 密钥](https://pocketalert.app/account/apikeys) 页面获取
> - `Authorization: Bearer <jwt-token>` — 通过 [登录](https://info.pocketalert.app/api/user/login.md) 接口获取

## 请求

### 请求头

| 请求头 | 必填 | 说明 |
|--------|:--------:|-------------|
| `Token` | ✅ | 你的 API 密钥 |
| `Authorization` | ✅ | `Bearer <jwt-token>` |

### 查询参数

| 参数 | 类型 | 默认值 | 说明 |
|-----------|------|:-------:|-------------|
| `sort` | string | `desc` | 按创建时间排序（`asc` 或 `desc`） |
| `limit` | integer | `50` | 返回消息的最大数量 |

### 请求示例

**cURL**

```bash
curl -X GET "https://api.pocketalert.app/v1/messages?sort=desc&limit=10" \
  -H "Token: your-api-key"
```

**JavaScript**

```javascript
const response = await fetch('https://api.pocketalert.app/v1/messages?sort=desc&limit=10', {
  headers: { 'Token': 'your-api-key' }
});
const messages = await response.json();
```

**Python**

```python
import requests

response = requests.get(
    'https://api.pocketalert.app/v1/messages',
    headers={'Token': 'your-api-key'},
    params={'sort': 'desc', 'limit': 10}
)
print(response.json())
```

**PHP**

```php
$response = Http::withHeaders([
    'Token' => 'your-api-key',
])->get('https://api.pocketalert.app/v1/messages', [
    'sort' => 'desc',
    'limit' => 10,
]);

return $response->json();
```

## 响应

### 成功响应

> **Tip: 200 OK**
>
> 返回消息对象数组

| 字段 | 类型 | 说明 |
|-------|------|-------------|
| `tid` | string | 消息的唯一标识符 |
| `title` | string | 消息标题 |
| `message` | string | 消息正文 |
| `application` | string | 应用名称 |
| `device` | string | 目标设备 |
| `is_read` | boolean | 消息是否已读 |
| `created_at` | string | 创建时间戳 |

```json
[
  {
    "tid": "jb4xw9elz24c5",
    "title": "Server Alert",
    "message": "CPU usage exceeded 90%",
    "application": "Monitoring",
    "device": "iPhone",
    "is_read": true,
    "created_at": "18.09.2023 17:35:35"
  },
  {
    "tid": "d4u21qej1hld",
    "title": "Deploy Complete",
    "message": "Version 2.1.0 deployed",
    "application": "CI/CD",
    "device": "iPhone",
    "is_read": false,
    "created_at": "18.09.2023 17:35:23"
  }
]
```

### 错误响应

| 状态码 | 说明 |
|:------:|-------------|
| `401` | 未授权 — 令牌无效或缺失 |
