# Get All Messages (GET)

Retrieve a list of all messages in your account.

## Endpoint

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

## Authentication

> **Info: Required**
>
> Include one of these headers in your request:
> - `Token: <your-api-key>` — Get it from [API Keys](https://pocketalert.app/account/apikeys)
> - `Authorization: Bearer <jwt-token>` — From [Login](https://info.pocketalert.app/api/user/login.md)

## Request

### Headers

| Header | Required | Description |
|--------|:--------:|-------------|
| `Token` | ✅ | Your API key |
| `Authorization` | ✅ | `Bearer <jwt-token>` |

### Query Parameters

| Parameter | Type | Default | Description |
|-----------|------|:-------:|-------------|
| `sort` | string | `desc` | Sort order by creation time (`asc` or `desc`) |
| `limit` | integer | `50` | Maximum number of messages to return |

### Example Request

**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();
```

## Response

### Success Response

> **Tip: 200 OK**
>
> Returns an array of message objects

| Field | Type | Description |
|-------|------|-------------|
| `tid` | string | Unique message identifier |
| `title` | string | Message title |
| `message` | string | Message body |
| `application` | string | Application name |
| `device` | string | Target device |
| `is_read` | boolean | Whether the message was read |
| `created_at` | string | Creation timestamp |

```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"
  }
]
```

### Error Responses

| Status | Description |
|:------:|-------------|
| `401` | Unauthorized — Invalid or missing token |
