# Crear con adjunto (POST) (Paid)

Envía una notificación push con un archivo de imagen adjunto.

> **Warning: Función de pago**
>
> Este endpoint solo está disponible en los planes de pago.

## Endpoint

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

## Autenticación

> **Info: Obligatorio**
>
> Incluye uno de estos headers en tu solicitud:
> - `Token: <your-api-key>` — Obténla en [Claves de API](https://pocketalert.app/account/apikeys)
> - `Authorization: Bearer <jwt-token>` — Desde [Iniciar sesión](https://info.pocketalert.app/api/user/login.md)

## Solicitud

### Headers

| Header | Obligatorio | Descripción |
|--------|:--------:|-------------|
| `Content-Type` | ✅ | `multipart/form-data` |
| `Token` | ✅ | Tu clave de API |

### Parámetros del cuerpo (multipart/form-data)

| Parámetro | Tipo | Obligatorio | Descripción |
|-----------|------|:--------:|-------------|
| `title` | string | ✅ | Título de la notificación |
| `message` | string | ✅ | Texto del cuerpo de la notificación |
| `application_id` | string | ❌ | TID de la aplicación |
| `device_id` | string | ❌ | TID del dispositivo (omítelo para todos) |
| `image` | file | ❌ | Imagen adjunta (`.png`, `.jpg`, `.jpeg`, `.gif`) |

### Ejemplo de solicitud

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

## Respuesta

### Respuesta correcta

> **Tip: 201 Created**
>
> Mensaje con adjunto creado correctamente

| Campo | Tipo | Descripción |
|-------|------|-------------|
| `tid` | string | Identificador único del mensaje |
| `title` | string | Título del mensaje |
| `message` | string | Cuerpo del mensaje |
| `attachment` | object | Detalles del adjunto |
| `attachment.tid` | string | Identificador del adjunto |
| `attachment.file_name` | string | Nombre del archivo almacenado |
| `attachment.content_type` | string | Tipo MIME |
| `attachment.file_size` | integer | Tamaño del archivo en 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
  }
}
```

### Respuestas de error

| Estado | Descripción |
|:------:|-------------|
| `401` | No autorizado — token inválido o ausente |
| `403` | Prohibido — la función requiere un plan de pago |
| `400` | Solicitud incorrecta — falta `title` o `message`, o el archivo no es compatible |
| `404` | No encontrado — `application_id` o `device_id` no existe |
| `429` | Límite diario alcanzado — no se almacena ni se sube nada. Consulta [Límites diarios de mensajes](https://info.pocketalert.app/features/daily-limits.md). |
