# Create with Attachment (POST) (Paid)

Kirim push notification dengan lampiran file gambar.

> **Warning: Paid Feature**
>
> Endpoint ini hanya tersedia untuk paket berbayar.

## Endpoint

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

## Authentication

> **Info: Required**
>
> Sertakan salah satu header berikut dalam permintaan Anda:
> - `Token: <your-api-key>` — Dapatkan dari [API Keys](https://pocketalert.app/account/apikeys)
> - `Authorization: Bearer <jwt-token>` — Dari [Login](https://info.pocketalert.app/api/user/login.md)

## Request

### Headers

| Header | Required | Description |
|--------|:--------:|-------------|
| `Content-Type` | ✅ | `multipart/form-data` |
| `Token` | ✅ | Kunci API Anda |

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

| Parameter | Type | Required | Description |
|-----------|------|:--------:|-------------|
| `title` | string | ✅ | Judul notifikasi |
| `message` | string | ✅ | Teks isi notifikasi |
| `application_id` | string | ❌ | TID aplikasi |
| `device_id` | string | ❌ | TID perangkat (kosongkan untuk semua) |
| `image` | file | ❌ | Lampiran gambar (`.png`, `.jpg`, `.jpeg`, `.gif`) |

### Example Request

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

## Response

### Success Response

> **Tip: 201 Created**
>
> Pesan dengan lampiran berhasil dibuat

| Field | Type | Description |
|-------|------|-------------|
| `tid` | string | Pengenal unik pesan |
| `title` | string | Judul pesan |
| `message` | string | Isi pesan |
| `attachment` | object | Detail lampiran |
| `attachment.tid` | string | Pengenal lampiran |
| `attachment.file_name` | string | Nama file yang disimpan |
| `attachment.content_type` | string | Tipe MIME |
| `attachment.file_size` | integer | Ukuran file dalam 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
  }
}
```

### Error Responses

| Status | Description |
|:------:|-------------|
| `401` | Unauthorized — Token tidak valid atau tidak ada |
| `403` | Forbidden — Fitur memerlukan paket berbayar |
| `400` | Bad Request — `title` atau `message` tidak ada, atau file tidak didukung |
| `404` | Not Found — `application_id` atau `device_id` tidak ditemukan |
| `429` | Batas harian tercapai — tidak ada yang disimpan atau diunggah. Lihat [Batas pesan harian](https://info.pocketalert.app/features/daily-limits.md). |
