# Mit Anhang senden (POST) (Paid)

Sende eine Push-Benachrichtigung mit einer angehängten Bilddatei.

> **Warning: Bezahlte Funktion**
>
> Dieser Endpunkt ist nur in bezahlten Tarifen verfügbar.

## Endpunkt

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

## Authentifizierung

> **Info: Erforderlich**
>
> Füge einen dieser Header in deine Anfrage ein:
> - `Token: <your-api-key>` — Hol ihn dir unter [API-Schlüssel](https://pocketalert.app/account/apikeys)
> - `Authorization: Bearer <jwt-token>` — Aus [Anmelden](https://info.pocketalert.app/api/user/login.md)

## Anfrage

### Header

| Header | Erforderlich | Beschreibung |
|--------|:--------:|-------------|
| `Content-Type` | ✅ | `multipart/form-data` |
| `Token` | ✅ | Dein API-Schlüssel |

### Body-Parameter (multipart/form-data)

| Parameter | Typ | Erforderlich | Beschreibung |
|-----------|------|:--------:|-------------|
| `title` | string | ✅ | Titel der Push-Benachrichtigung |
| `message` | string | ✅ | Text der Push-Benachrichtigung |
| `application_id` | string | ❌ | TID der Anwendung |
| `device_id` | string | ❌ | TID des Geräts (weglassen für alle) |
| `image` | file | ❌ | Bildanhang (`.png`, `.jpg`, `.jpeg`, `.gif`) |

### Beispielanfrage

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

## Antwort

### Erfolgreiche Antwort

> **Tip: 201 Created**
>
> Nachricht mit Anhang erfolgreich erstellt

| Feld | Typ | Beschreibung |
|-------|------|-------------|
| `tid` | string | Eindeutige Nachrichten-ID |
| `title` | string | Titel der Nachricht |
| `message` | string | Text der Nachricht |
| `attachment` | object | Details zum Anhang |
| `attachment.tid` | string | Kennung des Anhangs |
| `attachment.file_name` | string | Gespeicherter Dateiname |
| `attachment.content_type` | string | MIME-Typ |
| `attachment.file_size` | integer | Dateigröße in Bytes |

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

### Fehlerantworten

| Status | Beschreibung |
|:------:|-------------|
| `401` | Nicht autorisiert — Token ungültig oder fehlt |
| `403` | Verboten — Funktion erfordert bezahlten Tarif |
| `400` | Ungültige Anfrage — `title` oder `message` fehlt, oder nicht unterstützte Datei |
| `404` | Nicht gefunden — `application_id` oder `device_id` existiert nicht |
| `429` | Tageslimit erreicht — nichts wird gespeichert oder hochgeladen. Siehe [Tageslimits für Nachrichten](https://info.pocketalert.app/features/daily-limits.md). |
