# Anmelden (POST)

Melde dich mit E-Mail und Passwort an, um ein JWT-Token zu erhalten.

## Endpunkt

```
POST https://api.pocketalert.app/v1/auth/signin
```

## Anfrage

### Header

| Header | Pflicht | Beschreibung |
|--------|:--------:|-------------|
| `Content-Type` | ✅ | `application/json` |

### Body-Parameter

| Parameter | Typ | Pflicht | Beschreibung |
|-----------|------|:--------:|-------------|
| `email` | string | ✅ | Deine registrierte E-Mail-Adresse |
| `password` | string | ✅ | Dein Kontopasswort |

### Beispielanfrage

**cURL**

```bash
curl -X POST "https://api.pocketalert.app/v1/auth/signin" \
  -H "Content-Type: application/json" \
  -d '{
    "email": "user@example.com",
    "password": "your-password"
  }'
```

**JavaScript**

```javascript
const response = await fetch('https://api.pocketalert.app/v1/auth/signin', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    email: 'user@example.com',
    password: 'your-password'
  })
});

const { token } = await response.json();
// Use token in Authorization header for subsequent requests
```

**Python**

```python
import requests

response = requests.post(
    'https://api.pocketalert.app/v1/auth/signin',
    json={
        'email': 'user@example.com',
        'password': 'your-password'
    }
)

data = response.json()
# Use token in Authorization header for subsequent requests
```

**PHP**

```php
$response = Http::post('https://api.pocketalert.app/v1/auth/signin', [
    'email' => 'user@example.com',
    'password' => 'your-password',
]);

$token = $response->json()['token'];
// Use token in Authorization header for subsequent requests
```

## Antwort

### Erfolgreiche Antwort

> **Tip: 200 OK**
>
> Anmeldung erfolgreich

| Feld | Typ | Beschreibung |
|-------|------|-------------|
| `token` | string | JWT-Token für die API-Authentifizierung |
| `email` | string | E-Mail-Adresse des Nutzers |
| `name` | string | Anzeigename des Nutzers |
| `avatar` | string | URL zum Avatarbild des Nutzers |

```json
{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "email": "user@example.com",
  "name": "John Doe",
  "avatar": ""
}
```

### Token verwenden

Nachdem du das Token erhalten hast, füge es in Folgeanfragen ein:

```bash
curl -X GET "https://api.pocketalert.app/v1/messages" \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
```

### Fehlerantworten

| Status | Beschreibung |
|:------:|-------------|
| `400` | Ungültige Anfrage — E-Mail oder Passwort fehlt, oder das Captcha ist fehlgeschlagen |
| `401` | Ungültige Anmeldedaten — falsches Passwort oder unbekannte E-Mail-Adresse |

> **Tip: Empfehlung**
>
> Für serverseitige Integrationen empfehlen wir die Verwendung von [API-Schlüsseln](https://pocketalert.app/account/apikeys) statt JWT-Tokens. API-Schlüssel laufen nicht ab und sind einfacher zu verwalten.
