# Create with Attachment (POST) (Paid)

Send a push notification with an attached image file.

> **Warning: Paid Feature**
>
> This endpoint is only available on paid plans.

## Endpoint

```
POST 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 |
|--------|:--------:|-------------|
| `Content-Type` | ✅ | `multipart/form-data` |
| `Token` | ✅ | Your API key |

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

| Parameter | Type | Required | Description |
|-----------|------|:--------:|-------------|
| `title` | string | ✅ | Notification title |
| `message` | string | ✅ | Notification body text |
| `application_id` | string | ❌ | Application TID |
| `device_id` | string | ❌ | Device TID (omit for all) |
| `image` | file | ❌ | Image attachment (`.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**
>
> Message with attachment created successfully

| Field | Type | Description |
|-------|------|-------------|
| `tid` | string | Unique message identifier |
| `title` | string | Message title |
| `message` | string | Message body |
| `attachment` | object | Attachment details |
| `attachment.tid` | string | Attachment identifier |
| `attachment.file_name` | string | Stored file name |
| `attachment.content_type` | string | MIME type |
| `attachment.file_size` | integer | File size 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
  }
}
```

### Error Responses

| Status | Description |
|:------:|-------------|
| `401` | Unauthorized — Invalid or missing token |
| `403` | Forbidden — Feature requires paid plan |
| `422` | Validation Error — Invalid file type or missing fields |
| `429` | Daily limit reached — nothing is stored or uploaded. See [Daily message limits](https://info.pocketalert.app/features/daily-limits.md). |
