# Ottenere tutti i messaggi (GET)

Recupera l'elenco di tutti i messaggi del tuo account.

## Endpoint

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

## Autenticazione

> **Info: Obbligatorio**
>
> Includi uno di questi header nella tua richiesta:
> - `Token: <your-api-key>` — Ottienila da [Chiavi API](https://pocketalert.app/account/apikeys)
> - `Authorization: Bearer <jwt-token>` — Da [Accedi](https://info.pocketalert.app/api/user/login.md)

## Richiesta

### Header

| Header | Obbligatorio | Descrizione |
|--------|:--------:|-------------|
| `Token` | ✅ | La tua chiave API |
| `Authorization` | ✅ | `Bearer <jwt-token>` |

### Parametri di query

| Parametro | Tipo | Predefinito | Descrizione |
|-----------|------|:-------:|-------------|
| `sort` | string | `desc` | Ordine di ordinamento per data di creazione (`asc` o `desc`) |
| `limit` | integer | `50` | Numero massimo di messaggi da restituire |

### Esempio di richiesta

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

## Risposta

### Risposta di successo

> **Tip: 200 OK**
>
> Restituisce un array di oggetti messaggio

| Campo | Tipo | Descrizione |
|-------|------|-------------|
| `tid` | string | Identificatore univoco del messaggio |
| `title` | string | Titolo del messaggio |
| `message` | string | Corpo del messaggio |
| `application` | string | Nome dell'applicazione |
| `device` | string | Dispositivo di destinazione |
| `is_read` | boolean | Indica se il messaggio è stato letto |
| `created_at` | string | Data e ora di creazione |

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

### Risposte di errore

| Stato | Descrizione |
|:------:|-------------|
| `401` | Non autorizzato — Token non valido o mancante |
