# Invio con allegato (POST) (Paid)

Invia una notifica push con un file immagine allegato.

> **Warning: Funzionalità a pagamento**
>
> Questo endpoint è disponibile solo con i piani a pagamento.

## Endpoint

```
POST 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 [Login](https://info.pocketalert.app/api/user/login.md)

## Richiesta

### Header

| Header | Obbligatorio | Descrizione |
|--------|:--------:|-------------|
| `Content-Type` | ✅ | `multipart/form-data` |
| `Token` | ✅ | La tua chiave API |

### Parametri del body (multipart/form-data)

| Parametro | Tipo | Obbligatorio | Descrizione |
|-----------|------|:--------:|-------------|
| `title` | string | ✅ | Titolo della notifica |
| `message` | string | ✅ | Testo del corpo della notifica |
| `application_id` | string | ❌ | TID dell'applicazione |
| `device_id` | string | ❌ | TID del dispositivo (ometti per tutti) |
| `image` | file | ❌ | Allegato immagine (`.png`, `.jpg`, `.jpeg`, `.gif`) |

### Esempio di richiesta

**cURL**

```bash
curl -X POST "https://api.pocketalert.app/v1/messages" \
  -H "Token: your-api-key" \
  -F "title=Screenshot Alert" \
  -F "message=New screenshot captured" \
  -F "image=@/path/to/screenshot.png"
```

**JavaScript**

```javascript
const formData = new FormData();
formData.append('title', 'Screenshot Alert');
formData.append('message', 'New screenshot captured');
formData.append('image', fileInput.files[0]);

const response = await fetch('https://api.pocketalert.app/v1/messages', {
  method: 'POST',
  headers: { 'Token': 'your-api-key' },
  body: formData
});
```

**Python**

```python
import requests

with open('screenshot.png', 'rb') as f:
    response = requests.post(
        'https://api.pocketalert.app/v1/messages',
        headers={'Token': 'your-api-key'},
        data={
            'title': 'Screenshot Alert',
            'message': 'New screenshot captured'
        },
        files={'image': f}
    )
print(response.json())
```

**PHP**

```php
$response = Http::withHeaders([
    'Token' => 'your-api-key',
])->attach(
    'image', file_get_contents('/path/to/screenshot.png'), 'screenshot.png'
)->post('https://api.pocketalert.app/v1/messages', [
    'title' => 'Screenshot Alert',
    'message' => 'New screenshot captured',
]);

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

## Risposta

### Risposta di successo

> **Tip: 201 Created**
>
> Messaggio con allegato creato con successo

| Campo | Tipo | Descrizione |
|-------|------|-------------|
| `tid` | string | Identificatore univoco del messaggio |
| `title` | string | Titolo del messaggio |
| `message` | string | Corpo del messaggio |
| `attachment` | object | Dettagli dell'allegato |
| `attachment.tid` | string | Identificatore dell'allegato |
| `attachment.file_name` | string | Nome del file salvato |
| `attachment.content_type` | string | Tipo MIME |
| `attachment.file_size` | integer | Dimensione del file in byte |

```json
{
  "tid": "zvtfxzk55fpqugz7ueslmse2a",
  "title": "Screenshot Alert",
  "message": "New screenshot captured",
  "application": "Monitoring",
  "device": "iPhone",
  "created_at": "04.01.2025 09:12:08",
  "attachment": {
    "tid": "i6k4b8un79otbcbdkmavmf4ha",
    "file_name": "5bd64bb3b76df1be1fc7f41eeb5078ca.jpg",
    "content_type": "image/jpeg",
    "file_size": 247421
  }
}
```

### Risposte di errore

| Stato | Descrizione |
|:------:|-------------|
| `401` | Non autorizzato — token non valido o mancante |
| `403` | Vietato — la funzionalità richiede un piano a pagamento |
| `400` | Richiesta non valida — `title` o `message` mancanti, oppure file non supportato |
| `404` | Non trovato — `application_id` o `device_id` non esiste |
| `429` | Limite giornaliero raggiunto — nulla viene salvato o caricato. Vedi [Limiti giornalieri dei messaggi](https://info.pocketalert.app/features/daily-limits.md). |
